aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse
diff options
context:
space:
mode:
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java7
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java17
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java24
3 files changed, 42 insertions, 6 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 257137ae..f67bd4e3 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -328,6 +328,7 @@ public class EclipsePatcher extends Agent {
final String LOCALDECLARATION_SIG = "org.eclipse.jdt.internal.compiler.ast.LocalDeclaration";
final String PARSER_SIG = "org.eclipse.jdt.internal.compiler.parser.Parser";
final String VARIABLEDECLARATIONSTATEMENT_SIG = "org.eclipse.jdt.core.dom.VariableDeclarationStatement";
+ final String SINGLEVARIABLEDECLARATION_SIG = "org.eclipse.jdt.core.dom.SingleVariableDeclaration";
final String ASTCONVERTER_SIG = "org.eclipse.jdt.core.dom.ASTConverter";
sm.addScript(ScriptBuilder.addField()
@@ -363,6 +364,12 @@ public class EclipsePatcher extends Agent {
.wrapMethod(new Hook("lombok.eclipse.agent.PatchValEclipsePortal", "addFinalAndValAnnotationToVariableDeclarationStatement",
"void", "java.lang.Object", "java.lang.Object", "java.lang.Object"))
.request(StackRequest.THIS, StackRequest.PARAM1, StackRequest.PARAM2).build());
+
+ sm.addScript(ScriptBuilder.wrapReturnValue()
+ .target(new MethodTarget(ASTCONVERTER_SIG, "setModifiers", "void", SINGLEVARIABLEDECLARATION_SIG, LOCALDECLARATION_SIG))
+ .wrapMethod(new Hook("lombok.eclipse.agent.PatchValEclipsePortal", "addFinalAndValAnnotationToSingleVariableDeclaration",
+ "void", "java.lang.Object", "java.lang.Object", "java.lang.Object"))
+ .request(StackRequest.THIS, StackRequest.PARAM1, StackRequest.PARAM2).build());
}
private static void addPatchesForVal(ScriptManager sm) {
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java
index 3fb407b9..ac3b58a0 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java
@@ -35,6 +35,7 @@ import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.IExtendedModifier;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
@@ -101,7 +102,17 @@ public class PatchValEclipse {
}
}
+ public static void addFinalAndValAnnotationToSingleVariableDeclaration(Object converter, SingleVariableDeclaration out, LocalDeclaration in) {
+ @SuppressWarnings("unchecked") List<IExtendedModifier> modifiers = out.modifiers();
+ addFinalAndValAnnotationToModifierList(converter, modifiers, out.getAST(), in);
+ }
+
public static void addFinalAndValAnnotationToVariableDeclarationStatement(Object converter, VariableDeclarationStatement out, LocalDeclaration in) {
+ @SuppressWarnings("unchecked") List<IExtendedModifier> modifiers = out.modifiers();
+ addFinalAndValAnnotationToModifierList(converter, modifiers, out.getAST(), in);
+ }
+
+ public static void addFinalAndValAnnotationToModifierList(Object converter, List<IExtendedModifier> modifiers, AST ast, LocalDeclaration in) {
// First check that 'in' has the final flag on, and a @val / @lombok.val annotation.
if ((in.modifiers & ClassFileConstants.AccFinal) == 0) return;
if (in.annotations == null) return;
@@ -130,8 +141,6 @@ public class PatchValEclipse {
// Now check that 'out' is missing either of these.
- @SuppressWarnings("unchecked") List<IExtendedModifier> modifiers = out.modifiers();
-
if (modifiers == null) return; // This is null only if the project is 1.4 or less. Lombok doesn't work in that.
boolean finalIsPresent = false;
boolean valIsPresent = false;
@@ -156,11 +165,11 @@ public class PatchValEclipse {
if (!finalIsPresent) {
modifiers.add(
- createModifier(out.getAST(), ModifierKeyword.FINAL_KEYWORD, valAnnotation.sourceStart, valAnnotation.sourceEnd));
+ createModifier(ast, ModifierKeyword.FINAL_KEYWORD, valAnnotation.sourceStart, valAnnotation.sourceEnd));
}
if (!valIsPresent) {
- MarkerAnnotation newAnnotation = createValAnnotation(out.getAST(), valAnnotation, valAnnotation.sourceStart, valAnnotation.sourceEnd);
+ MarkerAnnotation newAnnotation = createValAnnotation(ast, valAnnotation, valAnnotation.sourceStart, valAnnotation.sourceEnd);
try {
Reflection.astConverterRecordNodes.invoke(converter, newAnnotation, valAnnotation);
Reflection.astConverterRecordNodes.invoke(converter, newAnnotation.getTypeName(), valAnnotation.type);
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java
index cca1d4d0..8c308912 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java
@@ -30,6 +30,7 @@ public class PatchValEclipsePortal {
static final String LOCALDECLARATION_SIG = "org.eclipse.jdt.internal.compiler.ast.LocalDeclaration";
static final String PARSER_SIG = "org.eclipse.jdt.internal.compiler.parser.Parser";
static final String VARIABLEDECLARATIONSTATEMENT_SIG = "org.eclipse.jdt.core.dom.VariableDeclarationStatement";
+ static final String SINGLEVARIABLEDECLARATION_SIG = "org.eclipse.jdt.core.dom.SingleVariableDeclaration";
static final String ASTCONVERTER_SIG = "org.eclipse.jdt.core.dom.ASTConverter";
public static void copyInitializationOfForEachIterable(Object parser) {
@@ -72,13 +73,27 @@ public class PatchValEclipsePortal {
}
}
+ public static void addFinalAndValAnnotationToSingleVariableDeclaration(Object converter, Object out, Object in) {
+ try {
+ Reflection.addFinalAndValAnnotationToSingleVariableDeclaration.invoke(null, converter, out, in);
+ } catch (NoClassDefFoundError e) {
+ //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly
+ //do anything useful here.
+ } catch (IllegalAccessException e) {
+ Lombok.sneakyThrow(e);
+ } catch (InvocationTargetException e) {
+ Lombok.sneakyThrow(e);
+ }
+ }
+
private static final class Reflection {
public static final Method copyInitializationOfForEachIterable;
public static final Method copyInitializationOfLocalDeclaration;
- public static final Method addFinalAndValAnnotationToVariableDeclarationStatement;
+ public static final Method addFinalAndValAnnotationToVariableDeclarationStatement;
+ public static final Method addFinalAndValAnnotationToSingleVariableDeclaration;
static {
- Method m = null, n = null, o = null;
+ Method m = null, n = null, o = null, p = null;
try {
m = PatchValEclipse.class.getMethod("copyInitializationOfForEachIterable", Class.forName(PARSER_SIG));
n = PatchValEclipse.class.getMethod("copyInitializationOfLocalDeclaration", Class.forName(PARSER_SIG));
@@ -86,6 +101,10 @@ public class PatchValEclipsePortal {
Object.class,
Class.forName(VARIABLEDECLARATIONSTATEMENT_SIG),
Class.forName(LOCALDECLARATION_SIG));
+ p = PatchValEclipse.class.getMethod("addFinalAndValAnnotationToSingleVariableDeclaration",
+ Object.class,
+ Class.forName(SINGLEVARIABLEDECLARATION_SIG),
+ Class.forName(LOCALDECLARATION_SIG));
} catch (Exception e) {
// That's problematic, but as long as no local classes are used we don't actually need it.
// Better fail on local classes than crash altogether.
@@ -93,6 +112,7 @@ public class PatchValEclipsePortal {
copyInitializationOfForEachIterable = m;
copyInitializationOfLocalDeclaration = n;
addFinalAndValAnnotationToVariableDeclarationStatement = o;
+ addFinalAndValAnnotationToSingleVariableDeclaration = p;
}
}