1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Jun 26 12:22:40 2009 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Jun 26 18:51:39 2009 -0700 1.3 @@ -916,6 +916,10 @@ 1.4 } 1.5 } 1.6 1.7 + public void visitAnnotatedType(JCAnnotatedType tree) { 1.8 + tree.underlyingType.accept(this); 1.9 + } 1.10 + 1.11 /** Default visitor method: do nothing. 1.12 */ 1.13 public void visitTree(JCTree tree) { 1.14 @@ -1806,6 +1810,14 @@ 1.15 validateAnnotation(a, s); 1.16 } 1.17 1.18 + /** Check the type annotations 1.19 + */ 1.20 + public void validateTypeAnnotations(List<JCTypeAnnotation> annotations, boolean isTypeParameter) { 1.21 + if (skipAnnotations) return; 1.22 + for (JCTypeAnnotation a : annotations) 1.23 + validateTypeAnnotation(a, isTypeParameter); 1.24 + } 1.25 + 1.26 /** Check an annotation of a symbol. 1.27 */ 1.28 public void validateAnnotation(JCAnnotation a, Symbol s) { 1.29 @@ -1820,6 +1832,15 @@ 1.30 } 1.31 } 1.32 1.33 + public void validateTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) { 1.34 + if (a.type == null) 1.35 + throw new AssertionError("annotation tree hasn't been attributed yet: " + a); 1.36 + validateAnnotation(a); 1.37 + 1.38 + if (!isTypeAnnotation(a, isTypeParameter)) 1.39 + log.error(a.pos(), "annotation.type.not.applicable"); 1.40 + } 1.41 + 1.42 /** Is s a method symbol that overrides a method in a superclass? */ 1.43 boolean isOverrider(Symbol s) { 1.44 if (s.kind != MTH || s.isStatic()) 1.45 @@ -1838,6 +1859,25 @@ 1.46 return false; 1.47 } 1.48 1.49 + /** Is the annotation applicable to type annotations */ 1.50 + boolean isTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) { 1.51 + Attribute.Compound atTarget = 1.52 + a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); 1.53 + if (atTarget == null) return true; 1.54 + Attribute atValue = atTarget.member(names.value); 1.55 + if (!(atValue instanceof Attribute.Array)) return true; // error recovery 1.56 + Attribute.Array arr = (Attribute.Array) atValue; 1.57 + for (Attribute app : arr.values) { 1.58 + if (!(app instanceof Attribute.Enum)) return true; // recovery 1.59 + Attribute.Enum e = (Attribute.Enum) app; 1.60 + if (!isTypeParameter && e.value.name == names.TYPE_USE) 1.61 + return true; 1.62 + else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER) 1.63 + return true; 1.64 + } 1.65 + return false; 1.66 + } 1.67 + 1.68 /** Is the annotation applicable to the symbol? */ 1.69 boolean annotationApplicable(JCAnnotation a, Symbol s) { 1.70 Attribute.Compound atTarget = 1.71 @@ -1874,6 +1914,13 @@ 1.72 } 1.73 else if (e.value.name == names.PACKAGE) 1.74 { if (s.kind == PCK) return true; } 1.75 + else if (e.value.name == names.TYPE_USE) 1.76 + { if (s.kind == TYP || 1.77 + s.kind == VAR || 1.78 + (s.kind == MTH && !s.isConstructor() && 1.79 + s.type.getReturnType().tag != VOID)) 1.80 + return true; 1.81 + } 1.82 else 1.83 return true; // recovery 1.84 }