From afcb211e47f387c5c9b42a0d954e247aec84e781 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 13 Aug 2012 02:45:58 +0200 Subject: Fix for issue 401: test(), Object.test(), and super.test() were all allowed in eclipse for @ExtensionMethod, resulting in VerifyErrors in the emitted class files. --- .../lombok/eclipse/agent/PatchExtensionMethod.java | 13 ++++++++++++- .../agent/PatchExtensionMethodCompletionProposal.java | 14 +++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src/eclipseAgent/lombok') diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java index b96f70c9..008e722a 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java @@ -48,8 +48,10 @@ import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.NameReference; import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.SuperReference; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; @@ -201,7 +203,16 @@ public class PatchExtensionMethod { } } - for (Extension extension : extensions) { + boolean skip = false; + + if (methodCall.receiver instanceof ThisReference && (((ThisReference)methodCall.receiver).bits & ASTNode.IsImplicitThis) != 0) skip = true; + if (methodCall.receiver instanceof SuperReference) skip = true; + if (methodCall.receiver instanceof NameReference) { + Binding binding = ((NameReference)methodCall.receiver).binding; + if (binding instanceof TypeBinding) skip = true; + } + + if (!skip) for (Extension extension : extensions) { if (!extension.suppressBaseMethods && !(methodCall.binding instanceof ProblemMethodBinding)) continue; for (MethodBinding extensionMethod : extension.extensionMethods) { if (!Arrays.equals(methodCall.selector, extensionMethod.selector)) continue; diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java index 701a2029..97ca5a7e 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java @@ -45,7 +45,7 @@ import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.FieldReference; import org.eclipse.jdt.internal.compiler.ast.NameReference; -import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.SuperReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -103,14 +103,18 @@ public class PatchExtensionMethodCompletionProposal { if (node == null) return null; if (!(node instanceof CompletionOnQualifiedNameReference) && !(node instanceof CompletionOnSingleNameReference) && !(node instanceof CompletionOnMemberAccess)) return null; + // Never offer on 'super.'. + if (node instanceof FieldReference && ((FieldReference)node).receiver instanceof SuperReference) return null; + if (node instanceof NameReference) { Binding binding = ((NameReference) node).binding; - if ((node instanceof SingleNameReference) && (((SingleNameReference) node).token.length == 0)) { + // Unremark next block to allow a 'blank' autocomplete to list any extensions that apply to the current scope, but make sure we're not in a static context first, which this doesn't do. + // Lacking good use cases, and having this particular concept be a little tricky on javac, means for now we don't support extension methods like this. this.X() will be fine, though. + +/* if ((node instanceof SingleNameReference) && (((SingleNameReference) node).token.length == 0)) { firstParameterType = decl.binding; - } else if (binding instanceof VariableBinding) { + } else */if (binding instanceof VariableBinding) { firstParameterType = ((VariableBinding) binding).type; - } else if (binding instanceof TypeBinding) { - firstParameterType = (TypeBinding) binding; } } else if (node instanceof FieldReference) { firstParameterType = ((FieldReference) node).actualReceiverType; -- cgit