mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 12:14:31 +00:00
Lombok generated members are now handled better in a ListRewrite (like generate equals & hashcode)
This commit is contained in:
1 parent
9c469dc72a
commit
b43cd35093
2 files changed
+40
No files matched your search
@@ -89,6 +89,7 @@ public class EclipsePatcher extends Agent {
|
||||
patchHideGeneratedNodes(sm);
|
||||
patchPostCompileHookEclipse(sm);
|
||||
patchFixSourceTypeConverter(sm);
|
||||
patchListRewriteHandleGeneratedMethods(sm);
|
||||
} else {
|
||||
patchPostCompileHookEcj(sm);
|
||||
}
|
||||
@@ -99,6 +100,14 @@ public class EclipsePatcher extends Agent {
|
||||
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
|
||||
}
|
||||
|
||||
private static void patchListRewriteHandleGeneratedMethods(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter", "rewriteList"))
|
||||
.methodToReplace(new Hook("org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent", "getChildren", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent[]"))
|
||||
.replacementMethod(new Hook("lombok.eclipse.agent.PatchFixes", "listRewriteHandleGeneratedMethods", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent[]", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent"))
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void patchDomAstReparseIssues(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer", "visit"))
|
||||
|
||||
@@ -38,6 +38,8 @@ import org.eclipse.jdt.core.IAnnotation;
|
||||
import org.eclipse.jdt.core.IMethod;
|
||||
import org.eclipse.jdt.core.dom.SimpleName;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Annotation;
|
||||
import org.eclipse.jdt.internal.core.dom.rewrite.NodeRewriteEvent;
|
||||
import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent;
|
||||
import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner;
|
||||
|
||||
public class PatchFixes {
|
||||
@@ -82,6 +84,35 @@ public class PatchFixes {
|
||||
}
|
||||
}
|
||||
|
||||
public static RewriteEvent[] listRewriteHandleGeneratedMethods(RewriteEvent parent) {
|
||||
RewriteEvent[] children = parent.getChildren();
|
||||
List<RewriteEvent> newChildren = new ArrayList<RewriteEvent>();
|
||||
List<RewriteEvent> modifiedChildren = new ArrayList<RewriteEvent>();
|
||||
for (int i=0; i<children.length; i++) {
|
||||
RewriteEvent child = children[i];
|
||||
boolean isGenerated = false;
|
||||
try {
|
||||
org.eclipse.jdt.core.dom.ASTNode originalValue = (org.eclipse.jdt.core.dom.ASTNode)child.getOriginalValue();
|
||||
isGenerated = (Boolean) originalValue.getClass().getField("$isGenerated").get(originalValue);
|
||||
} catch (Exception e) {
|
||||
// If this fails, better to break some refactor scripts than to crash eclipse.
|
||||
}
|
||||
if (isGenerated
|
||||
&& (child.getChangeKind() == RewriteEvent.REPLACED || child.getChangeKind() == RewriteEvent.REMOVED)
|
||||
&& child.getOriginalValue() instanceof org.eclipse.jdt.core.dom.MethodDeclaration
|
||||
) {
|
||||
if (child.getNewValue() != null)
|
||||
modifiedChildren.add(new NodeRewriteEvent(null, child.getNewValue()));
|
||||
} else {
|
||||
newChildren.add(child);
|
||||
}
|
||||
}
|
||||
// Since Eclipse doesn't honor the "insert at specified location" for already existing members,
|
||||
// we'll just add them last
|
||||
newChildren.addAll(modifiedChildren);
|
||||
return newChildren.toArray(new RewriteEvent[newChildren.size()]);
|
||||
}
|
||||
|
||||
public static int getTokenEndOffsetFixed(TokenScanner scanner, int token, int startOffset, Object domNode) throws CoreException {
|
||||
boolean isGenerated = false;
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user