[Groovy] convert TargetAnnotationHighlightingTest to Java (IDEA-327339)

GitOrigin-RevId: 66d1ca2a5e4d42e2378b61a873cc617f7753b8ec
This commit is contained in:
Bas Leijdekkers
2024-04-11 09:51:44 +00:00
committed by intellij-monorepo-bot
parent 61335bf12a
commit 0fdcdeb6ad
@@ -1,146 +1,137 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.lang
// 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;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
/**
* @author Max Medvedev
*/
class TargetAnnotationHighlightingTest extends LightJavaCodeInsightFixtureTestCase {
final LightProjectDescriptor projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR
public class TargetAnnotationHighlightingTest extends LightJavaCodeInsightFixtureTestCase {
private void addElementType() {
myFixture.addClass('''\
package java.lang.annotation;
myFixture.addClass("""
package java.lang.annotation;
public enum ElementType {
/** Class, interface (including annotation type), or enum declaration */
TYPE,
public enum ElementType {
/** Class, interface (including annotation type), or enum declaration */
TYPE,
/** Field declaration (includes enum constants) */
FIELD,
/** Field declaration (includes enum constants) */
FIELD,
/** Method declaration */
METHOD,
/** Method declaration */
METHOD,
/** Parameter declaration */
PARAMETER,
/** Parameter declaration */
PARAMETER,
/** Constructor declaration */
CONSTRUCTOR,
/** Constructor declaration */
CONSTRUCTOR,
/** Local variable declaration */
LOCAL_VARIABLE,
/** Local variable declaration */
LOCAL_VARIABLE,
/** Annotation type declaration */
ANNOTATION_TYPE,
/** Annotation type declaration */
ANNOTATION_TYPE,
/** Package declaration */
PACKAGE
}
''')
/** Package declaration */
PACKAGE
}
""");
}
private void addTarget() {
myFixture.addClass('''\
package java.lang.annotation;
myFixture.addClass("""
package java.lang.annotation;
public @interface Target {
ElementType[] value();
}
''')
public @interface Target {
ElementType[] value();
}
""");
}
void testTargetAnnotationInsideGroovy1() {
addElementType()
addTarget()
myFixture.addFileToProject('Ann.groovy', '''
import java.lang.annotation.Target
public void testTargetAnnotationInsideGroovy1() {
addElementType();
addTarget();
myFixture.addFileToProject("Ann.groovy", """
import java.lang.annotation.Target
import static java.lang.annotation.ElementType.*
import static java.lang.annotation.ElementType.*
@Target(FIELD)
@interface Ann {}
''')
@Target(FIELD)
@interface Ann {}
""");
myFixture.configureByText('_.groovy', '''\
@<error descr="'@Ann' not applicable to type">Ann</error>
class C {
@Ann
def foo
myFixture.configureByText("_.groovy", """
@<error descr="'@Ann' not applicable to type">Ann</error>
class C {
@Ann
def foo
def ar() {
@<error descr="'@Ann' not applicable to local variable">Ann</error>
def x
}
}''')
def ar() {
@<error descr="'@Ann' not applicable to local variable">Ann</error>
def x
}
}""");
myFixture.testHighlighting(true, false, false)
myFixture.testHighlighting(true, false, false);
}
void testTargetAnnotationInsideGroovy2() {
addElementType()
addTarget()
myFixture.addFileToProject('Ann.groovy', '''
import java.lang.annotation.Target
public void testTargetAnnotationInsideGroovy2() {
addElementType();
addTarget();
myFixture.addFileToProject("Ann.groovy", """
import java.lang.annotation.Target
import static java.lang.annotation.ElementType.*
import static java.lang.annotation.ElementType.*
@Target(value=[FIELD, TYPE])
@interface Ann {}
''')
@Target(value=[FIELD, TYPE])
@interface Ann {}
""");
myFixture.configureByText('_.groovy', '''\
@Ann
class C {
@Ann
def foo
myFixture.configureByText("_.groovy", """
@Ann
class C {
@Ann
def foo
def ar() {
@<error descr="'@Ann' not applicable to local variable">Ann</error>
def x
}
}''')
myFixture.testHighlighting(true, false, false)
def ar() {
@<error descr="'@Ann' not applicable to local variable">Ann</error>
def x
}
}""");
myFixture.testHighlighting(true, false, false);
}
void testTargetAnnotationInsideGroovy3() {
addElementType()
addTarget()
myFixture.addFileToProject('Ann.groovy', '''
import java.lang.annotation.Target
public void testTargetAnnotationInsideGroovy3() {
addElementType();
addTarget();
myFixture.addFileToProject("Ann.groovy", """
import java.lang.annotation.Target
import static java.lang.annotation.ElementType.*
import static java.lang.annotation.ElementType.*
@Target(LOCAL_VARIABLE)
@interface Ann {}
''')
@Target(LOCAL_VARIABLE)
@interface Ann {}
""");
myFixture.configureByText('_.groovy', '''\
@<error descr="'@Ann' not applicable to type">Ann</error>
class C {
@<error descr="'@Ann' not applicable to field">Ann</error>
def foo
myFixture.configureByText("_.groovy", """
@<error descr="'@Ann' not applicable to type">Ann</error>
class C {
@<error descr="'@Ann' not applicable to field">Ann</error>
def foo
def ar() {
@Ann
def x
def ar() {
@Ann
def x
}
}""");
myFixture.testHighlighting(true, false, false);
}
}''')
myFixture.testHighlighting(true, false, false)
@Override
public final @NotNull LightProjectDescriptor getProjectDescriptor() {
return LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR;
}
}