8035766: Execute TypeAnnotate visitor at queue flush time

Moved execution of TypeAnnotate visitor into Worker for type annotations

Reviewed-by: jjg
This commit is contained in:
Eric McCorkle 2014-02-27 00:29:22 -05:00
parent dd0e29f8b7
commit 816bfaa7bc
3 changed files with 73 additions and 76 deletions
langtools/src/share/classes/com/sun/tools/javac/comp

@ -790,44 +790,69 @@ public class Annotate {
*/
private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations,
final Env<AttrContext> env,
final Symbol s) {
final Symbol s,
final DiagnosticPosition deferPos) {
Map<TypeSymbol, ListBuffer<Attribute.TypeCompound>> annotated = new LinkedHashMap<>();
Map<Attribute.TypeCompound, DiagnosticPosition> pos = new HashMap<>();
for (List<JCAnnotation> 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 (tc == null) {
continue;
}
if (annotated.containsKey(a.type.tsym)) {
if (!allowRepeatedAnnos) {
log.error(a.pos(), "repeatable.annotations.not.supported.in.source");
allowRepeatedAnnos = true;
}
ListBuffer<Attribute.TypeCompound> 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 (deferPos != null) {
prevLintPos = deferredLintHandler.setPos(deferPos);
}
try {
if (s != null) {
s.appendTypeAttributesWithCompletion(
new AnnotateRepeatedContext<>(env, annotated, pos, log, true));
for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
JCAnnotation a = al.head;
Attribute.TypeCompound tc =
enterTypeAnnotation(a, syms.annotationType, env);
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<Attribute.TypeCompound> 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));
}
} finally {
if (prevLintPos != null)
deferredLintHandler.setPos(prevLintPos);
log.useSource(prev);
}
}
public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) {
if (allowTypeAnnos) {
tree.accept(new TypeAnnotate(env, sym, deferPos));
}
public void annotateTypeLater(final JCTree tree,
final Env<AttrContext> 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 @@ public class Annotate {
* annotations. We also need to visit type arguments, etc.
*/
private class TypeAnnotate extends TreeScanner {
private Env<AttrContext> env;
private Symbol sym;
private final Env<AttrContext> env;
private final Symbol sym;
private DiagnosticPosition deferPos;
public TypeAnnotate(final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) {
public TypeAnnotate(final Env<AttrContext> env,
final Symbol sym,
final DiagnosticPosition deferPos) {
this.env = env;
this.sym = sym;
this.deferPos = deferPos;
}
void annotateTypeLater(final List<JCAnnotation> 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<JCAnnotation> dimAnnos : tree.dimAnnotations)
annotateTypeLater(dimAnnos);
actualEnterTypeAnnotations(dimAnnos, env, sym, deferPos);
super.visitNewArray(tree);
}

@ -774,7 +774,7 @@ public class Attr extends JCTree.Visitor {
// 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 @@ public class Attr extends JCTree.Visitor {
}
// 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 @@ public class Attr extends JCTree.Visitor {
} 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 @@ public class Attr extends JCTree.Visitor {
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();
{

@ -607,7 +607,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
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 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
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 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
Env<AttrContext> 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 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
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 &&