mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 04:16:19 +00:00
Added some 'live debugging' - patches to improve error reporting for bugs that are very hard to reproduce.
This commit is contained in:
1 parent
8e1cbe1b10
commit
33b3e798fd
2 files changed
+35
No files matched your search
@@ -63,6 +63,7 @@ public class EclipsePatcher extends Agent {
|
||||
patchCatchReparse(sm);
|
||||
patchSetGeneratedFlag(sm);
|
||||
patchHideGeneratedNodes(sm);
|
||||
patchLiveDebug(sm);
|
||||
}
|
||||
|
||||
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
|
||||
@@ -165,6 +166,20 @@ public class EclipsePatcher extends Agent {
|
||||
.transplant().build());
|
||||
}
|
||||
|
||||
/**
|
||||
* XXX LIVE DEBUG
|
||||
*
|
||||
* Adds patches to improve error reporting in cases of extremely rare bugs that are hard to reproduce. These should be removed
|
||||
* once the issue has been solved!
|
||||
*/
|
||||
private static void patchLiveDebug(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget(
|
||||
"org.eclipse.jdt.internal.compiler.ast.MethodDeclaration", "resolveStatements", "void"))
|
||||
.decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "debugPrintStateOfScope", "boolean", "java.lang.Object"))
|
||||
.request(StackRequest.THIS).build());
|
||||
}
|
||||
|
||||
private static void patchAvoidReparsingGeneratedCode(ScriptManager sm) {
|
||||
final String PARSER_SIG = "org.eclipse.jdt.internal.compiler.parser.Parser";
|
||||
sm.addScript(ScriptBuilder.exitEarly()
|
||||
|
||||
@@ -20,6 +20,26 @@ public class PatchFixes {
|
||||
return (bits & ALREADY_PROCESSED_FLAG) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* XXX LIVE DEBUG
|
||||
*
|
||||
* Once in a blue moon eclipse throws a NullPointerException while editing a file. Can't reproduce it while running eclipse in a debugger,
|
||||
* but at least this way we patch the problem to be a bit more specific in the error that should then appear.
|
||||
*/
|
||||
public static boolean debugPrintStateOfScope(Object in) throws Exception {
|
||||
/* this.scope.enclosingSourceType().sourceName */
|
||||
Object scope = in.getClass().getField("scope").get(in);
|
||||
String msg = null;
|
||||
if (scope == null) msg = "scope itself is null";
|
||||
else {
|
||||
Object sourceTypeBinding = scope.getClass().getMethod("enclosingSourceType").invoke(scope);
|
||||
if (sourceTypeBinding == null) msg = "scope.enclosingSourceType() is null";
|
||||
}
|
||||
|
||||
if (msg != null) throw new NullPointerException(msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean skipRewritingGeneratedNodes(org.eclipse.jdt.core.dom.ASTNode node) throws Exception {
|
||||
return ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user