IDEA-196862 - added meta annotations processing

GitOrigin-RevId: c9cc025971ab76606d5d670efe9a472b3c9bd067
This commit is contained in:
Ilyas Selimov
2021-03-10 19:48:39 +00:00
committed by intellij-monorepo-bot
parent 5575a15b95
commit 173a2a03e1
4 changed files with 74 additions and 8 deletions
@@ -506,9 +506,14 @@ public abstract class EntryPointsManagerBase extends EntryPointsManager implemen
}
}
}
return AnnotationUtil.checkAnnotatedUsingPatterns(owner, ADDITIONAL_ANNOTATIONS) ||
AnnotationUtil.checkAnnotatedUsingPatterns(owner, getAdditionalAnnotations());
boolean annotationsMatch = AnnotationUtil.checkAnnotatedUsingPatterns(owner, ADDITIONAL_ANNOTATIONS) ||
AnnotationUtil.checkAnnotatedUsingPatterns(owner, getAdditionalAnnotations());
if (annotationsMatch) return true;
for (PsiAnnotation annotation : owner.getAnnotations()) {
PsiClass annClass = annotation.resolveAnnotationType();
if (AnnotationUtil.checkAnnotatedUsingPatterns(annClass, ADDITIONAL_ANNOTATIONS)) return true;
}
return false;
}
private static boolean isAcceptedByPattern(@NotNull PsiClass element, String qualifiedName, ClassPattern pattern, Set<? super PsiClass> visited) {
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problems>
<problem>
<file>MetaAnnotation.java</file>
<line>50</line>
<description>Class is not instantiated.</description>
</problem>
</problems>
@@ -0,0 +1,55 @@
import java.lang.annotation.*;
// definition
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestMapping {
@SuppressWarnings("unused") // suppress warning as we test another thing
RequestMethod[] method() default {};
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = RequestMethod.GET)
@interface GetMapping {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = RequestMethod.POST)
@interface PostMapping {
}
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface Ann1 {
}
enum RequestMethod {
GET, POST
}
// test
class Controller {
@GetMapping
public int get() {
return 111;
}
@PostMapping
public void post() {
}
}
@Ann1
class A {
}
@RequestMapping
class B {
}
@@ -5,6 +5,8 @@ import com.intellij.codeInspection.ex.EntryPointsManagerBase;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.IdeaTestUtil;
import java.util.List;
public class UnusedDeclarationTest extends AbstractUnusedDeclarationTest {
public void testSCR6067() {
@@ -97,13 +99,13 @@ public class UnusedDeclarationTest extends AbstractUnusedDeclarationTest {
}
public void testAdditionalAnnotations() {
final String testAnnotation = "Annotated";
EntryPointsManagerBase.getInstance(getProject()).ADDITIONAL_ANNOTATIONS.add(testAnnotation);
final List<String> testAnnotations = List.of("Annotated", "RequestMapping");
EntryPointsManagerBase.getInstance(getProject()).ADDITIONAL_ANNOTATIONS.addAll(testAnnotations);
try {
doTest();
}
finally {
EntryPointsManagerBase.getInstance(getProject()).ADDITIONAL_ANNOTATIONS.remove(testAnnotation);
EntryPointsManagerBase.getInstance(getProject()).ADDITIONAL_ANNOTATIONS.removeAll(testAnnotations);
}
}