aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java
diff options
context:
space:
mode:
authorgrootjans <grootjans@gmail.com>2011-07-18 22:45:29 +0200
committergrootjans <grootjans@gmail.com>2011-07-18 22:45:48 +0200
commit931959c89addb8213594033ed43da734c426f3a4 (patch)
tree2c6033fbd78f5d4989653fe5014f45656f70f97e /src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java
parent43d938a895323e3bae807ea534de10a13b66ad24 (diff)
downloadlombok-931959c89addb8213594033ed43da734c426f3a4.tar.gz
lombok-931959c89addb8213594033ed43da734c426f3a4.tar.bz2
lombok-931959c89addb8213594033ed43da734c426f3a4.zip
Fixes issue 232, now we also patch dom.SingleVariableDecls. Fixes val import disappearing when organizing imports in Eclipse, when using val in a foreach.
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchValEclipsePortal.java24
1 files changed, 22 insertions, 2 deletions
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;
}
}