mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 14:16:39 +00:00
Merge pull request #15 from jvanderhel/Issue_51
Proposed fix for Issue 51 and 301
This commit is contained in:
commit
6d6a191c67
2 files changed
+26
-18
No files matched your search
@@ -115,9 +115,16 @@ public class EclipsePatcher extends Agent {
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.ForStatement"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.IfStatement"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.WhileStatement"))
|
||||
.decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.Statement"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$ThisQualifierVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.MethodInvocation"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$ThisQualifierVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.FieldAccess"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$CodeStyleVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.MethodInvocation"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$CodeStyleVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.TypeDeclaration"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$CodeStyleVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.QualifiedName"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$CodeStyleVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName"))
|
||||
// if a generated node has children we can just ignore them as well;
|
||||
.decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
|
||||
.request(StackRequest.PARAM1)
|
||||
.valueMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.Statement"))
|
||||
.valueMethod(new Hook("lombok.eclipse.agent.PatchFixes", "returnFalse", "boolean", "java.lang.Object"))
|
||||
.build());
|
||||
}
|
||||
|
||||
|
||||
@@ -43,16 +43,22 @@ import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent;
|
||||
import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner;
|
||||
|
||||
public class PatchFixes {
|
||||
public static boolean isGenerated(org.eclipse.jdt.core.dom.Statement statement) {
|
||||
public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) {
|
||||
boolean result = false;
|
||||
try {
|
||||
result = ((Boolean)statement.getClass().getField("$isGenerated").get(statement)).booleanValue();
|
||||
result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
|
||||
if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName)
|
||||
result = isGenerated(node.getParent());
|
||||
} catch (Exception e) {
|
||||
// better to assume it isn't generated
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static boolean returnFalse(java.lang.Object object) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int fixRetrieveStartingCatchPosition(int original, int start) {
|
||||
return original == -1 ? start : original;
|
||||
}
|
||||
@@ -104,19 +110,14 @@ public class PatchFixes {
|
||||
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)
|
||||
boolean isGenerated = isGenerated( (org.eclipse.jdt.core.dom.ASTNode)child.getOriginalValue() );
|
||||
if (isGenerated) {
|
||||
if ((child.getChangeKind() == RewriteEvent.REPLACED || child.getChangeKind() == RewriteEvent.REMOVED)
|
||||
&& child.getOriginalValue() instanceof org.eclipse.jdt.core.dom.MethodDeclaration
|
||||
&& child.getNewValue() != null
|
||||
) {
|
||||
modifiedChildren.add(new NodeRewriteEvent(null, child.getNewValue()));
|
||||
}
|
||||
} else {
|
||||
newChildren.add(child);
|
||||
}
|
||||
@@ -216,4 +217,4 @@ public class PatchFixes {
|
||||
|
||||
return replace;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user