Skip to content

Commit

Permalink
Fix for #1497: source range for closure literal
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 6, 2023
1 parent 126c301 commit 6667ced
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,10 @@ private org.eclipse.jdt.internal.compiler.ast.Expression createAnnotationMemberE

} else if (expr instanceof ClosureExpression) {
// annotation is something like "@Tag(value = { -> ... })"
return new ClassLiteralAccess(expr.getStart() - 1, new Wildcard(Wildcard.UNBOUND));
TypeReference stub = new Wildcard(Wildcard.UNBOUND);
stub.sourceStart = expr.getStart();
stub.sourceEnd = expr.getEnd() - 1;
return new ClassLiteralAccess(stub.sourceEnd, stub);

} else if (expr instanceof BinaryExpression) {
BinaryExpression be = (BinaryExpression) expr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
*/
package org.codehaus.groovy.eclipse.codebrowsing.tests

import static org.eclipse.jdt.groovy.core.util.JavaConstants.AST_LEVEL

import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.FieldNode
import org.codehaus.groovy.ast.MethodNode
import org.eclipse.jdt.core.IJavaElement
import org.eclipse.jdt.core.dom.*
import org.junit.Test

final class CodeSelectAttributesTests extends BrowsingTestSuite {
Expand Down Expand Up @@ -273,5 +276,32 @@ final class CodeSelectAttributesTests extends BrowsingTestSuite {
assert inferredElement instanceof MethodNode
assert inferredElement.declaringClass.name == 'org.codehaus.groovy.ast.ASTNode'
}

def unit = addGroovySource(source, nextUnitName())
unit = unit.reconcile(AST_LEVEL, true, null, null)
def elem = NodeFinder.perform(unit, source.indexOf('node'), 4)
assert elem instanceof Block
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1497
void testCodeSelectOnAttributeValue11() {
String source = '''\
|class C {
| @groovy.transform.ASTTest({
| node
| })
| void m() {
| }
|}
|'''.stripMargin()

assertCodeSelect([source], 'node').with {
assert elementType == IJavaElement.LOCAL_VARIABLE
}

def unit = addGroovySource(source, nextUnitName())
unit = unit.reconcile(AST_LEVEL, true, null, null)
def elem = NodeFinder.perform(unit, source.indexOf('node'), 4)
assert !(elem instanceof Annotation) : 'expect closure placeholder'
}
}

0 comments on commit 6667ced

Please sign in to comment.