mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 06:16:14 +00:00
Should fix issue #175, where annotations mysteriously appear to be copied to the methods generated by them.
This commit is contained in:
1 parent
6da38688de
commit
1d83020a0c
2 files changed
+57
No files matched your search
@@ -67,6 +67,7 @@ public class EclipsePatcher extends Agent {
|
||||
patchHideGeneratedNodes(sm);
|
||||
patchLiveDebug(sm);
|
||||
patchPostCompileHookEclipse(sm);
|
||||
patchFixSourceTypeConverter(sm);
|
||||
} else {
|
||||
patchPostCompileHookEcj(sm);
|
||||
}
|
||||
@@ -276,4 +277,15 @@ public class EclipsePatcher extends Agent {
|
||||
PatchDelegate.addPatches(sm, ecj);
|
||||
PatchVal.addPatches(sm, ecj);
|
||||
}
|
||||
|
||||
private static void patchFixSourceTypeConverter(ScriptManager sm) {
|
||||
final String SOURCE_TYPE_CONVERTER_SIG = "org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter";
|
||||
final String I_ANNOTATABLE_SIG = "org.eclipse.jdt.core.IAnnotatable";
|
||||
final String ANNOTATION_SIG = "org.eclipse.jdt.internal.compiler.ast.Annotation";
|
||||
|
||||
sm.addScript(ScriptBuilder.wrapReturnValue()
|
||||
.target(new MethodTarget(SOURCE_TYPE_CONVERTER_SIG, "convertAnnotations", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG))
|
||||
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "convertAnnotations", ANNOTATION_SIG + "[]", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG))
|
||||
.request(StackRequest.PARAM1, StackRequest.RETURN_VALUE).build());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user