Skip to content

Commit

Permalink
Fix for Issue 265, Sort members now works when class has @DaTa and @log
Browse files Browse the repository at this point in the history
… annotation
  • Loading branch information
jvanderhel committed Dec 20, 2011
1 parent 0a87943 commit 02d7e29
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private static void registerPatchScripts(Instrumentation instrumentation, boolea
patchDisableLombokForCodeFormatterAndCleanup(sm);
patchListRewriteHandleGeneratedMethods(sm);
patchSyntaxAndOccurrencesHighlighting(sm);
patchSortMembersOperation(sm);
} else {
patchPostCompileHookEcj(sm);
}
Expand Down Expand Up @@ -150,6 +151,48 @@ private static void patchListRewriteHandleGeneratedMethods(ScriptManager sm) {
.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 patchSortMembersOperation(ScriptManager sm) {
/* Fixes "sort members" action with @Data @Log
* I would have liked to patch sortMembers, but kept getting a VerifyError: Illegal type in constant pool
* So now I just patch all calling methods
*/
sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.CompilationUnit"))
.methodToWrap(new Hook("org.eclipse.jdt.core.dom.CompilationUnit", "types", "java.util.List"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List"))
.transplant().build());

sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.AnnotationTypeDeclaration"))
.methodToWrap(new Hook("org.eclipse.jdt.core.dom.AnnotationTypeDeclaration", "bodyDeclarations", "java.util.List"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List"))
.transplant().build());

sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.AnonymousClassDeclaration"))
.methodToWrap(new Hook("org.eclipse.jdt.core.dom.AnonymousClassDeclaration", "bodyDeclarations", "java.util.List"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List"))
.transplant().build());

sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.TypeDeclaration"))
.methodToWrap(new Hook("org.eclipse.jdt.core.dom.TypeDeclaration", "bodyDeclarations", "java.util.List"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List"))
.transplant().build());

sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.EnumDeclaration"))
.methodToWrap(new Hook("org.eclipse.jdt.core.dom.EnumDeclaration", "bodyDeclarations", "java.util.List"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List"))
.transplant().build());

sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.EnumDeclaration"))
.methodToWrap(new Hook("org.eclipse.jdt.core.dom.EnumDeclaration", "enumConstants", "java.util.List"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List"))
.transplant().build());
}

private static void patchDomAstReparseIssues(ScriptManager sm) {
sm.addScript(ScriptBuilder.replaceMethodCall()
Expand Down
14 changes: 14 additions & 0 deletions src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) {
public static boolean returnFalse(java.lang.Object object) {
return false;
}

@java.lang.SuppressWarnings({"unchecked", "rawtypes"}) public static java.util.List removeGeneratedNodes(java.util.List list) {
try {
java.util.List realNodes = new java.util.ArrayList(list.size());
for (java.lang.Object node : list) {
if(!isGenerated(((org.eclipse.jdt.core.dom.ASTNode)node))) {
realNodes.add(node);
}
}
return realNodes;
} catch (Exception e) {
}
return list;
}

/* Very practical implementation, but works for getter and setter even with type parameters */
public static java.lang.String getRealMethodDeclarationSource(java.lang.String original, org.eclipse.jdt.core.dom.MethodDeclaration declaration) {
Expand Down

0 comments on commit 02d7e29

Please sign in to comment.