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 };
}
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()]);
}
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);
}
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));
}
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));
}
Aggregations