aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-01-02 11:57:54 -0300
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-01-02 11:57:54 -0300
commit1d83020a0c9f68b4175044cb937dc13b27ec0986 (patch)
tree67e8e7859262465945c31c5f1bebd0b4c7cf0e13 /src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
parent6da38688de8eafb7b53ca8be0add444ddc116b46 (diff)
downloadlombok-1d83020a0c9f68b4175044cb937dc13b27ec0986.tar.gz
lombok-1d83020a0c9f68b4175044cb937dc13b27ec0986.tar.bz2
lombok-1d83020a0c9f68b4175044cb937dc13b27ec0986.zip
Should fix issue #175, where annotations mysteriously appear to be copied to the methods generated by them.
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
index 2c002bb6..b624caff 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
@@ -32,8 +32,12 @@ import java.util.List;
import lombok.core.DiagnosticsReceiver;
import lombok.core.PostCompiler;
+import org.eclipse.jdt.core.IAnnotatable;
+import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.internal.compiler.ast.Annotation;
public class PatchFixes {
public static int fixRetrieveStartingCatchPosition(int original, int start) {
@@ -134,4 +138,45 @@ public class PatchFixes {
String fileName = path + "/" + name;
return new BufferedOutputStream(PostCompiler.wrapOutputStream(out, fileName, DiagnosticsReceiver.CONSOLE));
}
+
+ public static Annotation[] convertAnnotations(Annotation[] out, IAnnotatable annotatable) {
+ IAnnotation[] in;
+
+ try {
+ in = annotatable.getAnnotations();
+ } catch (JavaModelException e) {
+ return out;
+ }
+
+ if (out == null) return null;
+ int toWrite = 0;
+
+ for (int idx = 0; idx < out.length; idx++) {
+ String oName = new String(out[idx].type.getLastToken());
+ boolean found = false;
+ for (IAnnotation i : in) {
+ String name = i.getElementName();
+ int li = name.lastIndexOf('.');
+ if (li > -1) name = name.substring(li + 1);
+ if (name.equals(oName)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) out[idx] = null;
+ else toWrite++;
+ }
+
+ Annotation[] replace = out;
+ if (toWrite < out.length) {
+ replace = new Annotation[toWrite];
+ int idx = 0;
+ for (int i = 0; i < out.length; i++) {
+ if (out[i] == null) continue;
+ replace[idx++] = out[i];
+ }
+ }
+
+ return replace;
+ }
}