diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2011-11-15 14:11:15 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2011-11-15 14:11:15 +0100 |
commit | 1cdd42ac10c128765d3ff642d808c00eab6a1782 (patch) | |
tree | ede0a5716dc39d36c0d19a1026196cf43d1055ee /src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java | |
parent | f3253a73c29c393bb572e05c992afa22b4de4748 (diff) | |
parent | b43cd3509311e25b64a559cd7dd02d11a45d9f0e (diff) | |
download | lombok-1cdd42ac10c128765d3ff642d808c00eab6a1782.tar.gz lombok-1cdd42ac10c128765d3ff642d808c00eab6a1782.tar.bz2 lombok-1cdd42ac10c128765d3ff642d808c00eab6a1782.zip |
Merge branch 'Issue_138' of https://github.com/jvanderhel/lombok into jvanderhel-Issue_138
Conflicts:
src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java')
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java index 8da7f668..f5306ab9 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java @@ -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 { @@ -92,6 +94,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 { |