From 089f2ec5f45567c8c12e9d13bf9be8fa5c107c18 Mon Sep 17 00:00:00 2001
From: Bulgakov Alexander <buls@yandex.ru>
Date: Fri, 24 May 2019 10:05:38 +0300
Subject: #1976. override error handling policy for problemReporter to
 guarantee AbortCompilation is throwing.

---
 src/eclipseAgent/lombok/eclipse/agent/PatchVal.java | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

(limited to 'src/eclipseAgent')

diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 832a25e3..3aa5d386 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -21,10 +21,13 @@
  */
 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.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;
@@ -45,9 +48,8 @@ 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;
 
@@ -358,6 +360,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) {
@@ -389,6 +395,8 @@ public class PatchVal {
 				}
 			}
 			throw e;
+		} finally {
+			referenceContext.problemReporter = oldProblemReporter;
 		}
 	}
 }
-- 
cgit 


From 67441a074f351da80b074c00e7981627b1918c9c Mon Sep 17 00:00:00 2001
From: Bulgakov Alexander <buls@yandex.ru>
Date: Fri, 24 May 2019 19:04:16 +0300
Subject: [val]. Sets false to ReferenceContexts'
 ignoreFurtherInvestigationField fields for generating bytecode correctly.
 Resolves the False part type of a conditional expression.

---
 .../lombok/eclipse/agent/PatchVal.java             | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)

(limited to 'src/eclipseAgent')

diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 3aa5d386..51994ced 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -26,17 +26,22 @@ 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;
@@ -53,6 +58,7 @@ 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;
@@ -390,6 +396,18 @@ 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;
 				}
@@ -399,4 +417,55 @@ public class PatchVal {
 			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);
+		}
+	}
 }
-- 
cgit