diff --git a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/MethodReferenceSearchRequestor.java b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/MethodReferenceSearchRequestor.java index 2000f0d3f6..c395d96262 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/MethodReferenceSearchRequestor.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/MethodReferenceSearchRequestor.java @@ -27,6 +27,7 @@ import org.codehaus.groovy.ast.ClassHelper; import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.MethodNode; +import org.codehaus.groovy.ast.PropertyNode; import org.codehaus.groovy.ast.expr.StaticMethodCallExpression; import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyTypeDeclaration; import org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode; @@ -204,18 +205,15 @@ public VisitStatus acceptASTNode(ASTNode node, TypeLookupResult result, IJavaEle int start = 0; int end = 0; - if (result.declaration instanceof MethodNode) { - if (methodName.equals(((MethodNode) result.declaration).getName())) { - if (isDeclaration || node instanceof StaticMethodCallExpression) { - start = ((AnnotatedNode) node).getNameStart(); - end = ((AnnotatedNode) node).getNameEnd() + 1; - } else { - String text = node.getText(); // check for non-synthetic match; SyntheticAccessorSearchRequestor matches "foo.bar" to "getBar()" w/o backing field - if (methodName.equals(text) || result.declaringType.getField(text) != null) { - start = node.getStart(); - end = node.getEnd(); - } - } + if (result.declaration instanceof MethodNode && ((MethodNode) result.declaration).getName().equals(methodName)) { + if (isDeclaration || node instanceof StaticMethodCallExpression) { + start = ((AnnotatedNode) node).getNameStart(); + end = ((AnnotatedNode) node).getNameEnd() + 1; + + // check for non-synthetic match; SyntheticAccessorSearchRequestor matches "foo.bar" to "getBar()" w/o backing field + } else if (node.getText().equals(methodName) || isNotSynthetic(node.getText(), result.declaringType)) { + start = node.getStart(); + end = node.getEnd(); } } @@ -395,6 +393,17 @@ private static boolean supportsOverride(IMethod method) throws JavaModelExceptio return !(Flags.isPrivate(flags) || Flags.isStatic(flags)); } + private static boolean isNotSynthetic(String name, ClassNode type) { + if (type.getField(name) != null) { + return true; + } + PropertyNode prop = type.getProperty(name); + if (prop != null && !prop.isSynthetic()) { + return true; + } + return false; + } + private static boolean equal(char[] arr, CharSequence seq) { if (arr.length != seq.length()) { return false;