From 3284db533f178f38e4d9e611506c550a0fb971f5 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Fri, 26 Apr 2019 12:00:25 -0500 Subject: [PATCH] Fix for #875: add test for final property --- .../test/ui/SemanticHighlightingTests.groovy | 31 ++++++++++++++++++- .../SemanticReferenceRequestor.java | 5 ++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy index a5f4fa11f5..4f3e15be81 100644 --- a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -132,6 +132,35 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite { new HighlightedTypedPosition(contents.lastIndexOf('PI'), 2, STATIC_VALUE)) } + @Test + void testStaticFinals3() { + String contents = '''\ + class C { + static final VALUE = 'value' + static foo() { + VALUE + } + static class Inner { + void bar() { + VALUE + } + } + } + class SamePack { + def baz = C.VALUE + } + '''.stripIndent() + + assertHighlighting(contents, + new HighlightedTypedPosition(contents.indexOf('VALUE'), 5, STATIC_VALUE), + new HighlightedTypedPosition(contents.indexOf('foo'), 3, STATIC_METHOD), + new HighlightedTypedPosition(contents.indexOf('VALUE', contents.indexOf('foo')), 5, STATIC_VALUE), + new HighlightedTypedPosition(contents.indexOf('bar'), 3, METHOD), + new HighlightedTypedPosition(contents.indexOf('VALUE', contents.indexOf('bar')), 5, STATIC_VALUE), + new HighlightedTypedPosition(contents.indexOf('baz'), 3, FIELD), + new HighlightedTypedPosition(contents.indexOf('VALUE', contents.indexOf('baz')), 5, STATIC_VALUE)) + } + @Test void testMethods() { String contents = '''\ diff --git a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/SemanticReferenceRequestor.java b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/SemanticReferenceRequestor.java index a5779d1182..38826d5ae1 100644 --- a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/SemanticReferenceRequestor.java +++ b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/SemanticReferenceRequestor.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -68,6 +68,9 @@ protected static boolean isFinal(ASTNode node) { if (node instanceof MethodNode) { return ((MethodNode) node).isFinal(); } + if (node instanceof PropertyNode) { + return ((PropertyNode) node).getField().isFinal(); + } return false; }