2099 2100 private void checkClassOverrideEqualsAndHash(DiagnosticPosition pos, 2101 ClassSymbol someClass) { 2102 if (lint.isEnabled(LintCategory.OVERRIDES)) { 2103 MethodSymbol equalsAtObject = (MethodSymbol)syms.objectType 2104 .tsym.members().findFirst(names.equals); 2105 MethodSymbol hashCodeAtObject = (MethodSymbol)syms.objectType 2106 .tsym.members().findFirst(names.hashCode); 2107 boolean overridesEquals = types.implementation(equalsAtObject, 2108 someClass, false, equalsHasCodeFilter).owner == someClass; 2109 boolean overridesHashCode = types.implementation(hashCodeAtObject, 2110 someClass, false, equalsHasCodeFilter) != hashCodeAtObject; 2111 2112 if (overridesEquals && !overridesHashCode) { 2113 log.warning(LintCategory.OVERRIDES, pos, 2114 "override.equals.but.not.hashcode", someClass); 2115 } 2116 } 2117 } 2118 2119 private boolean checkNameClash(ClassSymbol origin, Symbol s1, Symbol s2) { 2120 ClashFilter cf = new ClashFilter(origin.type); 2121 return (cf.accepts(s1) && 2122 cf.accepts(s2) && 2123 types.hasSameArgs(s1.erasure(types), s2.erasure(types))); 2124 } 2125 2126 2127 /** Check that all abstract members of given class have definitions. 2128 * @param pos Position to be used for error reporting. 2129 * @param c The class. 2130 */ 2131 void checkAllDefined(DiagnosticPosition pos, ClassSymbol c) { 2132 MethodSymbol undef = types.firstUnimplementedAbstract(c); 2133 if (undef != null) { 2134 MethodSymbol undef1 = 2135 new MethodSymbol(undef.flags(), undef.name, 2136 types.memberType(c.type, undef), undef.owner); 2137 log.error(pos, "does.not.override.abstract", 2138 c, undef1, undef1.location()); 3860 3861 if (whatPackage.modle != inPackage.modle && whatPackage.modle != syms.java_base) { 3862 //check that relativeTo.modle requires transitive what.modle, somehow: 3863 List<ModuleSymbol> todo = List.of(inPackage.modle); 3864 3865 while (todo.nonEmpty()) { 3866 ModuleSymbol current = todo.head; 3867 todo = todo.tail; 3868 if (current == whatPackage.modle) 3869 return ; //OK 3870 for (RequiresDirective req : current.requires) { 3871 if (req.isTransitive()) { 3872 todo = todo.prepend(req.module); 3873 } 3874 } 3875 } 3876 3877 log.warning(LintCategory.EXPORTS, pos, Warnings.LeaksNotAccessibleNotRequiredTransitive(kindName(what), what, what.packge().modle)); 3878 } 3879 } 3880 } | 2099 2100 private void checkClassOverrideEqualsAndHash(DiagnosticPosition pos, 2101 ClassSymbol someClass) { 2102 if (lint.isEnabled(LintCategory.OVERRIDES)) { 2103 MethodSymbol equalsAtObject = (MethodSymbol)syms.objectType 2104 .tsym.members().findFirst(names.equals); 2105 MethodSymbol hashCodeAtObject = (MethodSymbol)syms.objectType 2106 .tsym.members().findFirst(names.hashCode); 2107 boolean overridesEquals = types.implementation(equalsAtObject, 2108 someClass, false, equalsHasCodeFilter).owner == someClass; 2109 boolean overridesHashCode = types.implementation(hashCodeAtObject, 2110 someClass, false, equalsHasCodeFilter) != hashCodeAtObject; 2111 2112 if (overridesEquals && !overridesHashCode) { 2113 log.warning(LintCategory.OVERRIDES, pos, 2114 "override.equals.but.not.hashcode", someClass); 2115 } 2116 } 2117 } 2118 2119 public void checkModuleName (JCModuleDecl tree) { 2120 Name moduleName = tree.sym.name; 2121 Assert.checkNonNull(moduleName); 2122 if (lint.isEnabled(LintCategory.MODULE)) { 2123 String moduleNameString = moduleName.toString(); 2124 int nameLength = moduleNameString.length(); 2125 if (nameLength > 0 && Character.isDigit(moduleNameString.charAt(nameLength - 1))) { 2126 log.warning(Lint.LintCategory.MODULE, tree.qualId.pos(), Warnings.PoorChoiceForModuleName(moduleName)); 2127 } 2128 } 2129 } 2130 2131 private boolean checkNameClash(ClassSymbol origin, Symbol s1, Symbol s2) { 2132 ClashFilter cf = new ClashFilter(origin.type); 2133 return (cf.accepts(s1) && 2134 cf.accepts(s2) && 2135 types.hasSameArgs(s1.erasure(types), s2.erasure(types))); 2136 } 2137 2138 2139 /** Check that all abstract members of given class have definitions. 2140 * @param pos Position to be used for error reporting. 2141 * @param c The class. 2142 */ 2143 void checkAllDefined(DiagnosticPosition pos, ClassSymbol c) { 2144 MethodSymbol undef = types.firstUnimplementedAbstract(c); 2145 if (undef != null) { 2146 MethodSymbol undef1 = 2147 new MethodSymbol(undef.flags(), undef.name, 2148 types.memberType(c.type, undef), undef.owner); 2149 log.error(pos, "does.not.override.abstract", 2150 c, undef1, undef1.location()); 3872 3873 if (whatPackage.modle != inPackage.modle && whatPackage.modle != syms.java_base) { 3874 //check that relativeTo.modle requires transitive what.modle, somehow: 3875 List<ModuleSymbol> todo = List.of(inPackage.modle); 3876 3877 while (todo.nonEmpty()) { 3878 ModuleSymbol current = todo.head; 3879 todo = todo.tail; 3880 if (current == whatPackage.modle) 3881 return ; //OK 3882 for (RequiresDirective req : current.requires) { 3883 if (req.isTransitive()) { 3884 todo = todo.prepend(req.module); 3885 } 3886 } 3887 } 3888 3889 log.warning(LintCategory.EXPORTS, pos, Warnings.LeaksNotAccessibleNotRequiredTransitive(kindName(what), what, what.packge().modle)); 3890 } 3891 } 3892 3893 void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) { 3894 if (msym.kind != MDL) { 3895 deferredLintHandler.report(new DeferredLintHandler.LintLogger() { 3896 @Override 3897 public void report() { 3898 if (lint.isEnabled(Lint.LintCategory.MODULE)) 3899 log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym)); 3900 } 3901 }); 3902 } 3903 } 3904 3905 } |