Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support boolean value annotations #887

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.codehaus.groovy.ast.expr.ListExpression;
import org.codehaus.groovy.ast.expr.PropertyExpression;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.impl.BooleanConstant;
import org.eclipse.jdt.internal.compiler.impl.IntConstant;
import org.eclipse.jdt.internal.compiler.impl.StringConstant;
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
Expand All @@ -42,6 +43,7 @@ public class JDTAnnotationNode extends AnnotationNode {

private static final char[] jlString = "Ljava/lang/String;".toCharArray();
private static final char[] baseInt = "I".toCharArray();
private static final char[] baseBoolean = "Z".toCharArray();

private boolean membersInitialized = false;
private AnnotationBinding annotationBinding;
Expand Down Expand Up @@ -153,6 +155,8 @@ private Expression createExpressionFor(TypeBinding b, Object value) {
char[] sig = b.signature();
if (CharOperation.equals(sig, baseInt)) {
return new ConstantExpression(((IntConstant) value).intValue());
} else if (CharOperation.equals(sig, baseBoolean)) {
return new ConstantExpression(((BooleanConstant) value).booleanValue());
} else {
throw new GroovyEclipseBug("NYI for signature " + String.valueOf(sig));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
doTestOfLastMatch('foo.Bar', 'currentType(annotatedBy("a.Tag"))', 'foo.Bar')
}

@Test
void testAnnotatedBy9b() {
addGroovySource('@interface Tag { boolean value(); }', 'Tag', 'a')
addGroovySource('@interface Tags { Tag[] value(); }', 'Tags', 'a')
addGroovySource('import a.*; @Tags(@Tag(true)) class Bar { def baz() {} }', 'Bar', 'foo')
doTestOfLastMatch('foo.Bar', 'currentType(annotatedBy("a.Tag"))', 'foo.Bar')
}

@Test
void testFileExtension1() {
doTestOfLastMatch('2', 'fileExtension("groovy")', 'src/p/TestUnit\\d+.groovy')
Expand Down