< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java

Print this page

        

*** 27,36 **** --- 27,37 ---- import java.util.*; import java.util.function.Supplier; import javax.lang.model.element.ElementKind; + import javax.lang.model.element.NestingKind; import javax.tools.JavaFileManager; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Attribute.Compound; import com.sun.tools.javac.code.Directive.ExportsDirective;
*** 3825,3834 **** --- 3826,3888 ---- log.warning(pos, Warnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile)); } } + /** + * Check for a default constructor in an exported package. + */ + void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) { + if (lint.isEnabled(LintCategory.MISSING_DECLARED_CTOR) && + ((c.flags() & (ENUM | RECORD)) == 0) && + !c.isAnonymous() && + ((c.flags() & PUBLIC) != 0) && + Feature.MODULES.allowedInSource(source)) { + NestingKind nestingKind = c.getNestingKind(); + switch (nestingKind) { + case ANONYMOUS, + LOCAL -> {return;} + case TOP_LEVEL -> {;} // No additional checks needed + case MEMBER -> { + // For nested member classes, all the enclosing + // classes must be public. + Symbol owner = c.owner; + while (owner != null && owner.kind == TYP) { + if ((owner.flags() & PUBLIC) == 0) + return; + owner = owner.owner; + } + } + } + + // Only check classes in named packages exported by its module + PackageSymbol pkg = c.packge(); + if (!pkg.isUnnamed()) { + ModuleSymbol modle = pkg.modle; + for (ExportsDirective exportDir : modle.exports) { + // Report warning only if the containing + // package is unconditionally exported + if (exportDir.packge.equals(pkg)) { + if (exportDir.modules == null || exportDir.modules.isEmpty()) { + // Warning may be suppressed by + // annotations; check again for being + // enabled in the deferred context. + deferredLintHandler.report(() -> { + if (lint.isEnabled(LintCategory.MISSING_DECLARED_CTOR)) + log.warning(LintCategory.MISSING_DECLARED_CTOR, + pos, Warnings.MissingDeclaredCtor(c, pkg, modle)); + }); + } else { + return; + } + } + } + } + } + return; + } + private class ConversionWarner extends Warner { final String uncheckedKey; final Type found; final Type expected; public ConversionWarner(DiagnosticPosition pos, String uncheckedKey, Type found, Type expected) {
< prev index next >