Skip to content

Commit

Permalink
Fix for #875: add test for final property
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 26, 2019
1 parent c9173d3 commit 3284db5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = '''\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 3284db5

Please sign in to comment.