aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2021-10-21 10:38:37 +0200
committerRawi01 <Rawi01@users.noreply.github.com>2021-10-22 09:24:17 +0200
commit553b25addde4fab136258f7718e274a98bfbe34a (patch)
treef65f76f8c838a73f5f91f8efe0811c6b019857bb /src/eclipseAgent/lombok/eclipse
parent13d84b129e562fdc71b049778c3b3bd2376e29a4 (diff)
downloadlombok-553b25addde4fab136258f7718e274a98bfbe34a.tar.gz
lombok-553b25addde4fab136258f7718e274a98bfbe34a.tar.bz2
lombok-553b25addde4fab136258f7718e274a98bfbe34a.zip
[fixes #2985] Resolve var/val only once in eclipse
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java1
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java85
2 files changed, 42 insertions, 44 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 328860e3..33dad64e 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -764,6 +764,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
sm.addScript(ScriptBuilder.replaceMethodCall()
.target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG))
+ .target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG, "boolean"))
.methodToReplace(new Hook(EXPRESSION_SIG, "resolveType", TYPEBINDING_SIG, BLOCKSCOPE_SIG))
.requestExtra(StackRequest.THIS)
.replacementMethod(new Hook("lombok.launch.PatchFixesHider$Val", "skipResolveInitializerIfAlreadyCalled2", TYPEBINDING_SIG, EXPRESSION_SIG, BLOCKSCOPE_SIG, LOCALDECLARATION_SIG))
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 3e96e75d..e758979d 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -35,13 +35,11 @@ import org.eclipse.jdt.internal.compiler.ast.FunctionalExpression;
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
-import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
@@ -250,7 +248,6 @@ public class PatchVal {
}
TypeBinding resolved = null;
- Constant oldConstant = init.constant;
try {
resolved = decomponent ? getForEachComponentType(init, scope) : resolveForExpression(init, scope);
} catch (NullPointerException e) {
@@ -260,6 +257,46 @@ public class PatchVal {
// just go with 'Object' and let the IDE print the appropriate errors.
resolved = null;
}
+
+ if (resolved == null) {
+ if (init instanceof ConditionalExpression) {
+ ConditionalExpression cexp = (ConditionalExpression) init;
+ Expression ifTrue = cexp.valueIfTrue;
+ Expression ifFalse = cexp.valueIfFalse;
+ TypeBinding ifTrueResolvedType = ifTrue.resolvedType;
+ CompilationResult compilationResult = scope.referenceCompilationUnit().compilationResult;
+ CategorizedProblem[] problems = compilationResult.problems;
+ CategorizedProblem lastProblem = problems[compilationResult.problemCount - 1];
+ if (ifTrueResolvedType != null && ifFalse.resolvedType == null && lastProblem.getCategoryID() == CAT_TYPE) {
+ int problemCount = compilationResult.problemCount;
+ for (int i = 0; i < problemCount; ++i) {
+ if (problems[i] == lastProblem) {
+ problems[i] = null;
+ if (i + 1 < problemCount) {
+ System.arraycopy(problems, i + 1, problems, i, problemCount - i + 1);
+ }
+ break;
+ }
+ }
+ compilationResult.removeProblem(lastProblem);
+ if (!compilationResult.hasErrors()) {
+ clearIgnoreFurtherInvestigationField(scope.referenceContext());
+ setValue(getField(CompilationResult.class, "hasMandatoryErrors"), compilationResult, false);
+ }
+
+ if (ifFalse instanceof FunctionalExpression) {
+ FunctionalExpression functionalExpression = (FunctionalExpression) ifFalse;
+ functionalExpression.setExpectedType(ifTrueResolvedType);
+ }
+ if (ifFalse.resolvedType == null) {
+ resolveForExpression(ifFalse, scope);
+ }
+
+ resolved = ifTrueResolvedType;
+ }
+ }
+ }
+
if (resolved != null) {
try {
replacement = makeType(resolved, local.type, false);
@@ -267,10 +304,6 @@ public class PatchVal {
} catch (Exception e) {
// Some type thing failed.
}
- } else {
- if (init instanceof MessageSend && ((MessageSend) init).actualReceiverType == null) {
- init.constant = oldConstant;
- }
}
}
@@ -370,43 +403,7 @@ public class PatchVal {
// Known cause of issues; for example: val e = mth("X"), where mth takes 2 arguments.
return null;
} catch (AbortCompilation e) {
- if (collection instanceof ConditionalExpression) {
- ConditionalExpression cexp = (ConditionalExpression) collection;
- Expression ifTrue = cexp.valueIfTrue;
- Expression ifFalse = cexp.valueIfFalse;
- TypeBinding ifTrueResolvedType = ifTrue.resolvedType;
- CategorizedProblem problem = e.problem;
- if (ifTrueResolvedType != null && ifFalse.resolvedType == null && problem.getCategoryID() == CAT_TYPE) {
- CompilationResult compilationResult = e.compilationResult;
- CategorizedProblem[] problems = compilationResult.problems;
- int problemCount = compilationResult.problemCount;
- for (int i = 0; i < problemCount; ++i) {
- if (problems[i] == problem) {
- problems[i] = null;
- if (i + 1 < problemCount) {
- System.arraycopy(problems, i + 1, problems, i, problemCount - i + 1);
- }
- break;
- }
- }
- compilationResult.removeProblem(problem);
- if (!compilationResult.hasErrors()) {
- clearIgnoreFurtherInvestigationField(scope.referenceContext());
- setValue(getField(CompilationResult.class, "hasMandatoryErrors"), compilationResult, false);
- }
-
- if (ifFalse instanceof FunctionalExpression) {
- FunctionalExpression functionalExpression = (FunctionalExpression) ifFalse;
- functionalExpression.setExpectedType(ifTrueResolvedType);
- }
- if (ifFalse.resolvedType == null) {
- ifFalse.resolve(scope);
- }
-
- return ifTrueResolvedType;
- }
- }
- throw e;
+ return null;
}
}