1282 checkDisjoint(pos, flags,
1283 PRIVATE,
1284 PUBLIC | PROTECTED)
1285 &&
1286 checkDisjoint(pos, flags,
1287 FINAL,
1288 VOLATILE)
1289 &&
1290 (sym.kind == TYP ||
1291 checkDisjoint(pos, flags,
1292 ABSTRACT | NATIVE,
1293 STRICTFP))) {
1294 // skip
1295 }
1296 return flags & (mask | ~ExtendedStandardFlags) | implicit;
1297 }
1298
1299
1300 /** Determine if this enum should be implicitly final.
1301 *
1302 * If the enum has no specialized enum contants, it is final.
1303 *
1304 * If the enum does have specialized enum contants, it is
1305 * <i>not</i> final.
1306 */
1307 private long implicitEnumFinalFlag(JCTree tree) {
1308 if (!tree.hasTag(CLASSDEF)) return 0;
1309 class SpecialTreeVisitor extends JCTree.Visitor {
1310 boolean specialized;
1311 SpecialTreeVisitor() {
1312 this.specialized = false;
1313 }
1314
1315 @Override
1316 public void visitTree(JCTree tree) { /* no-op */ }
1317
1318 @Override
1319 public void visitVarDef(JCVariableDecl tree) {
1320 if ((tree.mods.flags & ENUM) != 0) {
1321 if (tree.init instanceof JCNewClass &&
1322 ((JCNewClass) tree.init).def != null) {
1323 specialized = true;
1324 }
1844 Warnings.OverrideBridge(uncheckedOverrides(m, other)));
1845 }
1846
1847 // Warn if a deprecated method overridden by a non-deprecated one.
1848 if (!isDeprecatedOverrideIgnorable(other, origin)) {
1849 Lint prevLint = setLint(lint.augment(m));
1850 try {
1851 checkDeprecated(() -> TreeInfo.diagnosticPositionFor(m, tree), m, other);
1852 } finally {
1853 setLint(prevLint);
1854 }
1855 }
1856 }
1857 // where
1858 private boolean isDeprecatedOverrideIgnorable(MethodSymbol m, ClassSymbol origin) {
1859 // If the method, m, is defined in an interface, then ignore the issue if the method
1860 // is only inherited via a supertype and also implemented in the supertype,
1861 // because in that case, we will rediscover the issue when examining the method
1862 // in the supertype.
1863 // If the method, m, is not defined in an interface, then the only time we need to
1864 // address the issue is when the method is the supertype implemementation: any other
1865 // case, we will have dealt with when examining the supertype classes
1866 ClassSymbol mc = m.enclClass();
1867 Type st = types.supertype(origin.type);
1868 if (!st.hasTag(CLASS))
1869 return true;
1870 MethodSymbol stimpl = m.implementation((ClassSymbol)st.tsym, types, false);
1871
1872 if (mc != null && ((mc.flags() & INTERFACE) != 0)) {
1873 List<Type> intfs = types.interfaces(origin.type);
1874 return (intfs.contains(mc.type) ? false : (stimpl != null));
1875 }
1876 else
1877 return (stimpl != m);
1878 }
1879
1880
1881 // used to check if there were any unchecked conversions
1882 Warner overrideWarner = new Warner();
1883
1884 /** Check that a class does not inherit two concrete methods
1965
1966 for (Type t3 : interfaces1.values()) {
1967 for (Type t4 : interfaces2.values()) {
1968 Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
1969 if (s != null) return s;
1970 }
1971 }
1972 return null;
1973 }
1974
1975 /** Compute all the supertypes of t, indexed by type symbol. */
1976 private void closure(Type t, Map<TypeSymbol,Type> typeMap) {
1977 if (!t.hasTag(CLASS)) return;
1978 if (typeMap.put(t.tsym, t) == null) {
1979 closure(types.supertype(t), typeMap);
1980 for (Type i : types.interfaces(t))
1981 closure(i, typeMap);
1982 }
1983 }
1984
1985 /** Compute all the supertypes of t, indexed by type symbol (except thise in typesSkip). */
1986 private void closure(Type t, Map<TypeSymbol,Type> typesSkip, Map<TypeSymbol,Type> typeMap) {
1987 if (!t.hasTag(CLASS)) return;
1988 if (typesSkip.get(t.tsym) != null) return;
1989 if (typeMap.put(t.tsym, t) == null) {
1990 closure(types.supertype(t), typesSkip, typeMap);
1991 for (Type i : types.interfaces(t))
1992 closure(i, typesSkip, typeMap);
1993 }
1994 }
1995
1996 /** Return the first method in t2 that conflicts with a method from t1. */
1997 private Symbol firstDirectIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
1998 for (Symbol s1 : t1.tsym.members().getSymbols(NON_RECURSIVE)) {
1999 Type st1 = null;
2000 if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types) ||
2001 (s1.flags() & SYNTHETIC) != 0) continue;
2002 Symbol impl = ((MethodSymbol)s1).implementation(site.tsym, types, false);
2003 if (impl != null && (impl.flags() & ABSTRACT) == 0) continue;
2004 for (Symbol s2 : t2.tsym.members().getSymbolsByName(s1.name)) {
2005 if (s1 == s2) continue;
2661 if (args1.length() != args2.length()) return;
2662 boolean potentiallyAmbiguous = false;
2663 while (args1.nonEmpty() && args2.nonEmpty()) {
2664 Type s = args1.head;
2665 Type t = args2.head;
2666 if (!types.isSubtype(t, s) && !types.isSubtype(s, t)) {
2667 if (types.isFunctionalInterface(s) && types.isFunctionalInterface(t) &&
2668 types.findDescriptorType(s).getParameterTypes().length() > 0 &&
2669 types.findDescriptorType(s).getParameterTypes().length() ==
2670 types.findDescriptorType(t).getParameterTypes().length()) {
2671 potentiallyAmbiguous = true;
2672 } else {
2673 break;
2674 }
2675 }
2676 args1 = args1.tail;
2677 args2 = args2.tail;
2678 }
2679 if (potentiallyAmbiguous) {
2680 //we found two incompatible functional interfaces with same arity
2681 //this means a call site passing an implicit lambda would be ambigiuous
2682 msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
2683 msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
2684 log.warning(LintCategory.OVERLOADS, pos,
2685 Warnings.PotentiallyAmbiguousOverload(msym1, msym1.location(),
2686 msym2, msym2.location()));
2687 return;
2688 }
2689 }
2690 }
2691
2692 void checkAccessFromSerializableElement(final JCTree tree, boolean isLambda) {
2693 if (warnOnAnyAccessToMembers ||
2694 (lint.isEnabled(LintCategory.SERIAL) &&
2695 !lint.isSuppressed(LintCategory.SERIAL) &&
2696 isLambda)) {
2697 Symbol sym = TreeInfo.symbol(tree);
2698 if (!sym.kind.matches(KindSelector.VAL_MTH)) {
2699 return;
2700 }
2701
3259 (s.owner.kind == MTH && (s.flags() & PARAMETER) != 0)) {
3260 return true;
3261 }
3262 } else if (target == names.CONSTRUCTOR) {
3263 if (s.kind == MTH && s.isConstructor())
3264 return true;
3265 } else if (target == names.LOCAL_VARIABLE) {
3266 if (s.kind == VAR && s.owner.kind == MTH &&
3267 (s.flags() & PARAMETER) == 0) {
3268 return true;
3269 }
3270 } else if (target == names.ANNOTATION_TYPE) {
3271 if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) {
3272 return true;
3273 }
3274 } else if (target == names.PACKAGE) {
3275 if (s.kind == PCK)
3276 return true;
3277 } else if (target == names.TYPE_USE) {
3278 if (s.kind == VAR && s.owner.kind == MTH && s.type.hasTag(NONE)) {
3279 //cannot type annotate implictly typed locals
3280 return false;
3281 } else if (s.kind == TYP || s.kind == VAR ||
3282 (s.kind == MTH && !s.isConstructor() &&
3283 !s.type.getReturnType().hasTag(VOID)) ||
3284 (s.kind == MTH && s.isConstructor())) {
3285 return true;
3286 }
3287 } else if (target == names.TYPE_PARAMETER) {
3288 if (s.kind == TYP && s.type.hasTag(TYPEVAR))
3289 return true;
3290 } else
3291 return true; // Unknown ElementType. This should be an error at declaration site,
3292 // assume applicable.
3293 }
3294 return false;
3295 }
3296
3297 Attribute.Array getAttributeTargetAttribute(TypeSymbol s) {
3298 Attribute.Compound atTarget = s.getAnnotationTypeMetadata().getTarget();
3299 if (atTarget == null) return null; // ok, is applicable
3590 if (sym.owner.name == names.any) return false;
3591 for (Symbol byName : s.getSymbolsByName(sym.name, NON_RECURSIVE)) {
3592 if (sym != byName &&
3593 (byName.flags() & CLASH) == 0 &&
3594 sym.kind == byName.kind &&
3595 sym.name != names.error &&
3596 (sym.kind != MTH ||
3597 types.hasSameArgs(sym.type, byName.type) ||
3598 types.hasSameArgs(types.erasure(sym.type), types.erasure(byName.type)))) {
3599 if ((sym.flags() & VARARGS) != (byName.flags() & VARARGS)) {
3600 sym.flags_field |= CLASH;
3601 varargsDuplicateError(pos, sym, byName);
3602 return true;
3603 } else if (sym.kind == MTH && !types.hasSameArgs(sym.type, byName.type, false)) {
3604 duplicateErasureError(pos, sym, byName);
3605 sym.flags_field |= CLASH;
3606 return true;
3607 } else if ((sym.flags() & MATCH_BINDING) != 0 &&
3608 (byName.flags() & MATCH_BINDING) != 0 &&
3609 (byName.flags() & MATCH_BINDING_TO_OUTER) == 0) {
3610 //this error will be reported separatelly in MatchBindingsComputer
3611 return false;
3612 } else {
3613 duplicateError(pos, byName);
3614 return false;
3615 }
3616 }
3617 }
3618 return true;
3619 }
3620
3621 /** Report duplicate declaration error.
3622 */
3623 void duplicateErasureError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) {
3624 if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) {
3625 log.error(pos, Errors.NameClashSameErasure(sym1, sym2));
3626 }
3627 }
3628
3629 /**Check that types imported through the ordinary imports don't clash with types imported
3630 * by other (static or ordinary) imports. Note that two static imports may import two clashing
|
1282 checkDisjoint(pos, flags,
1283 PRIVATE,
1284 PUBLIC | PROTECTED)
1285 &&
1286 checkDisjoint(pos, flags,
1287 FINAL,
1288 VOLATILE)
1289 &&
1290 (sym.kind == TYP ||
1291 checkDisjoint(pos, flags,
1292 ABSTRACT | NATIVE,
1293 STRICTFP))) {
1294 // skip
1295 }
1296 return flags & (mask | ~ExtendedStandardFlags) | implicit;
1297 }
1298
1299
1300 /** Determine if this enum should be implicitly final.
1301 *
1302 * If the enum has no specialized enum constants, it is final.
1303 *
1304 * If the enum does have specialized enum constants, it is
1305 * <i>not</i> final.
1306 */
1307 private long implicitEnumFinalFlag(JCTree tree) {
1308 if (!tree.hasTag(CLASSDEF)) return 0;
1309 class SpecialTreeVisitor extends JCTree.Visitor {
1310 boolean specialized;
1311 SpecialTreeVisitor() {
1312 this.specialized = false;
1313 }
1314
1315 @Override
1316 public void visitTree(JCTree tree) { /* no-op */ }
1317
1318 @Override
1319 public void visitVarDef(JCVariableDecl tree) {
1320 if ((tree.mods.flags & ENUM) != 0) {
1321 if (tree.init instanceof JCNewClass &&
1322 ((JCNewClass) tree.init).def != null) {
1323 specialized = true;
1324 }
1844 Warnings.OverrideBridge(uncheckedOverrides(m, other)));
1845 }
1846
1847 // Warn if a deprecated method overridden by a non-deprecated one.
1848 if (!isDeprecatedOverrideIgnorable(other, origin)) {
1849 Lint prevLint = setLint(lint.augment(m));
1850 try {
1851 checkDeprecated(() -> TreeInfo.diagnosticPositionFor(m, tree), m, other);
1852 } finally {
1853 setLint(prevLint);
1854 }
1855 }
1856 }
1857 // where
1858 private boolean isDeprecatedOverrideIgnorable(MethodSymbol m, ClassSymbol origin) {
1859 // If the method, m, is defined in an interface, then ignore the issue if the method
1860 // is only inherited via a supertype and also implemented in the supertype,
1861 // because in that case, we will rediscover the issue when examining the method
1862 // in the supertype.
1863 // If the method, m, is not defined in an interface, then the only time we need to
1864 // address the issue is when the method is the supertype implementation: any other
1865 // case, we will have dealt with when examining the supertype classes
1866 ClassSymbol mc = m.enclClass();
1867 Type st = types.supertype(origin.type);
1868 if (!st.hasTag(CLASS))
1869 return true;
1870 MethodSymbol stimpl = m.implementation((ClassSymbol)st.tsym, types, false);
1871
1872 if (mc != null && ((mc.flags() & INTERFACE) != 0)) {
1873 List<Type> intfs = types.interfaces(origin.type);
1874 return (intfs.contains(mc.type) ? false : (stimpl != null));
1875 }
1876 else
1877 return (stimpl != m);
1878 }
1879
1880
1881 // used to check if there were any unchecked conversions
1882 Warner overrideWarner = new Warner();
1883
1884 /** Check that a class does not inherit two concrete methods
1965
1966 for (Type t3 : interfaces1.values()) {
1967 for (Type t4 : interfaces2.values()) {
1968 Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
1969 if (s != null) return s;
1970 }
1971 }
1972 return null;
1973 }
1974
1975 /** Compute all the supertypes of t, indexed by type symbol. */
1976 private void closure(Type t, Map<TypeSymbol,Type> typeMap) {
1977 if (!t.hasTag(CLASS)) return;
1978 if (typeMap.put(t.tsym, t) == null) {
1979 closure(types.supertype(t), typeMap);
1980 for (Type i : types.interfaces(t))
1981 closure(i, typeMap);
1982 }
1983 }
1984
1985 /** Compute all the supertypes of t, indexed by type symbol (except this in typesSkip). */
1986 private void closure(Type t, Map<TypeSymbol,Type> typesSkip, Map<TypeSymbol,Type> typeMap) {
1987 if (!t.hasTag(CLASS)) return;
1988 if (typesSkip.get(t.tsym) != null) return;
1989 if (typeMap.put(t.tsym, t) == null) {
1990 closure(types.supertype(t), typesSkip, typeMap);
1991 for (Type i : types.interfaces(t))
1992 closure(i, typesSkip, typeMap);
1993 }
1994 }
1995
1996 /** Return the first method in t2 that conflicts with a method from t1. */
1997 private Symbol firstDirectIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
1998 for (Symbol s1 : t1.tsym.members().getSymbols(NON_RECURSIVE)) {
1999 Type st1 = null;
2000 if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types) ||
2001 (s1.flags() & SYNTHETIC) != 0) continue;
2002 Symbol impl = ((MethodSymbol)s1).implementation(site.tsym, types, false);
2003 if (impl != null && (impl.flags() & ABSTRACT) == 0) continue;
2004 for (Symbol s2 : t2.tsym.members().getSymbolsByName(s1.name)) {
2005 if (s1 == s2) continue;
2661 if (args1.length() != args2.length()) return;
2662 boolean potentiallyAmbiguous = false;
2663 while (args1.nonEmpty() && args2.nonEmpty()) {
2664 Type s = args1.head;
2665 Type t = args2.head;
2666 if (!types.isSubtype(t, s) && !types.isSubtype(s, t)) {
2667 if (types.isFunctionalInterface(s) && types.isFunctionalInterface(t) &&
2668 types.findDescriptorType(s).getParameterTypes().length() > 0 &&
2669 types.findDescriptorType(s).getParameterTypes().length() ==
2670 types.findDescriptorType(t).getParameterTypes().length()) {
2671 potentiallyAmbiguous = true;
2672 } else {
2673 break;
2674 }
2675 }
2676 args1 = args1.tail;
2677 args2 = args2.tail;
2678 }
2679 if (potentiallyAmbiguous) {
2680 //we found two incompatible functional interfaces with same arity
2681 //this means a call site passing an implicit lambda would be ambiguous
2682 msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
2683 msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
2684 log.warning(LintCategory.OVERLOADS, pos,
2685 Warnings.PotentiallyAmbiguousOverload(msym1, msym1.location(),
2686 msym2, msym2.location()));
2687 return;
2688 }
2689 }
2690 }
2691
2692 void checkAccessFromSerializableElement(final JCTree tree, boolean isLambda) {
2693 if (warnOnAnyAccessToMembers ||
2694 (lint.isEnabled(LintCategory.SERIAL) &&
2695 !lint.isSuppressed(LintCategory.SERIAL) &&
2696 isLambda)) {
2697 Symbol sym = TreeInfo.symbol(tree);
2698 if (!sym.kind.matches(KindSelector.VAL_MTH)) {
2699 return;
2700 }
2701
3259 (s.owner.kind == MTH && (s.flags() & PARAMETER) != 0)) {
3260 return true;
3261 }
3262 } else if (target == names.CONSTRUCTOR) {
3263 if (s.kind == MTH && s.isConstructor())
3264 return true;
3265 } else if (target == names.LOCAL_VARIABLE) {
3266 if (s.kind == VAR && s.owner.kind == MTH &&
3267 (s.flags() & PARAMETER) == 0) {
3268 return true;
3269 }
3270 } else if (target == names.ANNOTATION_TYPE) {
3271 if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) {
3272 return true;
3273 }
3274 } else if (target == names.PACKAGE) {
3275 if (s.kind == PCK)
3276 return true;
3277 } else if (target == names.TYPE_USE) {
3278 if (s.kind == VAR && s.owner.kind == MTH && s.type.hasTag(NONE)) {
3279 //cannot type annotate implicitly typed locals
3280 return false;
3281 } else if (s.kind == TYP || s.kind == VAR ||
3282 (s.kind == MTH && !s.isConstructor() &&
3283 !s.type.getReturnType().hasTag(VOID)) ||
3284 (s.kind == MTH && s.isConstructor())) {
3285 return true;
3286 }
3287 } else if (target == names.TYPE_PARAMETER) {
3288 if (s.kind == TYP && s.type.hasTag(TYPEVAR))
3289 return true;
3290 } else
3291 return true; // Unknown ElementType. This should be an error at declaration site,
3292 // assume applicable.
3293 }
3294 return false;
3295 }
3296
3297 Attribute.Array getAttributeTargetAttribute(TypeSymbol s) {
3298 Attribute.Compound atTarget = s.getAnnotationTypeMetadata().getTarget();
3299 if (atTarget == null) return null; // ok, is applicable
3590 if (sym.owner.name == names.any) return false;
3591 for (Symbol byName : s.getSymbolsByName(sym.name, NON_RECURSIVE)) {
3592 if (sym != byName &&
3593 (byName.flags() & CLASH) == 0 &&
3594 sym.kind == byName.kind &&
3595 sym.name != names.error &&
3596 (sym.kind != MTH ||
3597 types.hasSameArgs(sym.type, byName.type) ||
3598 types.hasSameArgs(types.erasure(sym.type), types.erasure(byName.type)))) {
3599 if ((sym.flags() & VARARGS) != (byName.flags() & VARARGS)) {
3600 sym.flags_field |= CLASH;
3601 varargsDuplicateError(pos, sym, byName);
3602 return true;
3603 } else if (sym.kind == MTH && !types.hasSameArgs(sym.type, byName.type, false)) {
3604 duplicateErasureError(pos, sym, byName);
3605 sym.flags_field |= CLASH;
3606 return true;
3607 } else if ((sym.flags() & MATCH_BINDING) != 0 &&
3608 (byName.flags() & MATCH_BINDING) != 0 &&
3609 (byName.flags() & MATCH_BINDING_TO_OUTER) == 0) {
3610 //this error will be reported separately in MatchBindingsComputer
3611 return false;
3612 } else {
3613 duplicateError(pos, byName);
3614 return false;
3615 }
3616 }
3617 }
3618 return true;
3619 }
3620
3621 /** Report duplicate declaration error.
3622 */
3623 void duplicateErasureError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) {
3624 if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) {
3625 log.error(pos, Errors.NameClashSameErasure(sym1, sym2));
3626 }
3627 }
3628
3629 /**Check that types imported through the ordinary imports don't clash with types imported
3630 * by other (static or ordinary) imports. Note that two static imports may import two clashing
|