mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 22:16:11 +00:00
[i694] When we resolve anything with inner classes, supertype references in those inner classes
that also have val will break, depending on compile order. This should fix it.
This commit is contained in:
1 parent
e5705f94cd
commit
6a91c013ca
5 files changed
+59
-3
No files matched your search
@@ -241,7 +241,7 @@ public class JavacResolution {
|
||||
Type type0 = type;
|
||||
while (type0 instanceof ArrayType) {
|
||||
dims++;
|
||||
type0 = ((ArrayType)type0).elemtype;
|
||||
type0 = ((ArrayType) type0).elemtype;
|
||||
}
|
||||
|
||||
JCExpression result = typeToJCTree0(type0, ast, allowCompound, allowVoid);
|
||||
|
||||
@@ -28,13 +28,14 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.Messager;
|
||||
@@ -217,7 +218,17 @@ public class Processor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private final IdentityHashMap<JCCompilationUnit, Long> roots = new IdentityHashMap<JCCompilationUnit, Long>();
|
||||
// DEBUG - We just blithely assume that there's always a sourcefile.getName() component, and that the performance impact of this is not relevant.
|
||||
// - ... but mostly the 'just blithely assume there's a sourcefile' part means we shouldn't just roll this out.
|
||||
private final Map<JCCompilationUnit,Long> roots = new TreeMap<JCCompilationUnit, Long>(new Comparator<JCCompilationUnit>() {
|
||||
@Override public int compare(JCCompilationUnit o1, JCCompilationUnit o2) {
|
||||
if (o1 == o2) return 0;
|
||||
|
||||
int c = o1.sourcefile.getName().compareTo(o2.sourcefile.getName());
|
||||
if (c != 0) return c;
|
||||
return System.identityHashCode(o1) < System.identityHashCode(o2) ? -1 : +1;
|
||||
}
|
||||
});
|
||||
private long[] priorityLevels;
|
||||
private Set<Long> priorityLevelsRequiringResolutionReset;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import lombok.javac.ResolutionResetNeeded;
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.code.Symtab;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
@@ -110,6 +111,16 @@ public class HandleVal extends JavacASTAdapter {
|
||||
}
|
||||
} else {
|
||||
type = local.init.type;
|
||||
if (type.isErroneous()) {
|
||||
try {
|
||||
JavacResolution resolver = new JavacResolution(localNode.getContext());
|
||||
local.type = Symtab.instance(localNode.getContext()).unknownType;
|
||||
type = ((JCExpression) resolver.resolveMethodMember(localNode).get(local.init)).type;
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println("Exception while resolving: " + localNode);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (rhsOfEnhancedForLoop.type == null) {
|
||||
|
||||
@@ -162,6 +162,9 @@ public class Javac {
|
||||
public static final TypeTag CTC_VOID = typeTag("VOID");
|
||||
public static final TypeTag CTC_NONE = typeTag("NONE");
|
||||
public static final TypeTag CTC_BOT = typeTag("BOT");
|
||||
public static final TypeTag CTC_ERROR = typeTag("ERROR");
|
||||
public static final TypeTag CTC_UNKNOWN = typeTag("UNKNOWN");
|
||||
public static final TypeTag CTC_UNDETVAR = typeTag("UNDETVAR");
|
||||
public static final TypeTag CTC_CLASS = typeTag("CLASS");
|
||||
|
||||
public static final TreeTag CTC_NOT_EQUAL = treeTag("NE");
|
||||
|
||||
@@ -26,9 +26,16 @@ import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static lombok.javac.Javac.*;
|
||||
import lombok.javac.JavacTreeMaker.TypeTag;
|
||||
|
||||
import com.sun.source.tree.ClassTree;
|
||||
import com.sun.source.tree.LabeledStatementTree;
|
||||
import com.sun.source.tree.NewClassTree;
|
||||
import com.sun.source.tree.VariableTree;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCNewClass;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.tree.TreeCopier;
|
||||
import com.sun.tools.javac.util.List;
|
||||
@@ -91,6 +98,20 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
|
||||
@Override public JCTree visitVariable(VariableTree node, Void p) {
|
||||
JCVariableDecl copy = (JCVariableDecl) super.visitVariable(node, p);
|
||||
copy.sym = ((JCVariableDecl) node).sym;
|
||||
if (copy.sym != null) copy.type = ((JCVariableDecl) node).type;
|
||||
if (copy.type != null) {
|
||||
boolean wipeSymAndType = copy.type.isErroneous();
|
||||
if (!wipeSymAndType) {
|
||||
TypeTag typeTag = TypeTag.typeTag(copy.type);
|
||||
wipeSymAndType = (CTC_NONE.equals(typeTag) || CTC_ERROR.equals(typeTag) || CTC_UNKNOWN.equals(typeTag) || CTC_UNDETVAR.equals(typeTag));
|
||||
}
|
||||
|
||||
if (wipeSymAndType) {
|
||||
copy.sym = null;
|
||||
copy.type = null;
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@@ -99,4 +120,14 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
|
||||
@Override public JCTree visitLabeledStatement(LabeledStatementTree node, Void p) {
|
||||
return node.getStatement().accept(this, p);
|
||||
}
|
||||
|
||||
@Override public JCTree visitNewClass(NewClassTree node, Void p) {
|
||||
JCNewClass copy = (JCNewClass) super.visitNewClass(node, p);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override public JCTree visitClass(ClassTree node, Void p) {
|
||||
JCClassDecl copy = (JCClassDecl) super.visitClass(node, p);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user