diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2020-08-20 09:53:18 +0200 |
---|---|---|
committer | Rawi01 <Rawi01@users.noreply.github.com> | 2020-08-20 09:53:18 +0200 |
commit | 75b7a88a45f08dda24bb8dfe466acee0b10f3b40 (patch) | |
tree | eb9ce917345afe6bf37b9985ca19dd23de92f3dd /src/core/lombok/javac/handlers | |
parent | 4d2ae4ba3261ab2963c13649b3ba8f4b3881e9c3 (diff) | |
download | lombok-75b7a88a45f08dda24bb8dfe466acee0b10f3b40.tar.gz lombok-75b7a88a45f08dda24bb8dfe466acee0b10f3b40.tar.bz2 lombok-75b7a88a45f08dda24bb8dfe466acee0b10f3b40.zip |
[fixes #2261] Detect static method access properly
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleExtensionMethod.java | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleExtensionMethod.java b/src/core/lombok/javac/handlers/HandleExtensionMethod.java index 345c5f8e..805a96f8 100644 --- a/src/core/lombok/javac/handlers/HandleExtensionMethod.java +++ b/src/core/lombok/javac/handlers/HandleExtensionMethod.java @@ -28,6 +28,7 @@ import static lombok.javac.handlers.JavacResolver.*; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.lang.model.element.ElementKind; @@ -37,12 +38,14 @@ import lombok.core.HandlerPriority; import lombok.experimental.ExtensionMethod; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.javac.JavacResolution; import org.mangosdk.spi.ProviderFor; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.util.TreeScanner; import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Type; @@ -51,6 +54,7 @@ import com.sun.tools.javac.code.Type.ErrorType; import com.sun.tools.javac.code.Type.ForAll; import com.sun.tools.javac.code.Type.MethodType; import com.sun.tools.javac.code.Types; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCExpression; @@ -166,13 +170,25 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho JCExpression receiver = receiverOf(methodCall); String methodName = methodNameOf(methodCall); - if ("this".equals(methodName) || "super".equals(methodName)) return; - Type resolvedMethodCall = CLASS_AND_METHOD.resolveMember(methodCallNode, methodCall); - if (resolvedMethodCall == null) return; - if (!suppressBaseMethods && !(resolvedMethodCall instanceof ErrorType)) return; - Type receiverType = CLASS_AND_METHOD.resolveMember(methodCallNode, receiver); - if (receiverType == null) return; - if (receiverType.tsym.toString().endsWith(receiver.toString())) return; + if ("this".equals(receiver.toString()) || "this".equals(methodName) || "super".equals(methodName)) return; + Map<JCTree, JCTree> resolution = new JavacResolution(methodCallNode.getContext()).resolveMethodMember(methodCallNode); + + JCTree resolvedMethodCall = resolution.get(methodCall); + if (resolvedMethodCall == null || resolvedMethodCall.type == null) return; + if (!suppressBaseMethods && !(resolvedMethodCall.type instanceof ErrorType)) return; + + JCTree resolvedReceiver = resolution.get(receiver); + if (resolvedReceiver == null || resolvedReceiver.type == null) return; + Type receiverType = resolvedReceiver.type; + + // Skip static method access + Symbol sym = null; + if (resolvedReceiver instanceof JCIdent) { + sym = ((JCIdent) resolvedReceiver).sym; + } else if (resolvedReceiver instanceof JCFieldAccess) { + sym = ((JCFieldAccess) resolvedReceiver).sym; + } + if (sym instanceof ClassSymbol) return; Types types = Types.instance(annotationNode.getContext()); for (Extension extension : extensions) { |