mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 12:19:00 +00:00
Merge pull request #2138 from bulgakovalexander/feature/typeInferenceImprovements
val. override error handling policy for problemReporter to guarantee AbortCompilation is throwing.
This commit is contained in:
8 files changed
+137
-8
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,26 @@
|
||||
class ValInLambda {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final int i = 1;
|
||||
final java.lang.Runnable foo = (System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println;
|
||||
};
|
||||
|
||||
|
||||
public void easyLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final int i = 1;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void easyIntersectionLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final int i = 1;
|
||||
};
|
||||
}
|
||||
|
||||
public void easyLubLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final java.lang.Runnable fooInner = (System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,27 @@
|
||||
// version 8:
|
||||
class ValLambda {
|
||||
static {
|
||||
final java.lang.Runnable foo = (System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println;
|
||||
}
|
||||
|
||||
{
|
||||
final java.lang.Runnable foo = (System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println;
|
||||
}
|
||||
|
||||
public void easyLambda() {
|
||||
final java.lang.Runnable foo = (Runnable) () -> {
|
||||
};
|
||||
}
|
||||
|
||||
public void easyIntersectionLambda() {
|
||||
final java.lang.Runnable foo = (Runnable & java.io.Serializable) () -> {
|
||||
};
|
||||
final java.io.Serializable bar = (java.io.Serializable & Runnable) () -> {
|
||||
};
|
||||
}
|
||||
|
||||
public void easyLubLambda() {
|
||||
final java.lang.Runnable foo = (System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// version 8:
|
||||
|
||||
import lombok.val;
|
||||
class ValInLambda {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final @val int i = 1;
|
||||
final @lombok.val java.lang.Runnable foo = ((System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println);
|
||||
};
|
||||
ValInLambda() {
|
||||
super();
|
||||
@@ -16,6 +16,12 @@ class ValInLambda {
|
||||
public void easyIntersectionLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final @val int i = 1;
|
||||
};
|
||||
}
|
||||
public void easyLubLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final @lombok.val java.lang.Runnable fooInner = ((System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
class ValLambda {
|
||||
static {
|
||||
final @lombok.val java.lang.Runnable foo = ((System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println);
|
||||
}
|
||||
{
|
||||
final @lombok.val java.lang.Runnable foo = ((System.currentTimeMillis() > 0) ? (Runnable) () -> {
|
||||
} : System.out::println);
|
||||
}
|
||||
<clinit>() {
|
||||
}
|
||||
ValLambda() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.val;
|
||||
class ValInLambda {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
val i = 1;
|
||||
lombok.val foo = (System.currentTimeMillis() > 0) ? (Runnable)()-> {} : System.out::println;
|
||||
};
|
||||
|
||||
public void easyLambda() {
|
||||
@@ -18,4 +19,10 @@ class ValInLambda {
|
||||
val i = 1;
|
||||
};
|
||||
}
|
||||
|
||||
public void easyLubLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
lombok.val fooInner = (System.currentTimeMillis() > 0) ? (Runnable)()-> {} : System.out::println;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
// version 8:
|
||||
class ValLambda {
|
||||
|
||||
static {
|
||||
lombok.val foo = (System.currentTimeMillis() > 0) ? (Runnable)()-> {} : System.out::println;
|
||||
}
|
||||
{
|
||||
lombok.val foo = (System.currentTimeMillis() > 0) ? (Runnable)()-> {} : System.out::println;
|
||||
}
|
||||
|
||||
public void easyLambda() {
|
||||
lombok.val foo = (Runnable)()-> {};
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
14 Function is a raw type. References to generic type Function<T,R> should be parameterized
|
||||
15 Function is a raw type. References to generic type Function<T,R> should be parameterized
|
||||
23 Function is a raw type. References to generic type Function<T,R> should be parameterized
|
||||
24 Function is a raw type. References to generic type Function<T,R> should be parameterized
|
||||
Reference in new issue
Block a user