|
1 | 1 | /* |
2 | | - * Copyright (C) 2012-2021 The Project Lombok Authors. |
| 2 | + * Copyright (C) 2012-2025 The Project Lombok Authors. |
3 | 3 | * |
4 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
|
27 | 27 | import static lombok.javac.handlers.JavacResolver.*; |
28 | 28 |
|
29 | 29 | import java.util.ArrayList; |
| 30 | +import java.util.HashSet; |
30 | 31 | import java.util.List; |
31 | 32 | import java.util.Map; |
| 33 | +import java.util.Set; |
32 | 34 |
|
33 | 35 | import javax.lang.model.element.ElementKind; |
34 | 36 |
|
@@ -139,11 +141,18 @@ private static class ExtensionMethodReplaceVisitor extends TreeScanner<Void, Voi |
139 | 141 | final JavacNode annotationNode; |
140 | 142 | final List<Extension> extensions; |
141 | 143 | final boolean suppressBaseMethods; |
| 144 | + final Set<String> names = new HashSet<String>(); |
142 | 145 |
|
143 | 146 | public ExtensionMethodReplaceVisitor(JavacNode annotationNode, List<Extension> extensions, boolean suppressBaseMethods) { |
144 | 147 | this.annotationNode = annotationNode; |
145 | 148 | this.extensions = extensions; |
146 | 149 | this.suppressBaseMethods = suppressBaseMethods; |
| 150 | + |
| 151 | + for (Extension extension : extensions) { |
| 152 | + for (MethodSymbol methodSymbol : extension.extensionMethods) { |
| 153 | + names.add(methodSymbol.name.toString()); |
| 154 | + } |
| 155 | + } |
147 | 156 | } |
148 | 157 |
|
149 | 158 | public void replace() { |
@@ -173,6 +182,7 @@ private void handleMethodCall(final JCMethodInvocation methodCall) { |
173 | 182 | JCExpression receiver = receiverOf(methodCall); |
174 | 183 | String methodName = methodNameOf(methodCall); |
175 | 184 |
|
| 185 | + if (!names.contains(methodName)) return; |
176 | 186 | if ("this".equals(receiver.toString()) || "this".equals(methodName) || "super".equals(methodName)) return; |
177 | 187 | Map<JCTree, JCTree> resolution = new JavacResolution(methodCallNode.getContext()).resolveMethodMember(methodCallNode); |
178 | 188 |
|
|
0 commit comments