mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 08:17:18 +00:00
Merge branch 'Issue_81' of https://github.com/jvanderhel/lombok into jvanderhel-Issue_81
Conflicts: src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
This commit is contained in:
commit
aaf3101393
2 files changed
+44
-1
No files matched your search
@@ -174,6 +174,25 @@ public class EclipsePatcher extends Agent {
|
||||
}
|
||||
|
||||
private static void patchHideGeneratedNodes(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.SourceElementNotifier", "notifySourceElementRequestor", "void", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.ImportReference"))
|
||||
.methodToWrap(new Hook("org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt", "get", "int", "java.lang.Object"))
|
||||
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getSourceEndFixed", "int", "int", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.transplant().build());
|
||||
|
||||
sm.addScript(ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodDeclaration", "void",
|
||||
"org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite",
|
||||
"org.eclipse.jdt.core.dom.rewrite.ASTRewrite",
|
||||
"org.eclipse.jdt.core.dom.AbstractTypeDeclaration",
|
||||
"org.eclipse.jdt.core.dom.MethodDeclaration"
|
||||
))
|
||||
.methodToWrap(new Hook("org.eclipse.jface.text.IDocument", "get", "java.lang.String", "int", "int"))
|
||||
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getRealMethodDeclarationSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.dom.MethodDeclaration"))
|
||||
.requestExtra(StackRequest.PARAM4)
|
||||
.build());
|
||||
|
||||
sm.addScript(ScriptBuilder.wrapReturnValue()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByBinding"))
|
||||
|
||||
@@ -59,6 +59,30 @@ public class PatchFixes {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
if(isGenerated(declaration)) {
|
||||
String returnType = declaration.getReturnType2().toString();
|
||||
String params = "";
|
||||
for (Object object : declaration.parameters()) {
|
||||
org.eclipse.jdt.core.dom.ASTNode parameter = ((org.eclipse.jdt.core.dom.ASTNode)object);
|
||||
params += ","+parameter.toString();
|
||||
}
|
||||
return returnType + " "+declaration.getName().getFullyQualifiedName()+"("+(params.isEmpty() ? "" : params.substring(1))+");";
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
public static int getSourceEndFixed(int sourceEnd, org.eclipse.jdt.internal.compiler.ast.ASTNode node) throws Exception {
|
||||
if (sourceEnd == -1) {
|
||||
org.eclipse.jdt.internal.compiler.ast.ASTNode object = (org.eclipse.jdt.internal.compiler.ast.ASTNode)node.getClass().getField("$generatedBy").get(node);
|
||||
if (object != null) {
|
||||
return object.sourceEnd;
|
||||
}
|
||||
}
|
||||
return sourceEnd;
|
||||
}
|
||||
|
||||
public static int fixRetrieveStartingCatchPosition(int original, int start) {
|
||||
return original == -1 ? start : original;
|
||||
}
|
||||
@@ -217,4 +241,4 @@ public class PatchFixes {
|
||||
|
||||
return replace;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user