--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Oct 14 12:38:09 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Oct 14 22:11:09 2013 +0200
@@ -965,12 +965,6 @@
chk.validateAnnotationType(tree.restype);
// ensure that annotation method does not clash with members of Object/Annotation
chk.validateAnnotationMethod(tree.pos(), m);
-
- if (tree.defaultValue != null) {
- // if default value is an annotation, check it is a well-formed
- // annotation value (e.g. no duplicate values, no missing values, etc.)
- chk.validateAnnotationTree(tree.defaultValue);
- }
}
for (List<JCExpression> l = tree.thrown; l.nonEmpty(); l = l.tail)
@@ -1032,7 +1026,6 @@
localEnv.info.scope.leave();
result = tree.type = m.type;
- chk.validateAnnotations(tree.mods.annotations, m);
}
finally {
chk.setLint(prevLint);
@@ -1090,7 +1083,6 @@
}
}
result = tree.type = v.type;
- chk.validateAnnotations(tree.mods.annotations, v);
}
finally {
chk.setLint(prevLint);
@@ -4155,7 +4147,6 @@
JCCompilationUnit toplevel = env.toplevel;
try {
annotate.flush();
- chk.validateAnnotations(toplevel.packageAnnotations, toplevel.packge);
} catch (CompletionFailure ex) {
chk.completionError(toplevel.pos(), ex);
}
@@ -4240,6 +4231,7 @@
chk.checkDeprecatedAnnotation(env.tree.pos(), c);
chk.checkClassOverrideEqualsAndHashIfNeeded(env.tree.pos(), c);
+ chk.checkFunctionalInterface((JCClassDecl) env.tree, c);
} finally {
env.info.returnResult = prevReturnRes;
log.useSource(prev);
@@ -4258,9 +4250,6 @@
JCClassDecl tree = (JCClassDecl)env.tree;
Assert.check(c == tree.sym);
- // Validate annotations
- chk.validateAnnotations(tree.mods.annotations, c);
-
// Validate type parameters, supertype and interfaces.
attribStats(tree.typarams, env);
if (!c.isAnonymous()) {
@@ -4361,7 +4350,7 @@
typeAnnotations.organizeTypeAnnotationsBodies(tree);
// Check type annotations applicability rules
- validateTypeAnnotations(tree);
+ validateTypeAnnotations(tree, false);
}
}
// where
@@ -4436,14 +4425,19 @@
return types.capture(type);
}
- private void validateTypeAnnotations(JCTree tree) {
- tree.accept(typeAnnotationsValidator);
+ public void validateTypeAnnotations(JCTree tree, boolean sigOnly) {
+ tree.accept(new TypeAnnotationsValidator(sigOnly));
}
//where
- private final JCTree.Visitor typeAnnotationsValidator = new TreeScanner() {
-
+ private final class TypeAnnotationsValidator extends TreeScanner {
+
+ private final boolean sigOnly;
private boolean checkAllAnnotations = false;
+ public TypeAnnotationsValidator(boolean sigOnly) {
+ this.sigOnly = sigOnly;
+ }
+
public void visitAnnotation(JCAnnotation tree) {
if (tree.hasTag(TYPE_ANNOTATION) || checkAllAnnotations) {
chk.validateTypeAnnotation(tree, false);
@@ -4467,12 +4461,26 @@
if (tree.restype != null && tree.restype.type != null) {
validateAnnotatedType(tree.restype, tree.restype.type);
}
- super.visitMethodDef(tree);
+ if (sigOnly) {
+ scan(tree.mods);
+ scan(tree.restype);
+ scan(tree.typarams);
+ scan(tree.recvparam);
+ scan(tree.params);
+ scan(tree.thrown);
+ } else {
+ scan(tree.defaultValue);
+ scan(tree.body);
+ }
}
public void visitVarDef(final JCVariableDecl tree) {
if (tree.sym != null && tree.sym.type != null)
validateAnnotatedType(tree, tree.sym.type);
- super.visitVarDef(tree);
+ scan(tree.mods);
+ scan(tree.vartype);
+ if (!sigOnly) {
+ scan(tree.init);
+ }
}
public void visitTypeCast(JCTypeCast tree) {
if (tree.clazz != null && tree.clazz.type != null)
@@ -4509,6 +4517,29 @@
super.visitNewArray(tree);
}
+ @Override
+ public void visitClassDef(JCClassDecl tree) {
+ if (sigOnly) {
+ scan(tree.mods);
+ scan(tree.typarams);
+ scan(tree.extending);
+ scan(tree.implementing);
+ }
+ for (JCTree member : tree.defs) {
+ if (member.hasTag(Tag.CLASSDEF)) {
+ continue;
+ }
+ scan(member);
+ }
+ }
+
+ @Override
+ public void visitBlock(JCBlock tree) {
+ if (!sigOnly) {
+ scan(tree.stats);
+ }
+ }
+
/* I would want to model this after
* com.sun.tools.javac.comp.Check.Validator.visitSelectInternal(JCFieldAccess)
* and override visitSelect and visitTypeApply.