# HG changeset patch # User emc # Date 1393478962 18000 # Node ID 6d3b2e246dacaa86234356a614303f737ae73032 # Parent c91951cf65f0ae8f0b2126a90d636c10e86a5add 8035766: Execute TypeAnnotate visitor at queue flush time Summary: Moved execution of TypeAnnotate visitor into Worker for type annotations Reviewed-by: jjg diff -r c91951cf65f0 -r 6d3b2e246dac langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java Wed Feb 26 18:05:02 2014 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java Thu Feb 27 00:29:22 2014 -0500 @@ -790,44 +790,69 @@ */ private void actualEnterTypeAnnotations(final List annotations, final Env env, - final Symbol s) { + final Symbol s, + final DiagnosticPosition deferPos) { Map> annotated = new LinkedHashMap<>(); Map pos = new HashMap<>(); - for (List al = annotations; !al.isEmpty(); al = al.tail) { - JCAnnotation a = al.head; - Attribute.TypeCompound tc = - enterTypeAnnotation(a, syms.annotationType, env); + JavaFileObject prev = log.useSource(env.toplevel.sourcefile); + DiagnosticPosition prevLintPos = null; + + if (deferPos != null) { + prevLintPos = deferredLintHandler.setPos(deferPos); + } + try { + + for (List al = annotations; !al.isEmpty(); al = al.tail) { + JCAnnotation a = al.head; + Attribute.TypeCompound tc = + enterTypeAnnotation(a, syms.annotationType, env); - if (tc == null) { - continue; + if (tc == null) { + continue; + } + + if (annotated.containsKey(a.type.tsym)) { + if (!allowRepeatedAnnos) { + log.error(a.pos(), "repeatable.annotations.not.supported.in.source"); + allowRepeatedAnnos = true; + } + ListBuffer l = annotated.get(a.type.tsym); + l = l.append(tc); + annotated.put(a.type.tsym, l); + pos.put(tc, a.pos()); + } else { + annotated.put(a.type.tsym, ListBuffer.of(tc)); + pos.put(tc, a.pos()); + } } - if (annotated.containsKey(a.type.tsym)) { - if (!allowRepeatedAnnos) { - log.error(a.pos(), "repeatable.annotations.not.supported.in.source"); - allowRepeatedAnnos = true; - } - ListBuffer l = annotated.get(a.type.tsym); - l = l.append(tc); - annotated.put(a.type.tsym, l); - pos.put(tc, a.pos()); - } else { - annotated.put(a.type.tsym, ListBuffer.of(tc)); - pos.put(tc, a.pos()); + if (s != null) { + s.appendTypeAttributesWithCompletion( + new AnnotateRepeatedContext<>(env, annotated, pos, log, true)); } - } - - if (s != null) { - s.appendTypeAttributesWithCompletion( - new AnnotateRepeatedContext<>(env, annotated, pos, log, true)); + } finally { + if (prevLintPos != null) + deferredLintHandler.setPos(prevLintPos); + log.useSource(prev); } } - public void typeAnnotate(final JCTree tree, final Env env, final Symbol sym, DiagnosticPosition deferPos) { - if (allowTypeAnnos) { - tree.accept(new TypeAnnotate(env, sym, deferPos)); - } + public void annotateTypeLater(final JCTree tree, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos) { + + normal(new Annotate.Worker() { + @Override + public String toString() { + return "type annotate " + tree + " onto " + sym + " in " + sym.owner; + } + @Override + public void run() { + tree.accept(new TypeAnnotate(env, sym, deferPos)); + } + }); } /** @@ -835,64 +860,36 @@ * annotations. We also need to visit type arguments, etc. */ private class TypeAnnotate extends TreeScanner { - private Env env; - private Symbol sym; + private final Env env; + private final Symbol sym; private DiagnosticPosition deferPos; - public TypeAnnotate(final Env env, final Symbol sym, DiagnosticPosition deferPos) { + public TypeAnnotate(final Env env, + final Symbol sym, + final DiagnosticPosition deferPos) { + this.env = env; this.sym = sym; this.deferPos = deferPos; } - void annotateTypeLater(final List annotations) { - if (annotations.isEmpty()) { - return; - } - - final DiagnosticPosition deferPos = this.deferPos; - - normal(new Annotate.Worker() { - @Override - public String toString() { - return "type annotate " + annotations + " onto " + sym + " in " + sym.owner; - } - @Override - public void run() { - JavaFileObject prev = log.useSource(env.toplevel.sourcefile); - DiagnosticPosition prevLintPos = null; - - if (deferPos != null) { - prevLintPos = deferredLintHandler.setPos(deferPos); - } - try { - actualEnterTypeAnnotations(annotations, env, sym); - } finally { - if (prevLintPos != null) - deferredLintHandler.setPos(prevLintPos); - log.useSource(prev); - } - } - }); - } - @Override public void visitAnnotatedType(final JCAnnotatedType tree) { - annotateTypeLater(tree.annotations); + actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); super.visitAnnotatedType(tree); } @Override public void visitTypeParameter(final JCTypeParameter tree) { - annotateTypeLater(tree.annotations); + actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); super.visitTypeParameter(tree); } @Override public void visitNewArray(final JCNewArray tree) { - annotateTypeLater(tree.annotations); + actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); for (List dimAnnos : tree.dimAnnotations) - annotateTypeLater(dimAnnos); + actualEnterTypeAnnotations(dimAnnos, env, sym, deferPos); super.visitNewArray(tree); } diff -r c91951cf65f0 -r 6d3b2e246dac langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Feb 26 18:05:02 2014 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Feb 27 00:29:22 2014 -0500 @@ -774,7 +774,7 @@ // to the symbol. // This prevents having multiple type annotations, just because of // lazy constant value evaluation. - annotate.typeAnnotate(variable.init, env, null, variable.pos()); + annotate.annotateTypeLater(variable.init, env, null, variable.pos()); annotate.flush(); Type itype = attribExpr(variable.init, env, type); if (itype.constValue() != null) { @@ -1021,7 +1021,7 @@ } // Attribute all type annotations in the body - annotate.typeAnnotate(tree.body, localEnv, m, null); + annotate.annotateTypeLater(tree.body, localEnv, m, null); annotate.flush(); // Attribute method body. @@ -1050,7 +1050,7 @@ } else { if (tree.init != null) { // Field initializer expression need to be entered. - annotate.typeAnnotate(tree.init, env, tree.sym, tree.pos()); + annotate.annotateTypeLater(tree.init, env, tree.sym, tree.pos()); annotate.flush(); } } @@ -1111,7 +1111,7 @@ if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; // Attribute all type annotations in the block - annotate.typeAnnotate(tree, localEnv, localEnv.info.scope.owner, null); + annotate.annotateTypeLater(tree, localEnv, localEnv.info.scope.owner, null); annotate.flush(); { diff -r c91951cf65f0 -r 6d3b2e246dac langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Feb 26 18:05:02 2014 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Feb 27 00:29:22 2014 -0500 @@ -607,7 +607,7 @@ annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); // Visit the signature of the method. Note that // TypeAnnotate doesn't descend into the body. - annotate.typeAnnotate(tree, localEnv, m, tree.pos()); + annotate.annotateTypeLater(tree, localEnv, m, tree.pos()); if (tree.defaultValue != null) annotateDefaultValueLater(tree.defaultValue, localEnv, m); @@ -698,7 +698,7 @@ enclScope.enter(v); } annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); - annotate.typeAnnotate(tree.vartype, env, v, tree.pos()); + annotate.annotateTypeLater(tree.vartype, env, v, tree.pos()); v.pos = tree.pos; } finally { annotate.enterDone(); @@ -939,9 +939,9 @@ Env baseEnv = baseEnv(tree, env); if (tree.extending != null) - annotate.typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); + annotate.annotateTypeLater(tree.extending, baseEnv, sym, tree.pos()); for (JCExpression impl : tree.implementing) - annotate.typeAnnotate(impl, baseEnv, sym, tree.pos()); + annotate.annotateTypeLater(impl, baseEnv, sym, tree.pos()); annotate.flush(); // Determine supertype. @@ -1010,7 +1010,7 @@ attr.attribTypeVariables(tree.typarams, baseEnv); // Do this here, where we have the symbol. for (JCTypeParameter tp : tree.typarams) - annotate.typeAnnotate(tp, baseEnv, sym, tree.pos()); + annotate.annotateTypeLater(tp, baseEnv, sym, tree.pos()); // Add default constructor if needed. if ((c.flags() & INTERFACE) == 0 &&