diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ConstantExpressionTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ConstantExpressionTest.java index e33c4c67b890..36ba3d3874ee 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ConstantExpressionTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ConstantExpressionTest.java @@ -1,61 +1,66 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package org.jetbrains.plugins.groovy.lang.resolve +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy.lang.resolve; -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic -import org.jetbrains.plugins.groovy.GroovyProjectDescriptors -import org.jetbrains.plugins.groovy.LightGroovyTestCase +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiClass; +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.UsefulTestCase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.GroovyProjectDescriptors; +import org.jetbrains.plugins.groovy.LightGroovyTestCase; +import org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtil; +import org.jetbrains.plugins.groovy.util.TestUtils; -import static org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtil.getStringArrayValue -import static org.jetbrains.plugins.groovy.util.TestUtils.disableAstLoading - -@CompileStatic -class ConstantExpressionTest extends LightGroovyTestCase { - - final LightProjectDescriptor projectDescriptor = GroovyProjectDescriptors.GROOVY_LATEST +import java.util.List; +public class ConstantExpressionTest extends LightGroovyTestCase { private void addJavaAnnotation() { - fixture.addClass '''\ -package com.foo; - -public @interface MyJavaAnnotation { - String[] stringArrayValue() default {}; - String stringValue() default "default string"; -} -''' + getFixture().addClass(""" + package com.foo; + + public @interface MyJavaAnnotation { + String[] stringArrayValue() default {}; + String stringValue() default "default string"; + } + """); } private void addJavaConstants() { - fixture.addClass '''\ -package com.foo; - -public interface Constants { - String HELLO = "java hello"; - String WORLD = "java world"; - String COMPOUND = HELLO + " " + WORLD; -} -''' + getFixture().addClass(""" + package com.foo; + public interface Constants { + String HELLO = "java hello"; + String WORLD = "java world"; + String COMPOUND = HELLO + " " + WORLD; + } + """); } - void 'test annotation value from java'() { - addJavaAnnotation() - addJavaConstants() - fixture.addFileToProject '_.groovy', '''\ -import com.foo.Constants -import com.foo.MyJavaAnnotation + public void test_annotation_value_from_java() { + addJavaAnnotation(); + addJavaConstants(); + getFixture().addFileToProject("_.groovy", """ + import com.foo.Constants + import com.foo.MyJavaAnnotation + + @MyJavaAnnotation(stringArrayValue = [ + Constants.HELLO, + Constants.WORLD, + Constants.COMPOUND, + "literal" + ]) + class GroovyClass {} + """); + TestUtils.disableAstLoading(getProject(), getTestRootDisposable()); + PsiClass clazz = getFixture().findClass("GroovyClass"); + PsiAnnotation annotation = clazz.getModifierList().findAnnotation("com.foo.MyJavaAnnotation"); + List values = GrAnnotationUtil.getStringArrayValue(annotation, "stringArrayValue", false); + UsefulTestCase.assertOrderedEquals(List.of("java hello", "java world", "java hello java world", "literal"), + values); + } -@MyJavaAnnotation(stringArrayValue = [ - Constants.HELLO, - Constants.WORLD, - Constants.COMPOUND, - "literal" -]) -class GroovyClass {} -''' - disableAstLoading project, testRootDisposable - def clazz = fixture.findClass 'GroovyClass' - def annotation = clazz.modifierList.findAnnotation 'com.foo.MyJavaAnnotation' - def values = getStringArrayValue annotation, 'stringArrayValue', false - assertOrderedEquals(["java hello", "java world", "java hello java world", "literal"], values) + @Override + public final @NotNull LightProjectDescriptor getProjectDescriptor() { + return GroovyProjectDescriptors.GROOVY_LATEST; } }