mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 10:18:46 +00:00
Improve Extract method refactoring: you can extract method for code that also contains @SneakyThrows
This commit is contained in:
1 parent
85c90ca606
commit
14efdb09ad
3 files changed
+29
-2
No files matched your search
@@ -231,8 +231,10 @@ public class HandleSneakyThrows extends EclipseAnnotationHandler<SneakyThrows> {
|
||||
tryStatement.catchBlocks = new Block[] { block };
|
||||
|
||||
// Positions for in-method generated nodes are special
|
||||
tryStatement.sourceStart = method.bodyStart;
|
||||
tryStatement.sourceEnd = method.bodyEnd;
|
||||
// tryStatement.sourceStart = method.bodyStart;
|
||||
// tryStatement.sourceEnd = method.bodyEnd;
|
||||
tryStatement.sourceStart = pS;
|
||||
tryStatement.sourceEnd = pE;
|
||||
|
||||
return tryStatement;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ public class EclipsePatcher extends Agent {
|
||||
patchIdentifierEndReparse(sm);
|
||||
patchRetrieveEllipsisStartPosition(sm);
|
||||
patchSetGeneratedFlag(sm);
|
||||
patchDomAstReparseIssues(sm);
|
||||
patchHideGeneratedNodes(sm);
|
||||
patchPostCompileHookEclipse(sm);
|
||||
patchFixSourceTypeConverter(sm);
|
||||
@@ -98,6 +99,17 @@ public class EclipsePatcher extends Agent {
|
||||
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
|
||||
}
|
||||
|
||||
private static void patchDomAstReparseIssues(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer", "visit"))
|
||||
.methodToReplace(new Hook("org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner", "getTokenEndOffset", "int", "int", "int"))
|
||||
.replacementMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getTokenEndOffsetFixed", "int", "org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner", "int", "int", "java.lang.Object"))
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.transplant()
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
private static void patchPostCompileHookEclipse(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder", "writeClassFileContents"))
|
||||
|
||||
@@ -32,11 +32,13 @@ import java.util.List;
|
||||
import lombok.core.DiagnosticsReceiver;
|
||||
import lombok.core.PostCompiler;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jdt.core.IAnnotatable;
|
||||
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.TokenScanner;
|
||||
|
||||
public class PatchFixes {
|
||||
public static int fixRetrieveStartingCatchPosition(int original, int start) {
|
||||
@@ -80,6 +82,17 @@ public class PatchFixes {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getTokenEndOffsetFixed(TokenScanner scanner, int token, int startOffset, Object domNode) throws CoreException {
|
||||
boolean isGenerated = false;
|
||||
try {
|
||||
isGenerated = (Boolean) domNode.getClass().getField("$isGenerated").get(domNode);
|
||||
} catch (Exception e) {
|
||||
// If this fails, better to break some refactor scripts than to crash eclipse.
|
||||
}
|
||||
if (isGenerated) return -1;
|
||||
return scanner.getTokenEndOffset(token, startOffset);
|
||||
}
|
||||
|
||||
public static IMethod[] removeGeneratedMethods(IMethod[] methods) throws Exception {
|
||||
List<IMethod> result = new ArrayList<IMethod>();
|
||||
for (IMethod m : methods) {
|
||||
|
||||
Reference in new issue
Block a user