From b869181ae2e39b72b6e0fee82651513cdef9beee Mon Sep 17 00:00:00 2001 From: Oleg Rekutin Date: Mon, 13 May 2019 15:40:30 -0400 Subject: [PATCH] add support for annotations with primitive boolean values this allows handling of annotations such as TestNG's @BeforeMethod(alwaysRun = true) --- .../groovy/internal/compiler/ast/JDTAnnotationNode.java | 4 ++++ .../eclipse/dsl/tests/PointcutEvaluationTests.groovy | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java index 75131aae24..a017dbe1b6 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java @@ -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; @@ -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; @@ -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)); } diff --git a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/PointcutEvaluationTests.groovy b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/PointcutEvaluationTests.groovy index 0fdc0898ae..1e4fb3a916 100644 --- a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/PointcutEvaluationTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/PointcutEvaluationTests.groovy @@ -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')