mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 06:17:44 +00:00
[fixes #1554] javac9 now caches type lookups based on ‘position’ which is slapped together by a tuple based on the position (as gleaned from the JCTree object) and the source file (as gleaned from.. Log. *facepalm*). We didn’t update log when resolving for i.e. ‘val’, so the caches get all jumbled up. Fixed by setting the Log’s ‘useSource’ method.
This commit is contained in:
1 parent
14407cedb5
commit
369df91756
2 files changed
+21
-15
No files matched your search
@@ -31,6 +31,7 @@ import java.util.ArrayDeque;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import lombok.Lombok;
|
||||
import lombok.core.debug.AssertionLogger;
|
||||
@@ -59,6 +60,7 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Log;
|
||||
|
||||
public class JavacResolution {
|
||||
private final Attr attr;
|
||||
@@ -142,9 +144,14 @@ public class JavacResolution {
|
||||
|
||||
TreeMirrorMaker mirrorMaker = new TreeMirrorMaker(node.getTreeMaker(), node.getContext());
|
||||
JCTree copy = mirrorMaker.copy(finder.copyAt());
|
||||
|
||||
memberEnterAndAttribute(copy, finder.get(), node.getContext());
|
||||
return mirrorMaker.getOriginalToCopyMap();
|
||||
Log log = Log.instance(node.getContext());
|
||||
JavaFileObject oldFileObject = log.useSource(((JCCompilationUnit) node.top().get()).getSourceFile());
|
||||
try {
|
||||
memberEnterAndAttribute(copy, finder.get(), node.getContext());
|
||||
return mirrorMaker.getOriginalToCopyMap();
|
||||
} finally {
|
||||
log.useSource(oldFileObject);
|
||||
}
|
||||
} finally {
|
||||
messageSuppressor.enableLoggers();
|
||||
}
|
||||
|
||||
@@ -62,21 +62,21 @@ public class HandleVal extends JavacASTAdapter {
|
||||
JCTree typeTree = local.vartype;
|
||||
if (typeTree == null) return;
|
||||
String typeTreeToString = typeTree.toString();
|
||||
|
||||
|
||||
if (!(eq(typeTreeToString, "val") || eq(typeTreeToString, "var"))) return;
|
||||
boolean isVal = typeMatches(val.class, localNode, typeTree);
|
||||
boolean isVar = typeMatches(var.class, localNode, typeTree);
|
||||
if (!(isVal || isVar)) return;
|
||||
|
||||
|
||||
if (isVal) handleFlagUsage(localNode, ConfigurationKeys.VAL_FLAG_USAGE, "val");
|
||||
if (isVar) handleFlagUsage(localNode, ConfigurationKeys.VAR_FLAG_USAGE, "var");
|
||||
|
||||
|
||||
JCTree parentRaw = localNode.directUp().get();
|
||||
if (isVal && parentRaw instanceof JCForLoop) {
|
||||
localNode.addError("'val' is not allowed in old-style for loops");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
JCExpression rhsOfEnhancedForLoop = null;
|
||||
if (local.init == null) {
|
||||
if (parentRaw instanceof JCEnhancedForLoop) {
|
||||
@@ -84,26 +84,25 @@ public class HandleVal extends JavacASTAdapter {
|
||||
if (efl.var == local) rhsOfEnhancedForLoop = efl.expr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final String annotation = typeTreeToString;
|
||||
if (rhsOfEnhancedForLoop == null && local.init == null) {
|
||||
localNode.addError("'" + annotation + "' on a local variable requires an initializer expression");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (local.init instanceof JCNewArray && ((JCNewArray)local.init).elemtype == null) {
|
||||
localNode.addError("'" + annotation + "' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (localNode.shouldDeleteLombokAnnotations()) {
|
||||
JavacHandlerUtil.deleteImportFromCompilationUnit(localNode, val.class.getName());
|
||||
JavacHandlerUtil.deleteImportFromCompilationUnit(localNode, var.class.getName());
|
||||
}
|
||||
|
||||
|
||||
if (isVal) local.mods.flags |= Flags.FINAL;
|
||||
|
||||
|
||||
if (!localNode.shouldDeleteLombokAnnotations()) {
|
||||
JCAnnotation valAnnotation = recursiveSetGeneratedBy(localNode.getTreeMaker().Annotation(local.vartype, List.<JCExpression>nil()), typeTree, localNode.getContext());
|
||||
local.mods.annotations = local.mods.annotations == null ? List.of(valAnnotation) : local.mods.annotations.append(valAnnotation);
|
||||
@@ -126,7 +125,7 @@ public class HandleVal extends JavacASTAdapter {
|
||||
try {
|
||||
type = ((JCExpression) resolver.resolveMethodMember(localNode).get(local.init)).type;
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println("Exception while resolving: " + localNode);
|
||||
System.err.println("Exception while resolving: " + localNode + "(" + localNode.getFileName() + ")");
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
@@ -137,7 +136,7 @@ public class HandleVal extends JavacASTAdapter {
|
||||
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);
|
||||
System.err.println("Exception while resolving: " + localNode + "(" + localNode.getFileName() + ")");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user