--- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sat Sep 14 19:04:47 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Mon Sep 16 14:13:44 2013 +0200
@@ -84,6 +84,7 @@
private final Source source;
private final Target target;
private final DeferredLintHandler deferredLintHandler;
+ private final Lint lint;
public static MemberEnter instance(Context context) {
MemberEnter instance = context.get(memberEnterKey);
@@ -109,6 +110,7 @@
source = Source.instance(context);
target = Target.instance(context);
deferredLintHandler = DeferredLintHandler.instance(context);
+ lint = Lint.instance(context);
allowTypeAnnos = source.allowTypeAnnotations();
}
@@ -506,9 +508,10 @@
}
// process package annotations
- annotateLater(tree.packageAnnotations, env, tree.packge);
+ annotateLater(tree.packageAnnotations, env, tree.packge, null);
- DeferredLintHandler prevLintHandler = chk.setDeferredLintHandler(DeferredLintHandler.immediateHandler);
+ DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
+ Lint prevLint = chk.setLint(lint);
try {
// Import-on-demand java.lang.
@@ -517,7 +520,8 @@
// Process all import clauses.
memberEnter(tree.defs, env);
} finally {
- chk.setDeferredLintHandler(prevLintHandler);
+ chk.setLint(prevLint);
+ deferredLintHandler.setPos(prevLintPos);
}
}
@@ -564,8 +568,7 @@
Env<AttrContext> localEnv = methodEnv(tree, env);
- DeferredLintHandler prevLintHandler =
- chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
+ DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
try {
// Compute the method type
m.type = signature(m, tree.typarams, tree.params,
@@ -573,7 +576,7 @@
tree.thrown,
localEnv);
} finally {
- chk.setDeferredLintHandler(prevLintHandler);
+ deferredLintHandler.setPos(prevLintPos);
}
if (types.isSignaturePolymorphic(m)) {
@@ -597,10 +600,10 @@
if (chk.checkUnique(tree.pos(), m, enclScope)) {
enclScope.enter(m);
}
- annotateLater(tree.mods.annotations, localEnv, m);
+ annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
// Visit the signature of the method. Note that
// TypeAnnotate doesn't descend into the body.
- typeAnnotate(tree, localEnv, m);
+ typeAnnotate(tree, localEnv, m, tree.pos());
if (tree.defaultValue != null)
annotateDefaultValueLater(tree.defaultValue, localEnv, m);
@@ -630,15 +633,14 @@
localEnv = env.dup(tree, env.info.dup());
localEnv.info.staticLevel++;
}
- DeferredLintHandler prevLintHandler =
- chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
+ DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
try {
if (TreeInfo.isEnumInit(tree)) {
attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
} else {
// Make sure type annotations are processed.
// But we don't have a symbol to attach them to yet - use null.
- typeAnnotate(tree.vartype, env, null);
+ typeAnnotate(tree.vartype, env, null, tree.pos());
attr.attribType(tree.vartype, localEnv);
if (tree.nameexpr != null) {
attr.attribExpr(tree.nameexpr, localEnv);
@@ -658,7 +660,7 @@
}
}
} finally {
- chk.setDeferredLintHandler(prevLintHandler);
+ deferredLintHandler.setPos(prevLintPos);
}
if ((tree.mods.flags & VARARGS) != 0) {
@@ -680,15 +682,15 @@
needsLazyConstValue(tree.init)) {
Env<AttrContext> initEnv = getInitEnv(tree, env);
initEnv.info.enclVar = v;
- v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init);
+ v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
}
}
if (chk.checkUnique(tree.pos(), v, enclScope)) {
chk.checkTransparentVar(tree.pos(), v, enclScope);
enclScope.enter(v);
}
- annotateLater(tree.mods.annotations, localEnv, v);
- typeAnnotate(tree.vartype, env, v);
+ annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
+ typeAnnotate(tree.vartype, env, v, tree.pos());
annotate.flush();
v.pos = tree.pos;
}
@@ -720,6 +722,11 @@
}
@Override
+ public void visitNewArray(JCNewArray that) {
+ result = false;
+ }
+
+ @Override
public void visitLambda(JCLambda that) {
result = false;
}
@@ -730,6 +737,11 @@
}
@Override
+ public void visitApply(JCMethodInvocation that) {
+ result = false;
+ }
+
+ @Override
public void visitSelect(JCFieldAccess tree) {
tree.selected.accept(this);
}
@@ -820,7 +832,8 @@
/** Queue annotations for later processing. */
void annotateLater(final List<JCAnnotation> annotations,
final Env<AttrContext> localEnv,
- final Symbol s) {
+ final Symbol s,
+ final DiagnosticPosition deferPos) {
if (annotations.isEmpty()) {
return;
}
@@ -837,6 +850,11 @@
public void enterAnnotation() {
Assert.check(s.kind == PCK || s.annotationsPendingCompletion());
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
+ DiagnosticPosition prevLintPos =
+ deferPos != null
+ ? deferredLintHandler.setPos(deferPos)
+ : deferredLintHandler.immediate();
+ Lint prevLint = deferPos != null ? null : chk.setLint(lint);
try {
if (s.hasAnnotations() &&
annotations.nonEmpty())
@@ -845,6 +863,9 @@
kindName(s), s);
actualEnterAnnotations(annotations, localEnv, s);
} finally {
+ if (prevLint != null)
+ chk.setLint(prevLint);
+ deferredLintHandler.setPos(prevLintPos);
log.useSource(prev);
}
}
@@ -964,6 +985,7 @@
isFirst = false;
JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
+ DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
try {
// Save class environment for later member enter (2) processing.
halfcompleted.append(env);
@@ -985,9 +1007,9 @@
Env<AttrContext> baseEnv = baseEnv(tree, env);
if (tree.extending != null)
- typeAnnotate(tree.extending, baseEnv, sym);
+ typeAnnotate(tree.extending, baseEnv, sym, tree.pos());
for (JCExpression impl : tree.implementing)
- typeAnnotate(impl, baseEnv, sym);
+ typeAnnotate(impl, baseEnv, sym, tree.pos());
annotate.flush();
// Determine supertype.
@@ -1048,7 +1070,7 @@
attr.attribAnnotationTypes(tree.mods.annotations, baseEnv);
if (hasDeprecatedAnnotation(tree.mods.annotations))
c.flags_field |= DEPRECATED;
- annotateLater(tree.mods.annotations, baseEnv, c);
+ annotateLater(tree.mods.annotations, baseEnv, c, tree.pos());
// class type parameters use baseEnv but everything uses env
chk.checkNonCyclicDecl(tree);
@@ -1056,7 +1078,7 @@
attr.attribTypeVariables(tree.typarams, baseEnv);
// Do this here, where we have the symbol.
for (JCTypeParameter tp : tree.typarams)
- typeAnnotate(tp, baseEnv, sym);
+ typeAnnotate(tp, baseEnv, sym, tree.pos());
annotate.flush();
// Add default constructor if needed.
@@ -1126,6 +1148,7 @@
} catch (CompletionFailure ex) {
chk.completionError(tree.pos(), ex);
} finally {
+ deferredLintHandler.setPos(prevLintPos);
log.useSource(prev);
}
@@ -1186,9 +1209,9 @@
}
}
- public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym) {
+ public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) {
if (allowTypeAnnos) {
- tree.accept(new TypeAnnotate(env, sym));
+ tree.accept(new TypeAnnotate(env, sym, deferPos));
}
}
@@ -1199,10 +1222,12 @@
private class TypeAnnotate extends TreeScanner {
private Env<AttrContext> env;
private Symbol sym;
+ private DiagnosticPosition deferPos;
- public TypeAnnotate(final Env<AttrContext> env, final Symbol sym) {
+ public TypeAnnotate(final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) {
this.env = env;
this.sym = sym;
+ this.deferPos = deferPos;
}
void annotateTypeLater(final List<JCAnnotation> annotations) {
@@ -1210,6 +1235,8 @@
return;
}
+ final DiagnosticPosition deferPos = this.deferPos;
+
annotate.normal(new Annotate.Annotator() {
@Override
public String toString() {
@@ -1218,9 +1245,16 @@
@Override
public void enterAnnotation() {
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);
}
}
@@ -1262,13 +1296,19 @@
@Override
public void visitVarDef(final JCVariableDecl tree) {
- if (sym != null && sym.kind == Kinds.VAR) {
- // Don't visit a parameter once when the sym is the method
- // and once when the sym is the parameter.
- scan(tree.mods);
- scan(tree.vartype);
+ DiagnosticPosition prevPos = deferPos;
+ deferPos = tree.pos();
+ try {
+ if (sym != null && sym.kind == Kinds.VAR) {
+ // Don't visit a parameter once when the sym is the method
+ // and once when the sym is the parameter.
+ scan(tree.mods);
+ scan(tree.vartype);
+ }
+ scan(tree.init);
+ } finally {
+ deferPos = prevPos;
}
- scan(tree.init);
}
@Override