Skip to content

Commit

Permalink
Fix for issue #489: widen scope of non-synthetic access matching
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 28, 2018
1 parent 7219059 commit 76cb378
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 76cb378

Please sign in to comment.