mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 20:17:25 +00:00
Using @Delegate to add a varargs method now works in eclipse (the varargs nature of the method is preserved).
This commit is contained in:
1 parent
2f99cb62a1
commit
b56924dcd7
3 files changed
+20
-1
No files matched your search
@@ -62,6 +62,7 @@ public class EclipsePatcher extends Agent {
|
||||
patchLombokizeAST(sm);
|
||||
patchCatchReparse(sm);
|
||||
patchIdentifierEndReparse(sm);
|
||||
patchRetrieveEllipsisStartPosition(sm);
|
||||
patchSetGeneratedFlag(sm);
|
||||
patchHideGeneratedNodes(sm);
|
||||
patchLiveDebug(sm);
|
||||
@@ -151,6 +152,13 @@ public class EclipsePatcher extends Agent {
|
||||
.transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM2).build());
|
||||
}
|
||||
|
||||
private static void patchRetrieveEllipsisStartPosition(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.wrapReturnValue()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveEllipsisStartPosition"))
|
||||
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "fixRetrieveEllipsisStartPosition", "int", "int", "int"))
|
||||
.transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM2).build());
|
||||
}
|
||||
|
||||
private static void patchSetGeneratedFlag(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.addField()
|
||||
.targetClass("org.eclipse.jdt.internal.compiler.ast.ASTNode")
|
||||
|
||||
@@ -166,7 +166,6 @@ public class PatchDelegate {
|
||||
if (!Arrays.equals(mb.selector, name)) continue;
|
||||
int paramLen = mb.parameters == null ? 0 : mb.parameters.length;
|
||||
if (paramLen != args.length) continue;
|
||||
// TODO check if varargs are copied or otherwise handled correctly.
|
||||
for (int i = 0; i < paramLen; i++) {
|
||||
if (!mb.parameters[i].erasure().isEquivalentTo(args[i])) continue methods;
|
||||
}
|
||||
@@ -328,6 +327,8 @@ public class PatchDelegate {
|
||||
* }
|
||||
*/
|
||||
|
||||
boolean isVarargs = (pair.base.modifiers & ClassFileConstants.AccVarargs) != 0;
|
||||
|
||||
try {
|
||||
checkConflictOfTypeVarNames(pair, typeNode);
|
||||
} catch (CantMakeDelegates e) {
|
||||
@@ -423,6 +424,12 @@ public class PatchDelegate {
|
||||
call.arguments[i] = new SingleNameReference(argName, pos(source));
|
||||
Eclipse.setGeneratedBy(call.arguments[i], source);
|
||||
}
|
||||
if (isVarargs) {
|
||||
method.arguments[method.arguments.length - 1].type.bits |= ASTNode.IsVarArgs;
|
||||
}
|
||||
for (int i = 0; i < method.arguments.length; i++) {
|
||||
System.out.printf("Positions of marg type: %d %d\n", method.arguments[i].sourceStart(), method.arguments[i].sourceEnd());
|
||||
}
|
||||
}
|
||||
|
||||
Statement body;
|
||||
|
||||
@@ -44,6 +44,10 @@ public class PatchFixes {
|
||||
return original == -1 ? end : original;
|
||||
}
|
||||
|
||||
public static int fixRetrieveEllipsisStartPosition(int original, int end) {
|
||||
return original == -1 ? end : original;
|
||||
}
|
||||
|
||||
public static final int ALREADY_PROCESSED_FLAG = 0x800000; //Bit 24
|
||||
|
||||
public static boolean checkBit24(Object node) throws Exception {
|
||||
|
||||
Reference in new issue
Block a user