aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java14
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java69
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java100
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposalPortal.java72
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodPortal.java133
5 files changed, 184 insertions, 204 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 380b961e..4c6b6618 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -646,7 +646,8 @@ public class EclipsePatcher extends Agent {
}
private static void patchExtensionMethod(ScriptManager sm, boolean ecj) {
- final String PATCH_EXTENSIONMETHOD_PORTAL = "lombok.eclipse.agent.PatchExtensionMethodPortal";
+ final String PATCH_EXTENSIONMETHOD = "lombok.eclipse.agent.PatchExtensionMethod";
+ final String PATCH_EXTENSIONMETHOD_COMPLETIONPROPOSAL_PORTAL = "lombok.eclipse.agent.PatchExtensionMethodCompletionProposalPortal";
final String MESSAGE_SEND_SIG = "org.eclipse.jdt.internal.compiler.ast.MessageSend";
final String TYPE_BINDING_SIG = "org.eclipse.jdt.internal.compiler.lookup.TypeBinding";
final String BLOCK_SCOPE_SIG = "org.eclipse.jdt.internal.compiler.lookup.BlockScope";
@@ -661,18 +662,18 @@ public class EclipsePatcher extends Agent {
.request(StackRequest.RETURN_VALUE)
.request(StackRequest.THIS)
.request(StackRequest.PARAM1)
- .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD_PORTAL, "resolveType", TYPE_BINDING_SIG, "java.lang.Object", "java.lang.Object", "java.lang.Object"))
+ .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD, "resolveType", TYPE_BINDING_SIG, TYPE_BINDING_SIG, MESSAGE_SEND_SIG, BLOCK_SCOPE_SIG))
.build());
-
sm.addScript(replaceMethodCall()
.target(new MethodTarget(MESSAGE_SEND_SIG, "resolveType", TYPE_BINDING_SIG, BLOCK_SCOPE_SIG))
.methodToReplace(new Hook(PROBLEM_REPORTER_SIG, "errorNoMethodFor", "void", MESSAGE_SEND_SIG, TYPE_BINDING_SIG, TYPE_BINDINGS_SIG))
- .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD_PORTAL, "errorNoMethodFor", "void", "java.lang.Object", "java.lang.Object", "java.lang.Object", "java.lang.Object"))
+ .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "errorNoMethodFor", "void", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, TYPE_BINDING_SIG, TYPE_BINDINGS_SIG))
.build());
+
sm.addScript(replaceMethodCall()
.target(new MethodTarget(MESSAGE_SEND_SIG, "resolveType", TYPE_BINDING_SIG, BLOCK_SCOPE_SIG))
.methodToReplace(new Hook(PROBLEM_REPORTER_SIG, "invalidMethod", "void", MESSAGE_SEND_SIG, METHOD_BINDING_SIG))
- .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD_PORTAL, "invalidMethod", "void", "java.lang.Object", "java.lang.Object", "java.lang.Object"))
+ .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "invalidMethod", "void", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, METHOD_BINDING_SIG))
.build());
if (!ecj) {
@@ -680,8 +681,7 @@ public class EclipsePatcher extends Agent {
.target(new MethodTarget(COMPLETION_PROPOSAL_COLLECTOR_SIG, "getJavaCompletionProposals", I_JAVA_COMPLETION_PROPOSAL_SIG))
.request(StackRequest.RETURN_VALUE)
.request(StackRequest.THIS)
-// .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD_PORTAL, "getJavaCompletionProposals", I_JAVA_COMPLETION_PROPOSAL_SIG, I_JAVA_COMPLETION_PROPOSAL_SIG, COMPLETION_PROPOSAL_COLLECTOR_SIG))
- .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD_PORTAL, "getJavaCompletionProposals", "java.lang.Object", "java.lang.Object", "java.lang.Object"))
+ .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD_COMPLETIONPROPOSAL_PORTAL, "getJavaCompletionProposals", I_JAVA_COMPLETION_PROPOSAL_SIG, "java.lang.Object[]", "java.lang.Object"))
.build());
}
}
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
index 589f791c..1b244234 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
@@ -64,7 +64,6 @@ import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
-import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
@@ -73,13 +72,11 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
-import org.eclipse.jdt.internal.core.SearchableEnvironment;
import org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal;
import org.eclipse.jdt.ui.text.java.CompletionProposalCollector;
-import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
public class PatchExtensionMethod {
- private static class Extension {
+ static class Extension {
List<MethodBinding> extensionMethods;
boolean suppressBaseMethods;
}
@@ -299,63 +296,7 @@ public class PatchExtensionMethod {
}
}
- public static IJavaCompletionProposal[] getJavaCompletionProposals(IJavaCompletionProposal[] javaCompletionProposals,
- CompletionProposalCollector completionProposalCollector) {
-
- List<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(Arrays.asList(javaCompletionProposals));
- if (canExtendCodeAssist(proposals)) {
- IJavaCompletionProposal firstProposal = proposals.get(0);
- int replacementOffset = getReplacementOffset(firstProposal);
- for (Extension extension : getExtensionMethods(completionProposalCollector)) {
- for (MethodBinding method : extension.extensionMethods) {
- ExtensionMethodCompletionProposal newProposal = new ExtensionMethodCompletionProposal(replacementOffset);
- copyNameLookupAndCompletionEngine(completionProposalCollector, firstProposal, newProposal);
- ASTNode node = getAssistNode(completionProposalCollector);
- newProposal.setMethodBinding(method, node);
- createAndAddJavaCompletionProposal(completionProposalCollector, newProposal, proposals);
- }
- }
- }
- return proposals.toArray(new IJavaCompletionProposal[proposals.size()]);
- }
-
- private static void copyNameLookupAndCompletionEngine(CompletionProposalCollector completionProposalCollector, IJavaCompletionProposal proposal,
- InternalCompletionProposal newProposal) {
-
- try {
- InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
- InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
- LookupEnvironment lookupEnvironment = (LookupEnvironment) Reflection.lookupEnvironmentField.get(extendedContext);
- Reflection.nameLookupField.set(newProposal, ((SearchableEnvironment) lookupEnvironment.nameEnvironment).nameLookup);
- Reflection.completionEngineField.set(newProposal, lookupEnvironment.typeRequestor);
- } catch (IllegalAccessException ignore) {
- // ignore
- }
- }
-
- private static void createAndAddJavaCompletionProposal(CompletionProposalCollector completionProposalCollector, CompletionProposal newProposal,
- List<IJavaCompletionProposal> proposals) {
-
- try {
- proposals.add((IJavaCompletionProposal) Reflection.createJavaCompletionProposalMethod.invoke(completionProposalCollector, newProposal));
- } catch (Exception ignore) {
- // ignore
- }
- }
-
- private static boolean canExtendCodeAssist(List<IJavaCompletionProposal> proposals) {
- return !proposals.isEmpty() && Reflection.isComplete();
- }
-
- private static int getReplacementOffset(IJavaCompletionProposal proposal) {
- try {
- return Reflection.replacementOffsetField.getInt(proposal);
- } catch (Exception ignore) {
- return 0;
- }
- }
-
- private static List<Extension> getExtensionMethods(CompletionProposalCollector completionProposalCollector) {
+ static List<Extension> getExtensionMethods(CompletionProposalCollector completionProposalCollector) {
List<Extension> extensions = new ArrayList<Extension>();
ClassScope classScope = getClassScope(completionProposalCollector);
if (classScope != null) {
@@ -407,7 +348,7 @@ public class PatchExtensionMethod {
return firstParameterType;
}
- private static ASTNode getAssistNode(CompletionProposalCollector completionProposalCollector) {
+ static ASTNode getAssistNode(CompletionProposalCollector completionProposalCollector) {
try {
InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
@@ -418,7 +359,7 @@ public class PatchExtensionMethod {
}
}
- private static class Reflection {
+ static class Reflection {
public static final Field replacementOffsetField;
public static final Field contextField;
public static final Field extendedContextField;
@@ -441,7 +382,7 @@ public class PatchExtensionMethod {
createJavaCompletionProposalMethod = accessMethod(CompletionProposalCollector.class, "createJavaCompletionProposal", CompletionProposal.class);
}
- private static boolean isComplete() {
+ static boolean isComplete() {
Object[] requiredFieldsAndMethods = { replacementOffsetField, contextField, extendedContextField, assistNodeField, assistScopeField, lookupEnvironmentField, completionEngineField, nameLookupField, createJavaCompletionProposalMethod };
for (Object o : requiredFieldsAndMethods) if (o == null) return false;
return true;
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java
new file mode 100644
index 00000000..bd6e328c
--- /dev/null
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import lombok.eclipse.agent.PatchExtensionMethod.Extension;
+import lombok.eclipse.agent.PatchExtensionMethod.Reflection;
+
+import org.eclipse.jdt.core.CompletionProposal;
+import org.eclipse.jdt.internal.codeassist.InternalCompletionContext;
+import org.eclipse.jdt.internal.codeassist.InternalCompletionProposal;
+import org.eclipse.jdt.internal.codeassist.InternalExtendedCompletionContext;
+import org.eclipse.jdt.internal.compiler.ast.ASTNode;
+import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
+import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
+import org.eclipse.jdt.internal.core.SearchableEnvironment;
+import org.eclipse.jdt.ui.text.java.CompletionProposalCollector;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+
+public class PatchExtensionMethodCompletionProposal {
+
+
+ public static IJavaCompletionProposal[] getJavaCompletionProposals(IJavaCompletionProposal[] javaCompletionProposals,
+ CompletionProposalCollector completionProposalCollector) {
+
+ List<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(Arrays.asList(javaCompletionProposals));
+ if (canExtendCodeAssist(proposals)) {
+ IJavaCompletionProposal firstProposal = proposals.get(0);
+ int replacementOffset = getReplacementOffset(firstProposal);
+ for (Extension extension : PatchExtensionMethod.getExtensionMethods(completionProposalCollector)) {
+ for (MethodBinding method : extension.extensionMethods) {
+ ExtensionMethodCompletionProposal newProposal = new ExtensionMethodCompletionProposal(replacementOffset);
+ copyNameLookupAndCompletionEngine(completionProposalCollector, firstProposal, newProposal);
+ ASTNode node = PatchExtensionMethod.getAssistNode(completionProposalCollector);
+ newProposal.setMethodBinding(method, node);
+ createAndAddJavaCompletionProposal(completionProposalCollector, newProposal, proposals);
+ }
+ }
+ }
+ return proposals.toArray(new IJavaCompletionProposal[proposals.size()]);
+ }
+
+ private static void copyNameLookupAndCompletionEngine(CompletionProposalCollector completionProposalCollector, IJavaCompletionProposal proposal,
+ InternalCompletionProposal newProposal) {
+
+ try {
+ InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
+ InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
+ LookupEnvironment lookupEnvironment = (LookupEnvironment) Reflection.lookupEnvironmentField.get(extendedContext);
+ Reflection.nameLookupField.set(newProposal, ((SearchableEnvironment) lookupEnvironment.nameEnvironment).nameLookup);
+ Reflection.completionEngineField.set(newProposal, lookupEnvironment.typeRequestor);
+ } catch (IllegalAccessException ignore) {
+ // ignore
+ }
+ }
+
+ private static void createAndAddJavaCompletionProposal(CompletionProposalCollector completionProposalCollector, CompletionProposal newProposal,
+ List<IJavaCompletionProposal> proposals) {
+
+ try {
+ proposals.add((IJavaCompletionProposal) Reflection.createJavaCompletionProposalMethod.invoke(completionProposalCollector, newProposal));
+ } catch (Exception ignore) {
+ // ignore
+ }
+ }
+
+ private static boolean canExtendCodeAssist(List<IJavaCompletionProposal> proposals) {
+ return !proposals.isEmpty() && Reflection.isComplete();
+ }
+
+ private static int getReplacementOffset(IJavaCompletionProposal proposal) {
+ try {
+ return Reflection.replacementOffsetField.getInt(proposal);
+ } catch (Exception ignore) {
+ return 0;
+ }
+ }
+}
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposalPortal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposalPortal.java
new file mode 100644
index 00000000..29aedc81
--- /dev/null
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposalPortal.java
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+
+import lombok.Lombok;
+
+
+public class PatchExtensionMethodCompletionProposalPortal {
+ private static final String COMPLETION_PROPOSAL_COLLECTOR = "org.eclipse.jdt.ui.text.java.CompletionProposalCollector";
+ private static final String I_JAVA_COMPLETION_PROPOSAL_ARRAY = "[Lorg.eclipse.jdt.ui.text.java.IJavaCompletionProposal;";
+
+
+ public static IJavaCompletionProposal[] getJavaCompletionProposals(Object[] javaCompletionProposals, Object completionProposalCollector) {
+ try {
+ return (IJavaCompletionProposal[]) ReflectionForUi.getJavaCompletionProposals.invoke(null, javaCompletionProposals, completionProposalCollector);
+ } catch (NoClassDefFoundError e) {
+ //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly
+ //do anything useful here.
+ return (IJavaCompletionProposal[]) javaCompletionProposals;
+ } catch (IllegalAccessException e) {
+ throw Lombok.sneakyThrow(e);
+ } catch (InvocationTargetException e) {
+ throw Lombok.sneakyThrow(e);
+ } catch (NullPointerException e) {
+ e.initCause(ReflectionForUi.problem);
+ throw e;
+ }
+ }
+
+ private static final class ReflectionForUi {
+ public static final Method getJavaCompletionProposals;
+ public static final Throwable problem;
+
+ static {
+ Method p = null;
+ Throwable problem_ = null;
+ try {
+ p = PatchExtensionMethodCompletionProposal.class.getMethod("getJavaCompletionProposals", Class.forName(I_JAVA_COMPLETION_PROPOSAL_ARRAY), Class.forName(COMPLETION_PROPOSAL_COLLECTOR));
+ } catch (Throwable t) {
+ // That's problematic, but as long as no local classes are used we don't actually need it.
+ // Better fail on local classes than crash altogether.
+ problem_ = t;
+ }
+ getJavaCompletionProposals = p;
+ problem = problem_;
+ }
+ }
+}
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodPortal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodPortal.java
deleted file mode 100644
index 2ccc14ae..00000000
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodPortal.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
-
-import lombok.Lombok;
-
-
-public class PatchExtensionMethodPortal {
- private static final String TYPE_BINDING = "org.eclipse.jdt.internal.compiler.lookup.TypeBinding";
- private static final String TYPE_BINDING_ARRAY = "[Lorg.eclipse.jdt.internal.compiler.lookup.TypeBinding;";
- private static final String MESSAGE_SEND = "org.eclipse.jdt.internal.compiler.ast.MessageSend";
- private static final String BLOCK_SCOPE = "org.eclipse.jdt.internal.compiler.lookup.BlockScope";
- private static final String METHOD_BINDING = "org.eclipse.jdt.internal.compiler.lookup.MethodBinding";
- private static final String PROBLEM_REPORTER = "org.eclipse.jdt.internal.compiler.problem.ProblemReporter";
- private static final String COMPLETION_PROPOSAL_COLLECTOR = "org.eclipse.jdt.ui.text.java.CompletionProposalCollector";
- private static final String I_JAVA_COMPLETION_PROPOSAL_ARRAY = "[Lorg.eclipse.jdt.ui.text.java.IJavaCompletionProposal;";
-
- public static TypeBinding resolveType(Object resolvedType, Object methodCall, Object scope) {
- try {
- return (TypeBinding) Reflection.resolveType.invoke(null, resolvedType, methodCall, scope);
- } catch (NoClassDefFoundError e) {
- //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly
- //do anything useful here.
- return (TypeBinding) resolvedType;
- } catch (IllegalAccessException e) {
- throw Lombok.sneakyThrow(e);
- } catch (InvocationTargetException e) {
- throw Lombok.sneakyThrow(e);
- } catch (NullPointerException e) {
- e.initCause(Reflection.problem);
- throw e;
- }
- }
-
- public static void errorNoMethodFor(Object problemReporter, Object messageSend, Object recType, Object params) {
- try {
- Reflection.errorNoMethodFor.invoke(null, problemReporter, messageSend, recType, params);
- } catch (NoClassDefFoundError e) {
- //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly
- //do anything useful here.
- } catch (IllegalAccessException e) {
- Lombok.sneakyThrow(e);
- } catch (InvocationTargetException e) {
- Lombok.sneakyThrow(e);
- } catch (NullPointerException e) {
- e.initCause(Reflection.problem);
- throw e;
- }
- }
-
- public static void invalidMethod(Object problemReporter, Object messageSend, Object method) {
- try {
- Reflection.invalidMethod.invoke(null, problemReporter, messageSend, method);
- } catch (NoClassDefFoundError e) {
- //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly
- //do anything useful here.
- } catch (IllegalAccessException e) {
- Lombok.sneakyThrow(e);
- } catch (InvocationTargetException e) {
- Lombok.sneakyThrow(e);
- } catch (NullPointerException e) {
- e.initCause(Reflection.problem);
- throw e;
- }
- }
-
- public static Object getJavaCompletionProposals(Object[] javaCompletionProposals, Object completionProposalCollector) {
- try {
- return Reflection.getJavaCompletionProposals.invoke(null, javaCompletionProposals, completionProposalCollector);
- } catch (NoClassDefFoundError e) {
- //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly
- //do anything useful here.
- return javaCompletionProposals;
- } catch (IllegalAccessException e) {
- throw Lombok.sneakyThrow(e);
- } catch (InvocationTargetException e) {
- throw Lombok.sneakyThrow(e);
- } catch (NullPointerException e) {
- e.initCause(Reflection.problem);
- throw e;
- }
- }
-
- private static final class Reflection {
- public static final Method resolveType, errorNoMethodFor, invalidMethod, getJavaCompletionProposals;
- public static final Throwable problem;
-
- static {
- Method m = null, n = null, o = null, p = null;
- Throwable problem_ = null;
- try {
- m = PatchExtensionMethod.class.getMethod("resolveType", Class.forName(TYPE_BINDING), Class.forName(MESSAGE_SEND), Class.forName(BLOCK_SCOPE));
- n = PatchExtensionMethod.class.getMethod("errorNoMethodFor", Class.forName(PROBLEM_REPORTER),
- Class.forName(MESSAGE_SEND), Class.forName(TYPE_BINDING), Class.forName(TYPE_BINDING_ARRAY));
- o = PatchExtensionMethod.class.getMethod("invalidMethod", Class.forName(PROBLEM_REPORTER), Class.forName(MESSAGE_SEND), Class.forName(METHOD_BINDING));
- p = PatchExtensionMethod.class.getMethod("getJavaCompletionProposals", Class.forName(I_JAVA_COMPLETION_PROPOSAL_ARRAY), Class.forName(COMPLETION_PROPOSAL_COLLECTOR));
- } catch (Throwable t) {
- // That's problematic, but as long as no local classes are used we don't actually need it.
- // Better fail on local classes than crash altogether.
- problem_ = t;
- }
- resolveType = m;
- errorNoMethodFor = n;
- invalidMethod = o;
- getJavaCompletionProposals = p;
- problem = problem_;
- }
- }
-}