Skip to content

Commit

Permalink
Fix for #1117: mark ConstantExpression that infers as VariableExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 24, 2020
1 parent fba9d61 commit 3d5a7e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,31 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
new HighlightedTypedPosition(contents.indexOf('k;'), 1, VARIABLE))
}

@Test
void testScriptVariable1() {
String contents = '''\
|abc = null
|def xyz = abc
|'''.stripMargin()

assertHighlighting(contents,
new HighlightedTypedPosition(contents.indexOf('abc'), 3, VARIABLE),
new HighlightedTypedPosition(contents.indexOf('xyz'), 3, VARIABLE),
new HighlightedTypedPosition(contents.lastIndexOf('abc'), 3, VARIABLE))
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1117
void testScriptVariable2() {
String contents = '''\
|block = { -> }
|block()
|'''.stripMargin()

assertHighlighting(contents,
new HighlightedTypedPosition(contents.indexOf('block'), 5, VARIABLE),
new HighlightedTypedPosition(contents.lastIndexOf('block'), 5, VARIABLE))
}

@Test
void testParamsAndLocals() {
String contents = '''\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ public VisitStatus acceptASTNode(ASTNode node, TypeLookupResult result, IJavaEle
}
} else if (node instanceof ConstantExpression) {
if (result.declaration instanceof MethodNode) {
pos = handleMethodReference((Expression) node, result, (enclosingElement instanceof ImportDeclaration));
boolean isStaticImport = enclosingElement instanceof ImportDeclaration;
pos = handleMethodReference((Expression) node, result, isStaticImport);
} else if (result.declaration instanceof VariableExpression) {
pos = new HighlightedTypedPosition(node.getStart(), node.getLength(), HighlightKind.VARIABLE);
} else {
pos = handleConstantExpression((ConstantExpression) node);
try { // check for regular expression with inline comments
Expand Down

0 comments on commit 3d5a7e1

Please sign in to comment.