aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-07-09 00:20:43 +0200
committerGitHub <noreply@github.com>2019-07-09 00:20:43 +0200
commit8b805fadf74499c7bbf1724cfe6fea9d485d4b87 (patch)
tree7f3d93fe1f6f346103e84441c2200237b9ad5d01 /src/eclipseAgent/lombok
parentc1039553b088dc45d272b942d930414d3224b06c (diff)
parenta899ffcbca7d7d9e3d616659d12a843fe02da6f6 (diff)
downloadlombok-8b805fadf74499c7bbf1724cfe6fea9d485d4b87.tar.gz
lombok-8b805fadf74499c7bbf1724cfe6fea9d485d4b87.tar.bz2
lombok-8b805fadf74499c7bbf1724cfe6fea9d485d4b87.zip
Merge pull request #2138 from bulgakovalexander/feature/typeInferenceImprovements
val. override error handling policy for problemReporter to guarantee AbortCompilation is throwing.
Diffstat (limited to 'src/eclipseAgent/lombok')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java81
1 files changed, 79 insertions, 2 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index c0c2cea6..0c66bb31 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -21,19 +21,27 @@
*/
package lombok.eclipse.agent;
+import lombok.permit.Permit;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
+import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
+import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
+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.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.ReferenceContext;
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
@@ -45,12 +53,12 @@ import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
-
-import lombok.permit.Permit;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
+import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
import java.lang.reflect.Field;
+import static lombok.Lombok.sneakyThrow;
import static lombok.eclipse.Eclipse.poss;
import static lombok.eclipse.handlers.EclipseHandlerUtil.makeType;
import static org.eclipse.jdt.core.compiler.CategorizedProblem.CAT_TYPE;
@@ -358,6 +366,10 @@ public class PatchVal {
}
private static TypeBinding resolveForExpression(Expression collection, BlockScope scope) {
+ CompilationUnitDeclaration referenceContext = scope.compilationUnitScope().referenceContext;
+ ProblemReporter oldProblemReporter = referenceContext.problemReporter;
+ referenceContext.problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.exitOnFirstError(),
+ oldProblemReporter.options, oldProblemReporter.problemFactory);
try {
return collection.resolveType(scope);
} catch (ArrayIndexOutOfBoundsException e) {
@@ -384,11 +396,76 @@ public class PatchVal {
}
}
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;
+ } finally {
+ referenceContext.problemReporter = oldProblemReporter;
+ }
+ }
+
+ private static void clearIgnoreFurtherInvestigationField(ReferenceContext currentContext) {
+ if (currentContext instanceof AbstractMethodDeclaration) {
+ AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) currentContext;
+ methodDeclaration.ignoreFurtherInvestigation = false;
+ } else if (currentContext instanceof LambdaExpression) {
+ LambdaExpression lambdaExpression = (LambdaExpression) currentContext;
+ setValue(getField(LambdaExpression.class, "ignoreFurtherInvestigation"), lambdaExpression, false);
+
+ Scope parent = lambdaExpression.enclosingScope.parent;
+ while (parent != null) {
+ switch(parent.kind) {
+ case Scope.CLASS_SCOPE:
+ case Scope.METHOD_SCOPE:
+ ReferenceContext parentAST = parent.referenceContext();
+ if (parentAST != lambdaExpression) {
+ clearIgnoreFurtherInvestigationField(parentAST);
+ return;
+ }
+ default:
+ parent = parent.parent;
+ break;
+ }
+ }
+
+ } else if (currentContext instanceof TypeDeclaration) {
+ TypeDeclaration typeDeclaration = (TypeDeclaration) currentContext;
+ typeDeclaration.ignoreFurtherInvestigation = false;
+ } else if (currentContext instanceof CompilationUnitDeclaration) {
+ CompilationUnitDeclaration typeDeclaration = (CompilationUnitDeclaration) currentContext;
+ typeDeclaration.ignoreFurtherInvestigation = false;
+ } else {
+ throw new UnsupportedOperationException("clearIgnoreFurtherInvestigationField for " + currentContext.getClass());
+ }
+ }
+
+ private static void setValue(Field field, Object object, Object value) {
+ try {
+ field.set(object, value);
+ } catch (IllegalAccessException e) {
+ throw sneakyThrow(e);
+ }
+ }
+
+ private static Field getField(Class clazz, String name) {
+ try {
+ return Permit.getField(clazz, name);
+ } catch (NoSuchFieldException e) {
+ throw sneakyThrow(e);
}
}
}