Search in sources :

Example 26 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project qi4j-sdk by Qi4j.

the class MixinsAnnotationDeclaredOnMixinType method checkClass.

@Override
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    PsiAnnotation mixinsAnnotation = getMixinsAnnotation(psiClass);
    if (mixinsAnnotation == null) {
        return null;
    }
    if (psiClass.isInterface()) {
        return null;
    }
    String message = message("mixins.annotation.declared.on.mixin.type.error.declared.on.class");
    RemoveInvalidMixinClassReferenceFix fix = new RemoveInvalidMixinClassReferenceFix(mixinsAnnotation);
    ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(mixinsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
    return new ProblemDescriptor[] { problemDescriptor };
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 27 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project qi4j-sdk by Qi4j.

the class ConcernsAnnotationDeclaredCorrectlyInspection method checkClass.

@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    // If class does not have @Concerns, ignore
    PsiAnnotation concernsAnnotation = getConcernsAnnotation(psiClass);
    if (concernsAnnotation == null) {
        return null;
    }
    // If @Concerns declared in class, suggest remove @Concerns annotation
    if (!psiClass.isInterface()) {
        String message = message("concerns.annotation.declared.correctly.error.annotation.declared.in.class");
        RemoveConcernsAnnotationFix fix = new RemoveConcernsAnnotationFix(concernsAnnotation);
        ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(concernsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
        return new ProblemDescriptor[] { problemDescriptor };
    }
    // If @Concerns annotation is empty, ignore
    List<PsiAnnotationMemberValue> concernsAnnotationValue = getConcernsAnnotationValue(concernsAnnotation);
    if (concernsAnnotationValue.isEmpty()) {
        return null;
    }
    // If ConcernOfClass is not resolved, ignore
    Project project = psiClass.getProject();
    GlobalSearchScope searchScope = determineSearchScope(psiClass);
    PsiClass concernOfClass = getConcernOfClass(project, searchScope);
    if (concernOfClass == null) {
        return null;
    }
    List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
    for (PsiAnnotationMemberValue concernClassAnnotationValue : concernsAnnotationValue) {
        PsiJavaCodeReferenceElement concernClassReference = getConcernClassReference(concernClassAnnotationValue);
        // If it's not a class reference, ignore
        if (concernClassReference == null) {
            continue;
        }
        // If class reference can't be resolved, ignore
        PsiClass concernClass = (PsiClass) concernClassReference.resolve();
        if (concernClass == null) {
            continue;
        }
        // If concern class does not inherit concern class, suggest remove that reference.
        if (!concernClass.isInheritor(concernOfClass, true)) {
            String message = Qi4jResourceBundle.message("concerns.annotation.declared.correctly.error.concern.class.does.not.extend.ConcernOf", concernClass.getQualifiedName());
            RemoveInvalidConcernClassReferenceFix fix = new RemoveInvalidConcernClassReferenceFix(concernClassAnnotationValue, concernClassReference);
            ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(concernClassAnnotationValue, message, fix, GENERIC_ERROR_OR_WARNING);
            problems.add(problemDescriptor);
        } else {
        // TODO: Test whether it is a generic concern
        // TODO: Test whether it is a specific concern
        }
    }
    return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) LinkedList(java.util.LinkedList) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiAnnotationMemberValue(com.intellij.psi.PsiAnnotationMemberValue)

Example 28 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project qi4j-sdk by Qi4j.

the class AbstractInjectionAnnotationDeclarationOnFieldInspection method checkField.

@Override
public final ProblemDescriptor[] checkField(@NotNull PsiField field, @NotNull InspectionManager manager, boolean isOnTheFly) {
    PsiAnnotation annotationToCheck = getAnnotationToCheck(field);
    if (annotationToCheck == null) {
        return null;
    }
    PsiModifierList modifierList = field.getModifierList();
    if (modifierList != null) {
        if (modifierList.hasModifierProperty(com.intellij.psi.PsiModifier.STATIC)) {
            String message = getInjectionAnnotationValidDeclarationMessage();
            AbstractFix removeAnnotationFix = createRemoveAnnotationFix(annotationToCheck);
            ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(annotationToCheck, message, removeAnnotationFix, com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            return new ProblemDescriptor[] { problemDescriptor };
        }
    }
    return verifyAnnotationDeclaredCorrectly(field, annotationToCheck, manager);
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) AbstractFix(org.qi4j.ide.plugin.idea.common.inspections.AbstractFix) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 29 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project Intellij-Plugin by getgauge.

the class HookUtilTest method TestIsHookWhenNonHookAnnotation.

@Test
public void TestIsHookWhenNonHookAnnotation() throws Exception {
    PsiMethod method = mock(PsiMethod.class);
    PsiModifierList list = mock(PsiModifierList.class);
    PsiAnnotation annotation = mock(PsiAnnotation.class);
    when(annotation.getQualifiedName()).thenReturn("Unequal");
    when(list.getAnnotations()).thenReturn(new PsiAnnotation[] { annotation });
    when(method.getModifierList()).thenReturn(list);
    assertFalse(HookUtil.isHook(method));
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiModifierList(com.intellij.psi.PsiModifierList) Test(org.junit.Test)

Example 30 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project Intellij-Plugin by getgauge.

the class HookUtilTest method TestIsHook.

@Test
public void TestIsHook() throws Exception {
    PsiMethod method = mock(PsiMethod.class);
    PsiModifierList list = mock(PsiModifierList.class);
    PsiAnnotation annotation = mock(PsiAnnotation.class);
    when(annotation.getQualifiedName()).thenReturn(BeforeStep.class.getCanonicalName());
    when(list.getAnnotations()).thenReturn(new PsiAnnotation[] { annotation });
    when(method.getModifierList()).thenReturn(list);
    assertTrue(HookUtil.isHook(method));
}
Also used : BeforeStep(com.thoughtworks.gauge.BeforeStep) PsiMethod(com.intellij.psi.PsiMethod) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiModifierList(com.intellij.psi.PsiModifierList) Test(org.junit.Test)

Aggregations

PsiAnnotation (com.intellij.psi.PsiAnnotation)61 PsiModifierList (com.intellij.psi.PsiModifierList)18 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)14 PsiMethod (com.intellij.psi.PsiMethod)14 NotNull (org.jetbrains.annotations.NotNull)13 Project (com.intellij.openapi.project.Project)12 PsiClass (com.intellij.psi.PsiClass)11 PsiElement (com.intellij.psi.PsiElement)9 MockProblemDescriptor (com.intellij.testFramework.MockProblemDescriptor)6 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)5 PsiParameter (com.intellij.psi.PsiParameter)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5 Nullable (org.jetbrains.annotations.Nullable)5 PsiParameterList (com.intellij.psi.PsiParameterList)4 TestSize (com.google.idea.blaze.base.dependencies.TestSize)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 PsiNameValuePair (com.intellij.psi.PsiNameValuePair)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Nullable (javax.annotation.Nullable)3