28 import java.util.*; |
28 import java.util.*; |
29 |
29 |
30 import javax.tools.JavaFileManager; |
30 import javax.tools.JavaFileManager; |
31 |
31 |
32 import com.sun.tools.javac.code.*; |
32 import com.sun.tools.javac.code.*; |
|
33 import com.sun.tools.javac.code.Attribute.Compound; |
33 import com.sun.tools.javac.jvm.*; |
34 import com.sun.tools.javac.jvm.*; |
34 import com.sun.tools.javac.tree.*; |
35 import com.sun.tools.javac.tree.*; |
35 import com.sun.tools.javac.util.*; |
36 import com.sun.tools.javac.util.*; |
36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
37 import com.sun.tools.javac.util.List; |
38 import com.sun.tools.javac.util.List; |
1949 /** Check that a given method conforms with any method it overrides. |
1950 /** Check that a given method conforms with any method it overrides. |
1950 * @param tree The tree from which positions are extracted |
1951 * @param tree The tree from which positions are extracted |
1951 * for errors. |
1952 * for errors. |
1952 * @param m The overriding method. |
1953 * @param m The overriding method. |
1953 */ |
1954 */ |
1954 void checkOverride(JCTree tree, MethodSymbol m) { |
1955 void checkOverride(JCMethodDecl tree, MethodSymbol m) { |
1955 ClassSymbol origin = (ClassSymbol)m.owner; |
1956 ClassSymbol origin = (ClassSymbol)m.owner; |
1956 if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name)) |
1957 if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name)) |
1957 if (m.overrides(syms.enumFinalFinalize, origin, types, false)) { |
1958 if (m.overrides(syms.enumFinalFinalize, origin, types, false)) { |
1958 log.error(tree.pos(), "enum.no.finalize"); |
1959 log.error(tree.pos(), "enum.no.finalize"); |
1959 return; |
1960 return; |
1964 checkOverride(tree, t, origin, m); |
1965 checkOverride(tree, t, origin, m); |
1965 } |
1966 } |
1966 for (Type t2 : types.interfaces(t)) { |
1967 for (Type t2 : types.interfaces(t)) { |
1967 checkOverride(tree, t2, origin, m); |
1968 checkOverride(tree, t2, origin, m); |
1968 } |
1969 } |
|
1970 } |
|
1971 |
|
1972 if (m.attribute(syms.overrideType.tsym) != null && !isOverrider(m)) { |
|
1973 DiagnosticPosition pos = tree.pos(); |
|
1974 for (JCAnnotation a : tree.getModifiers().annotations) { |
|
1975 if (a.annotationType.type.tsym == syms.overrideType.tsym) { |
|
1976 pos = a.pos(); |
|
1977 break; |
|
1978 } |
|
1979 } |
|
1980 log.error(pos, "method.does.not.override.superclass"); |
1969 } |
1981 } |
1970 } |
1982 } |
1971 |
1983 |
1972 void checkOverride(JCTree tree, Type site, ClassSymbol origin, MethodSymbol m) { |
1984 void checkOverride(JCTree tree, Type site, ClassSymbol origin, MethodSymbol m) { |
1973 TypeSymbol c = site.tsym; |
1985 TypeSymbol c = site.tsym; |
2723 validateAnnotationTree(a); |
2735 validateAnnotationTree(a); |
2724 |
2736 |
2725 if (!annotationApplicable(a, s)) |
2737 if (!annotationApplicable(a, s)) |
2726 log.error(a.pos(), "annotation.type.not.applicable"); |
2738 log.error(a.pos(), "annotation.type.not.applicable"); |
2727 |
2739 |
2728 if (a.annotationType.type.tsym == syms.overrideType.tsym) { |
|
2729 if (!isOverrider(s)) |
|
2730 log.error(a.pos(), "method.does.not.override.superclass"); |
|
2731 } |
|
2732 |
|
2733 if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { |
2740 if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { |
2734 if (s.kind != TYP) { |
2741 if (s.kind != TYP) { |
2735 log.error(a.pos(), "bad.functional.intf.anno"); |
2742 log.error(a.pos(), "bad.functional.intf.anno"); |
2736 } else { |
2743 } else if (!s.isInterface() || (s.flags() & ANNOTATION) != 0) { |
2737 try { |
2744 log.error(a.pos(), "bad.functional.intf.anno.1", diags.fragment("not.a.functional.intf", s)); |
2738 types.findDescriptorSymbol((TypeSymbol)s); |
|
2739 } catch (Types.FunctionDescriptorLookupError ex) { |
|
2740 log.error(a.pos(), "bad.functional.intf.anno.1", ex.getDiagnostic()); |
|
2741 } |
|
2742 } |
2745 } |
2743 } |
2746 } |
2744 } |
2747 } |
2745 |
2748 |
2746 public void validateTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { |
2749 public void validateTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { |
2951 } |
2954 } |
2952 } |
2955 } |
2953 return false; |
2956 return false; |
2954 } |
2957 } |
2955 |
2958 |
2956 /** Is the annotation applicable to type annotations? */ |
2959 /** Is the annotation applicable to types? */ |
2957 protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { |
2960 protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { |
2958 Attribute.Compound atTarget = |
2961 Attribute.Compound atTarget = |
2959 a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); |
2962 a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); |
2960 if (atTarget == null) { |
2963 if (atTarget == null) { |
2961 // An annotation without @Target is not a type annotation. |
2964 // An annotation without @Target is not a type annotation. |
3505 } |
3508 } |
3506 |
3509 |
3507 public Warner convertWarner(DiagnosticPosition pos, Type found, Type expected) { |
3510 public Warner convertWarner(DiagnosticPosition pos, Type found, Type expected) { |
3508 return new ConversionWarner(pos, "unchecked.assign", found, expected); |
3511 return new ConversionWarner(pos, "unchecked.assign", found, expected); |
3509 } |
3512 } |
|
3513 |
|
3514 public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { |
|
3515 Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); |
|
3516 |
|
3517 if (functionalType != null) { |
|
3518 try { |
|
3519 types.findDescriptorSymbol((TypeSymbol)cs); |
|
3520 } catch (Types.FunctionDescriptorLookupError ex) { |
|
3521 DiagnosticPosition pos = tree.pos(); |
|
3522 for (JCAnnotation a : tree.getModifiers().annotations) { |
|
3523 if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { |
|
3524 pos = a.pos(); |
|
3525 break; |
|
3526 } |
|
3527 } |
|
3528 log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); |
|
3529 } |
|
3530 } |
|
3531 } |
3510 } |
3532 } |