aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2023-03-20 21:46:25 +0100
committerRoel Spilker <r.spilker@gmail.com>2023-03-22 22:57:52 +0100
commitafceb138e6e4ca2dca0f16fd5297d7451f5f4e80 (patch)
treeea8d5ddd944809b92f9a9ed857da90c00b521ac7 /src/eclipseAgent
parentd56b576c26d6e6a0621997a9758151cf41e7a74e (diff)
downloadlombok-afceb138e6e4ca2dca0f16fd5297d7451f5f4e80.tar.gz
lombok-afceb138e6e4ca2dca0f16fd5297d7451f5f4e80.tar.bz2
lombok-afceb138e6e4ca2dca0f16fd5297d7451f5f4e80.zip
[fixes #3373] Find references for extension methods
Diffstat (limited to 'src/eclipseAgent')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java7
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java13
-rwxr-xr-xsrc/eclipseAgent/lombok/launch/PatchFixesHider.java6
3 files changed, 26 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index c0bfbe09..aa548af0 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -918,6 +918,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.request(StackRequest.THIS)
.wrapMethod(new Hook(PATCH_EXTENSIONMETHOD_COMPLETIONPROPOSAL_PORTAL, "getJavaCompletionProposals", I_JAVA_COMPLETION_PROPOSAL_SIG, "java.lang.Object[]", "java.lang.Object"))
.build());
+
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapReturnValue()
+ .target(new MethodTarget("org.eclipse.jdt.core.search.SearchPattern", "createPattern", "org.eclipse.jdt.core.search.SearchPattern", "org.eclipse.jdt.core.IJavaElement", "int", "int"))
+ .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD, "modifyMethodPattern", "java.lang.Object", "java.lang.Object"))
+ .cast()
+ .request(StackRequest.RETURN_VALUE)
+ .build());
}
private static void patchNullCheck(ScriptManager sm) {
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
index 7743f9c6..9b2bde60 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
@@ -43,6 +43,7 @@ import lombok.eclipse.handlers.EclipseHandlerUtil;
import lombok.experimental.ExtensionMethod;
import lombok.permit.Permit;
+import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
@@ -66,6 +67,7 @@ import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
+import org.eclipse.jdt.internal.core.search.matching.MethodPattern;
public class PatchExtensionMethod {
static class Extension {
@@ -378,6 +380,17 @@ public class PatchExtensionMethod {
MessageSend_postponedErrors.clear(methodCall);
return resolvedType;
}
+
+ public static SearchPattern modifyMethodPattern(SearchPattern original) {
+ if (original != null && original instanceof MethodPattern) {
+ MethodPattern methodPattern = (MethodPattern) original;
+ if (methodPattern.parameterCount > 0) {
+ methodPattern.varargs = true;
+ }
+ }
+
+ return original;
+ }
private static boolean requiresPolyBinding(Expression argument) {
return Reflection.isFunctionalExpression(argument) || argument instanceof ConditionalExpression && Reflection.isPolyExpression(argument);
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index 5404ee1d..3a8a6b88 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -344,6 +344,7 @@ final class PatchFixesHider {
private static final Method ERROR_NO_METHOD_FOR;
private static final Method INVALID_METHOD, INVALID_METHOD2;
private static final Method NON_STATIC_ACCESS_TO_STATIC_METHOD;
+ private static final Method MODIFY_METHOD_PATTERN;
static {
Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchExtensionMethod");
@@ -352,6 +353,7 @@ final class PatchFixesHider {
INVALID_METHOD = Util.findMethod(shadowed, "invalidMethod", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, METHOD_BINDING_SIG);
INVALID_METHOD2 = Util.findMethod(shadowed, "invalidMethod", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, METHOD_BINDING_SIG, SCOPE_SIG);
NON_STATIC_ACCESS_TO_STATIC_METHOD = Util.findMethod(shadowed, "nonStaticAccessToStaticMethod", PROBLEM_REPORTER_SIG, AST_NODE_SIG, METHOD_BINDING_SIG, MESSAGE_SEND_SIG);
+ MODIFY_METHOD_PATTERN = Util.findMethod(shadowed, "modifyMethodPattern", "org.eclipse.jdt.core.search.SearchPattern");
}
public static Object resolveType(Object resolvedType, Object methodCall, Object scope) {
@@ -373,6 +375,10 @@ final class PatchFixesHider {
public static void nonStaticAccessToStaticMethod(Object problemReporter, Object location, Object method, Object messageSend) {
Util.invokeMethod(NON_STATIC_ACCESS_TO_STATIC_METHOD, problemReporter, location, method, messageSend);
}
+
+ public static Object modifyMethodPattern(Object original) {
+ return Util.invokeMethod(MODIFY_METHOD_PATTERN, original);
+ }
}
/** Contains patch code to support Javadoc for generated methods */