aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2012-10-08 20:26:06 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2012-10-08 20:26:06 +0200
commit0baf73b2aaecebf75a51f3d064c6d925a52f1a6d (patch)
tree6239444c69a32a1790cb81176895268e8ff3248c /src/eclipseAgent/lombok
parenta733c15082bcf4b56ebd27018c7fbfe01f03faca (diff)
downloadlombok-0baf73b2aaecebf75a51f3d064c6d925a52f1a6d.tar.gz
lombok-0baf73b2aaecebf75a51f3d064c6d925a52f1a6d.tar.bz2
lombok-0baf73b2aaecebf75a51f3d064c6d925a52f1a6d.zip
Patches ASTNode.setSourceRange; by default it throws IllegalArgumentExceptions in certain cases, but with no message, thus making it very hard to figure out what went wrong. The patch throws the same exceptions in the same cases, but gives the exception a useful error message.
Diffstat (limited to 'src/eclipseAgent/lombok')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java14
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java44
2 files changed, 58 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 4c6b6618..f9b53e68 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -96,6 +96,7 @@ public class EclipsePatcher extends Agent {
patchSortMembersOperation(sm);
patchExtractInterface(sm);
patchAboutDialog(sm);
+ patchEclipseDebugPatches(sm);
} else {
patchPostCompileHookEcj(sm);
}
@@ -645,6 +646,19 @@ public class EclipsePatcher extends Agent {
.request(StackRequest.PARAM1, StackRequest.RETURN_VALUE).build());
}
+ private static void patchEclipseDebugPatches(ScriptManager sm) {
+ final String ASTNODE_SIG = "org.eclipse.jdt.core.dom.ASTNode";
+ final String PATCH_DEBUG = "lombok.eclipse.agent.PatchDiagnostics";
+
+ sm.addScript(exitEarly()
+ .target(new MethodTarget(ASTNODE_SIG, "setSourceRange", "void", "int", "int"))
+ .request(StackRequest.THIS)
+ .request(StackRequest.PARAM1)
+ .request(StackRequest.PARAM2)
+ .decisionMethod(new Hook(PATCH_DEBUG, "setSourceRangeCheck", "boolean", "java.lang.Object", "int", "int"))
+ .build());
+ }
+
private static void patchExtensionMethod(ScriptManager sm, boolean ecj) {
final String PATCH_EXTENSIONMETHOD = "lombok.eclipse.agent.PatchExtensionMethod";
final String PATCH_EXTENSIONMETHOD_COMPLETIONPROPOSAL_PORTAL = "lombok.eclipse.agent.PatchExtensionMethodCompletionProposalPortal";
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java
new file mode 100644
index 00000000..82c4f522
--- /dev/null
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 The Project Lombok Authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package lombok.eclipse.agent;
+
+public class PatchDiagnostics {
+ /**
+ *
+ * org.eclipse.jdt.core.dom.ASTNode#setSourceRange starts off doing some sanity checks on the input arguments, and, if these fail the sanity check,
+ * a {@code IllegalArgumentException} is thrown. However, these IAEs do not have any message and are thus pretty much useless. We do the exact same
+ * checks, and throw the exact same exception (thus, effectively, we don't change how eclipse operates), but, we <em>do</em> provide a useful message.
+ */
+ public static boolean setSourceRangeCheck(Object astNode, int startPosition, int length) {
+ if (startPosition >= 0 && length < 0) {
+ throw new IllegalArgumentException("startPos = " + startPosition + " and length is " + length + ".\n" +
+ "This breaks the rule that lengths are not allowed to be negative. Affected Node:\n" + astNode);
+ }
+
+ if (startPosition < 0 && length != 0) {
+ throw new IllegalArgumentException("startPos = " + startPosition + " and length is " + length + ".\n" +
+ "This breaks the rule that length must be 0 if startPosition is negative. Affected Node:\n" + astNode);
+ }
+
+ return false;
+ }
+}