aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent
diff options
context:
space:
mode:
authorMichael Ernst <mernst@cs.washington.edu>2021-12-07 11:16:11 -0800
committerMichael Ernst <mernst@cs.washington.edu>2021-12-07 11:16:11 -0800
commit3f5e4a2819d2f03d634a06861ff5487af320b719 (patch)
treeba9ab7ba2f582bb179624e2bb3f717bea5d9a421 /src/eclipseAgent
parent0b4cc60c2367845ebc362e4b254f9e96a66d53c3 (diff)
parentd3b763f9dab4a46e88ff10bc2132fb6f12fda639 (diff)
downloadlombok-3f5e4a2819d2f03d634a06861ff5487af320b719.tar.gz
lombok-3f5e4a2819d2f03d634a06861ff5487af320b719.tar.bz2
lombok-3f5e4a2819d2f03d634a06861ff5487af320b719.zip
Merge ../lombok-branch-master into nullness-annotations
Diffstat (limited to 'src/eclipseAgent')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java101
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchJavadoc.java16
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java106
-rwxr-xr-xsrc/eclipseAgent/lombok/launch/PatchFixesHider.java53
4 files changed, 200 insertions, 76 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 0a11cd7a..06e10960 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -87,14 +87,14 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
patchHideGeneratedNodes(sm);
patchPostCompileHookEclipse(sm);
patchFixSourceTypeConverter(sm);
- patchDisableLombokForCodeCleanup(sm);
patchListRewriteHandleGeneratedMethods(sm);
patchSyntaxAndOccurrencesHighlighting(sm);
patchSortMembersOperation(sm);
- patchExtractInterface(sm);
+ patchExtractInterfaceAndPullUp(sm);
patchAboutDialog(sm);
patchEclipseDebugPatches(sm);
patchJavadoc(sm);
+ patchASTConverterLiterals(sm);
patchPostCompileHookEcj(sm);
@@ -134,7 +134,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.transplant().build());
}
- private static void patchExtractInterface(ScriptManager sm) {
+ private static void patchExtractInterfaceAndPullUp(ScriptManager sm) {
/* Fix sourceEnding for generated nodes to avoid null pointer */
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.SourceElementNotifier", "notifySourceElementRequestor", "void", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.ImportReference"))
@@ -156,10 +156,31 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.requestExtra(StackRequest.THIS, StackRequest.PARAM4)
.transplant().build());
- /* get real generated node in stead of a random one generated by the annotation */
+ /* Get real node source instead of the annotation */
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.HierarchyProcessor", "createPlaceholderForSingleVariableDeclaration", "org.eclipse.jdt.core.dom.SingleVariableDeclaration",
+ "org.eclipse.jdt.core.dom.SingleVariableDeclaration",
+ "org.eclipse.jdt.core.ICompilationUnit",
+ "org.eclipse.jdt.core.dom.rewrite.ASTRewrite"
+ ))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.HierarchyProcessor", "createPlaceholderForType", "org.eclipse.jdt.core.dom.Type",
+ "org.eclipse.jdt.core.dom.Type",
+ "org.eclipse.jdt.core.ICompilationUnit",
+ "org.eclipse.jdt.core.dom.rewrite.ASTRewrite"
+ ))
+ .methodToWrap(new Hook("org.eclipse.jdt.core.IBuffer", "getText", "java.lang.String", "int", "int"))
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealNodeSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.dom.ASTNode"))
+ .requestExtra(StackRequest.PARAM1)
+ .transplant()
+ .build());
+
+ /* Get real generated node instead of a random one generated by the annotation */
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.replaceMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMemberDeclarations"))
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodComments"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor", "createAbstractMethod"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor", "addMethodStubForAbstractMethod"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor", "createChangeManager"))
.methodToReplace(new Hook("org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil", "getMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit"))
.replacementMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit"))
.transplant().build());
@@ -177,6 +198,29 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
.request(StackRequest.PARAM2)
.transplant().build());
+
+ /* Do not add a modifier to the generating annotation during pull up
+ *
+ * Example: Pull up a protected method (canEqual()/@EqualsAndHashCode)
+ */
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor$IncomingMemberVisibilityAdjustment", "rewriteVisibility"))
+ .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "skipRewriteVisibility", "boolean", "org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor$IncomingMemberVisibilityAdjustment"))
+ .request(StackRequest.THIS)
+ .transplant()
+ .build());
+
+ /*
+ * ImportRemover sometimes removes lombok imports if a generated method/type gets changed. Skipping all generated nodes fixes this behavior.
+ *
+ * Example: Create a class (Use.java) that uses a generated method (Test t; t.toString();) and pull up this generated method.
+ */
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ImportRemover", "registerRemovedNode", "void", "org.eclipse.jdt.core.dom.ASTNode"))
+ .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
+ .request(StackRequest.PARAM1)
+ .transplant()
+ .build());
}
private static void patchAboutDialog(ScriptManager sm) {
@@ -200,20 +244,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addUsage"))
.target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addWrite"))
.target(new MethodTarget("org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector", "visitLiteral", "boolean", "org.eclipse.jdt.core.dom.Expression"))
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
.valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnFalse", "boolean", "java.lang.Object"))
.request(StackRequest.PARAM1)
.build());
}
- private static void patchDisableLombokForCodeCleanup(ScriptManager sm) {
- sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
- .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
- .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isRefactoringVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
- .request(StackRequest.THIS, StackRequest.PARAM1)
- .build());
- }
-
private static void patchListRewriteHandleGeneratedMethods(ScriptManager sm) {
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.replaceMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter", "rewriteList"))
@@ -308,6 +345,12 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
"org.eclipse.jdt.core.dom.SimpleName[]"))
.request(StackRequest.RETURN_VALUE).build());
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
+ .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isBlockedVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
+ .request(StackRequest.THIS, StackRequest.PARAM1)
+ .build());
+
patchRefactorScripts(sm);
patchFormatters(sm);
}
@@ -528,6 +571,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
"org.eclipse.jdt.core.dom.Name", "java.lang.Object"))
.transplant().build());
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.ASTNode", "boolean", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration"))
+ .methodToWrap(new Hook("org.eclipse.jdt.core.dom.Block", "<init>", "void", "org.eclipse.jdt.core.dom.AST"))
+ .requestExtra(StackRequest.PARAM2)
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlag", "void",
+ "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
+ .transplant().build());
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convertType", "org.eclipse.jdt.core.dom.Type", "org.eclipse.jdt.internal.compiler.ast.TypeReference"))
@@ -766,6 +816,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))
@@ -895,6 +946,14 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.requestExtra(StackRequest.PARAM1)
.build());
+ /* This is a copy for the language server implementation that also supports markdown */
+ sm.addScript(ScriptBuilder.wrapMethodCall()
+ .target(new MethodTarget("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2", "getHTMLContent", "java.lang.String", "org.eclipse.jdt.core.IJavaElement", "boolean"))
+ .methodToWrap(new Hook("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2", "getHTMLContentFromSource", "java.lang.String", "org.eclipse.jdt.core.IJavaElement"))
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$Javadoc", "getHTMLContentFromSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.IJavaElement"))
+ .requestExtra(StackRequest.PARAM1)
+ .build());
+
/* This is an older version that uses IMember instead of IJavaElement */
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2", "getHTMLContent", "java.lang.String", "org.eclipse.jdt.core.IMember", "boolean"))
@@ -919,4 +978,22 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.build());
}
+ private static void patchASTConverterLiterals(ScriptManager sm) {
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.Expression", "org.eclipse.jdt.internal.compiler.ast.StringLiteral"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.Expression", "org.eclipse.jdt.internal.compiler.ast.TextBlock"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.CharacterLiteral", "org.eclipse.jdt.internal.compiler.ast.CharLiteral"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.DoubleLiteral"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.FloatLiteral"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.LongLiteral"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.IntLiteral"))
+ .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue"))
+ .methodToWrap(new Hook("java.lang.String", "<init>", "void", "char[]", "int", "int"))
+ .requestExtra(StackRequest.PARAM1)
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealNodeSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
+ .transplant()
+ .build());
+ }
+
}
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchJavadoc.java b/src/eclipseAgent/lombok/eclipse/agent/PatchJavadoc.java
index 5b34917e..673c30fd 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchJavadoc.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchJavadoc.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 The Project Lombok Authors.
+ * Copyright (C) 2020-2021 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -103,8 +103,9 @@ public class PatchJavadoc {
private static class Reflection {
private static final Method javadoc2HTML;
private static final Method oldJavadoc2HTML;
+ private static final Method lsJavadoc2HTML;
static {
- Method a = null, b = null;
+ Method a = null, b = null, c = null;
try {
a = Permit.getMethod(JavadocContentAccess2.class, "javadoc2HTML", IMember.class, IJavaElement.class, String.class);
@@ -112,9 +113,13 @@ public class PatchJavadoc {
try {
b = Permit.getMethod(JavadocContentAccess2.class, "javadoc2HTML", IMember.class, String.class);
} catch (Throwable t) {}
+ try {
+ c = Permit.getMethod(Class.forName("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2"), "javadoc2HTML", IMember.class, IJavaElement.class, String.class);
+ } catch (Throwable t) {}
javadoc2HTML = a;
oldJavadoc2HTML = b;
+ lsJavadoc2HTML = c;
}
private static String javadoc2HTML(IMember member, IJavaElement element, String rawJavadoc) {
@@ -125,6 +130,13 @@ public class PatchJavadoc {
return null;
}
}
+ if (lsJavadoc2HTML != null) {
+ try {
+ return (String) lsJavadoc2HTML.invoke(null, member, element, rawJavadoc);
+ } catch (Throwable t) {
+ return null;
+ }
+ }
if (oldJavadoc2HTML != null) {
try {
return (String) oldJavadoc2HTML.invoke(null, member, rawJavadoc);
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 774e5b40..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;
@@ -59,8 +57,8 @@ import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
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 lombok.eclipse.Eclipse.*;
+import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import static org.eclipse.jdt.core.compiler.CategorizedProblem.CAT_TYPE;
public class PatchVal {
@@ -237,13 +235,19 @@ public class PatchVal {
TypeReference replacement = null;
+ // Java 10+: Lombok uses the native 'var' support and transforms 'val' to 'final var'.
+ if (hasNativeVarSupport(scope) && val) {
+ replacement = new SingleTypeReference("var".toCharArray(), pos(local.type));
+ local.initialization = init;
+ init = null;
+ }
+
if (init != null) {
if (init.getClass().getName().equals("org.eclipse.jdt.internal.compiler.ast.LambdaExpression")) {
return false;
}
TypeBinding resolved = null;
- Constant oldConstant = init.constant;
try {
resolved = decomponent ? getForEachComponentType(init, scope) : resolveForExpression(init, scope);
} catch (NullPointerException e) {
@@ -253,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);
@@ -260,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;
- }
}
}
@@ -281,6 +321,14 @@ public class PatchVal {
return is(local.type, scope, "lombok.val");
}
+ private static boolean hasNativeVarSupport(Scope scope) {
+ long sl = scope.problemReporter().options.sourceLevel >> 16;
+ long cl = scope.problemReporter().options.complianceLevel >> 16;
+ if (sl == 0) sl = cl;
+ if (cl == 0) cl = sl;
+ return Math.min((int)(sl - 44), (int)(cl - 44)) >= 10;
+ }
+
public static boolean handleValForForEach(ForeachStatement forEach, BlockScope scope) {
if (forEach.elementVariable == null) return false;
@@ -288,6 +336,8 @@ public class PatchVal {
boolean var = isVar(forEach.elementVariable, scope);
if (!(val || var)) return false;
+ if (hasNativeVarSupport(scope)) return false;
+
TypeBinding component = getForEachComponentType(forEach.collection, scope);
if (component == null) return false;
TypeReference replacement = makeType(component, forEach.elementVariable.type, false);
@@ -353,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;
}
}
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index bee30922..63bb3747 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -57,6 +57,7 @@ import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent;
import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner;
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup;
import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;
+import org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment;
import static lombok.eclipse.EcjAugments.ASTNode_generatedBy;
@@ -413,25 +414,27 @@ final class PatchFixesHider {
}
return result;
}
-
- public static boolean isRefactoringVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
- if (visitor == null) return false;
-
- String className = visitor.getClass().getName();
- if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix"))) return false;
-
+
+ public static boolean isGenerated(org.eclipse.jdt.core.IMember member) {
boolean result = false;
try {
- result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
- if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) {
- result = isGenerated(node.getParent());
- }
- } catch (Exception e) {
+ result = member.getNameRange().getLength() <= 0 || member.getNameRange().equals(member.getSourceRange());
+ } catch (JavaModelException e) {
// better to assume it isn't generated
}
return result;
}
+ public static boolean isBlockedVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
+ if (visitor == null) return false;
+
+ String className = visitor.getClass().getName();
+ if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix") || className.startsWith("org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokensVisitor"))) return false;
+ if (className.equals("org.eclipse.jdt.internal.corext.fix.VariableDeclarationFixCore$WrittenNamesFinder")) return false;
+
+ return isGenerated(node);
+ }
+
public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) {
return isGenerated(rewrite.getParent());
}
@@ -473,8 +476,10 @@ final class PatchFixesHider {
StringBuilder signature = new StringBuilder();
addAnnotations(annotations, signature);
- if ((Boolean)processor.getClass().getDeclaredField("fPublic").get(processor)) signature.append("public ");
- if ((Boolean)processor.getClass().getDeclaredField("fAbstract").get(processor)) signature.append("abstract ");
+ try {
+ if ((Boolean)processor.getClass().getDeclaredField("fPublic").get(processor)) signature.append("public ");
+ if ((Boolean)processor.getClass().getDeclaredField("fAbstract").get(processor)) signature.append("abstract ");
+ } catch (Throwable t) { }
signature
.append(declaration.getReturnType2().toString())
@@ -520,7 +525,7 @@ final class PatchFixesHider {
for (Object value : normalAnn.values()) values.add(value.toString());
}
- signature.append("@").append(annotation.resolveTypeBinding().getQualifiedName());
+ signature.append("@").append(annotation.getTypeName().getFullyQualifiedName());
if (!values.isEmpty()) {
signature.append("(");
boolean first = true;
@@ -696,7 +701,7 @@ final class PatchFixesHider {
public static IMethod[] removeGeneratedMethods(IMethod[] methods) throws Exception {
List<IMethod> result = new ArrayList<IMethod>();
for (IMethod m : methods) {
- if (m.getNameRange().getLength() > 0 && !m.getNameRange().equals(m.getSourceRange())) result.add(m);
+ if (!isGenerated(m)) result.add(m);
}
return result.size() == methods.length ? methods : result.toArray(new IMethod[0]);
}
@@ -799,5 +804,21 @@ final class PatchFixesHider {
return replace;
}
+
+ public static String getRealNodeSource(String original, org.eclipse.jdt.internal.compiler.ast.ASTNode node) {
+ if (!isGenerated(node)) return original;
+
+ return node.toString();
+ }
+
+ public static java.lang.String getRealNodeSource(java.lang.String original, org.eclipse.jdt.core.dom.ASTNode node) throws Exception {
+ if (!isGenerated(node)) return original;
+
+ return node.toString();
+ }
+
+ public static boolean skipRewriteVisibility(IncomingMemberVisibilityAdjustment adjustment) {
+ return isGenerated(adjustment.getMember());
+ }
}
}