diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java index 46802d5c2c..84ea57b2c7 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java @@ -889,6 +889,16 @@ public void testNotMapProperty() { assertType(contents, "value", "java.lang.Number"); } + @Test // GROOVY-5001 + public void testNotMapProperty2() { + String contents = + "class Pogo extends HashMap {\n" + + " public Number name\n" + + "}\n" + + "new Pogo().name\n"; + assertType(contents, "name", isAtLeastGroovy(50) ? "java.lang.Number" : "java.lang.String"); + } + @Test public void testBoolean1() { assertType("!x", "java.lang.Boolean"); diff --git a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java index 998000069d..3d84580af5 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java @@ -710,12 +710,14 @@ protected ASTNode findDeclaration(final String name, final ClassNode declaringTy // look for field FieldNode field = declaringType.getField(name); - if (isCompatible(field, isStaticExpression) && - !(Flags.isSynthetic(field.getModifiers()) && field.getType().equals(ClassHelper.REFERENCE_TYPE)) && - // no indirect, non-private accessor (map get or put if no non-final public/protected field exists) - (!(nonPrivateAccessor || (dynamicProperty && !(isLhsExpression && !field.isFinal() && (field.isPublic()||field.isProtected())))) || - directFieldAccess >= 1 && declaringType.equals(field.getDeclaringClass()) && (directFieldAccess == 1 || !field.isPrivate()))) { - return field; + if (isCompatible(field, isStaticExpression) && !(Flags.isSynthetic(field.getModifiers()) && field.getType().equals(ClassHelper.REFERENCE_TYPE))) { + boolean direct = directFieldAccess >= 1 && declaringType.equals(field.getDeclaringClass()) && (directFieldAccess == 1 || !field.isPrivate()); + boolean expose = isLhsExpression // GROOVY-11367: get and set incongruent + ? (!field.isFinal() && (field.isPublic() || field.isProtected())) // GROOVY-8065 + : (field.isPublic() && GroovyUtils.getGroovyVersion().getMajor() >= 5); // GROOVY-5001 + if (direct || !(nonPrivateAccessor || (dynamicProperty && !expose))) { + return field; + } } if (dynamicProperty && !(nonPrivateAccessor && (isLhsExpression || GroovyUtils.getGroovyVersion().getMajor() >= 5))) { // GROOVY-5001, GROOVY-5491