3818 /** Check that an auxiliary class is not accessed from any other file than its own. 3819 */ 3820 void checkForBadAuxiliaryClassAccess(DiagnosticPosition pos, Env<AttrContext> env, ClassSymbol c) { 3821 if (lint.isEnabled(Lint.LintCategory.AUXILIARYCLASS) && 3822 (c.flags() & AUXILIARY) != 0 && 3823 rs.isAccessible(env, c) && 3824 !fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile)) 3825 { 3826 log.warning(pos, 3827 Warnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile)); 3828 } 3829 } 3830 3831 /** 3832 * Check for a default constructor in an exported package. 3833 */ 3834 void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) { 3835 if (lint.isEnabled(LintCategory.MISSING_EXPLICIT_CTOR) && 3836 ((c.flags() & (ENUM | RECORD)) == 0) && 3837 !c.isAnonymous() && 3838 ((c.flags() & PUBLIC) != 0) && 3839 Feature.MODULES.allowedInSource(source)) { 3840 NestingKind nestingKind = c.getNestingKind(); 3841 switch (nestingKind) { 3842 case ANONYMOUS, 3843 LOCAL -> {return;} 3844 case TOP_LEVEL -> {;} // No additional checks needed 3845 case MEMBER -> { 3846 // For nested member classes, all the enclosing 3847 // classes must be public. 3848 Symbol owner = c.owner; 3849 while (owner != null && owner.kind == TYP) { 3850 if ((owner.flags() & PUBLIC) == 0) 3851 return; 3852 owner = owner.owner; 3853 } 3854 } 3855 } 3856 3857 // Only check classes in named packages exported by its module 3858 PackageSymbol pkg = c.packge(); 3859 if (!pkg.isUnnamed()) { 3860 ModuleSymbol modle = pkg.modle; 3861 for (ExportsDirective exportDir : modle.exports) { 3862 // Report warning only if the containing 3863 // package is unconditionally exported 3864 if (exportDir.packge.equals(pkg)) { 3865 if (exportDir.modules == null || exportDir.modules.isEmpty()) { 3866 // Warning may be suppressed by 3867 // annotations; check again for being 3868 // enabled in the deferred context. 3869 deferredLintHandler.report(() -> { 3870 if (lint.isEnabled(LintCategory.MISSING_EXPLICIT_CTOR)) | 3818 /** Check that an auxiliary class is not accessed from any other file than its own. 3819 */ 3820 void checkForBadAuxiliaryClassAccess(DiagnosticPosition pos, Env<AttrContext> env, ClassSymbol c) { 3821 if (lint.isEnabled(Lint.LintCategory.AUXILIARYCLASS) && 3822 (c.flags() & AUXILIARY) != 0 && 3823 rs.isAccessible(env, c) && 3824 !fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile)) 3825 { 3826 log.warning(pos, 3827 Warnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile)); 3828 } 3829 } 3830 3831 /** 3832 * Check for a default constructor in an exported package. 3833 */ 3834 void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) { 3835 if (lint.isEnabled(LintCategory.MISSING_EXPLICIT_CTOR) && 3836 ((c.flags() & (ENUM | RECORD)) == 0) && 3837 !c.isAnonymous() && 3838 ((c.flags() & (PUBLIC | PROTECTED)) != 0) && 3839 Feature.MODULES.allowedInSource(source)) { 3840 NestingKind nestingKind = c.getNestingKind(); 3841 switch (nestingKind) { 3842 case ANONYMOUS, 3843 LOCAL -> {return;} 3844 case TOP_LEVEL -> {;} // No additional checks needed 3845 case MEMBER -> { 3846 // For nested member classes, all the enclosing 3847 // classes must be public or protected. 3848 Symbol owner = c.owner; 3849 while (owner != null && owner.kind == TYP) { 3850 if ((owner.flags() & (PUBLIC | PROTECTED)) == 0) 3851 return; 3852 owner = owner.owner; 3853 } 3854 } 3855 } 3856 3857 // Only check classes in named packages exported by its module 3858 PackageSymbol pkg = c.packge(); 3859 if (!pkg.isUnnamed()) { 3860 ModuleSymbol modle = pkg.modle; 3861 for (ExportsDirective exportDir : modle.exports) { 3862 // Report warning only if the containing 3863 // package is unconditionally exported 3864 if (exportDir.packge.equals(pkg)) { 3865 if (exportDir.modules == null || exportDir.modules.isEmpty()) { 3866 // Warning may be suppressed by 3867 // annotations; check again for being 3868 // enabled in the deferred context. 3869 deferredLintHandler.report(() -> { 3870 if (lint.isEnabled(LintCategory.MISSING_EXPLICIT_CTOR)) |