use of com.intellij.psi.PsiAnnotationMemberValue 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.PsiAnnotationMemberValue in project qi4j-sdk by Qi4j.
the class SideEffectsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @SideEffects, ignore
PsiAnnotation sideEffectsAnnotation = getSideEffectsAnnotation(psiClass);
if (sideEffectsAnnotation == null) {
return null;
}
// If @SideEffects declared in class, suggest remove @SideEffects annotation
if (!psiClass.isInterface()) {
String message = message("side.effects.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveSideEffectsAnnotationFix fix = new RemoveSideEffectsAnnotationFix(sideEffectsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @SideEffects annotation is empty, ignore
List<PsiAnnotationMemberValue> sideEffectsAnnotationValue = getSideEffectsAnnotationValue(sideEffectsAnnotation);
if (sideEffectsAnnotationValue.isEmpty()) {
return null;
}
// If SideEffectOf is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass sideEffectOfClass = Qi4jSideEffectUtil.getGenericSideEffectClass(project, searchScope);
if (sideEffectOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue sideEffectClassReferenceWrapper : sideEffectsAnnotationValue) {
PsiJavaCodeReferenceElement sideEffectClassReference = getSideEffectClassReference(sideEffectClassReferenceWrapper);
// If it's not a class reference, ignore
if (sideEffectClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass sideEffectClass = (PsiClass) sideEffectClassReference.resolve();
if (sideEffectClass == null) {
continue;
}
// If side effect class does not inherit SideEffectOf class, suggest remove that reference.
if (!sideEffectClass.isInheritor(sideEffectOfClass, true)) {
String message = Qi4jResourceBundle.message("side.effects.annotation.declared.correctly.error.side.effect.does.not.extend.side.effect.of", sideEffectClass.getQualifiedName());
RemoveAnnotationValueFix fix = new RemoveAnnotationValueFix(sideEffectClassReferenceWrapper, sideEffectClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectClassReferenceWrapper, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic side effect
// TODO: Test whether it is a specific side effect
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.PsiAnnotationMemberValue in project kotlin by JetBrains.
the class LintDriver method isSuppressed.
/**
* Returns true if the annotation member value, assumed to be specified on a a SuppressWarnings
* or SuppressLint annotation, specifies the given id (or "all").
*
* @param issue the issue to be checked
* @param value the member value to check
* @return true if the issue or all issues should be suppressed for this modifier
*/
public static boolean isSuppressed(@NonNull Issue issue, @Nullable PsiAnnotationMemberValue value) {
if (value instanceof PsiLiteral) {
PsiLiteral literal = (PsiLiteral) value;
Object literalValue = literal.getValue();
if (literalValue instanceof String) {
if (isSuppressed(issue, (String) literalValue)) {
return true;
}
}
} else if (value instanceof PsiArrayInitializerMemberValue) {
PsiArrayInitializerMemberValue mv = (PsiArrayInitializerMemberValue) value;
for (PsiAnnotationMemberValue mmv : mv.getInitializers()) {
if (isSuppressed(issue, mmv)) {
return true;
}
}
} else if (value instanceof PsiArrayInitializerExpression) {
PsiArrayInitializerExpression expression = (PsiArrayInitializerExpression) value;
PsiExpression[] initializers = expression.getInitializers();
for (PsiExpression e : initializers) {
if (isSuppressed(issue, e)) {
return true;
}
}
}
return false;
}
use of com.intellij.psi.PsiAnnotationMemberValue in project qi4j-sdk by Qi4j.
the class MixinImplementsMixinType method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If psiClass is not an interface, ignore
if (!psiClass.isInterface()) {
return null;
}
// If @Mixins annotation is empty, ignore
List<PsiAnnotationMemberValue> mixinAnnotationValues = getMixinsAnnotationValue(psiClass);
if (mixinAnnotationValues.isEmpty()) {
return null;
}
// Get all valid mixin type
Set<PsiClass> validMixinsType = getAllValidMixinTypes(psiClass);
if (validMixinsType.isEmpty()) {
return null;
}
// For each mixin
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue mixinAnnotationValue : mixinAnnotationValues) {
PsiJavaCodeReferenceElement mixinClassReference = getMixinClassReference(mixinAnnotationValue);
// If it's not a class reference, ignore
if (mixinClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass mixinClass = (PsiClass) mixinClassReference.resolve();
if (mixinClass == null) {
continue;
}
String mixinQualifiedName = mixinClass.getQualifiedName();
boolean isMixinsDeclarationValid = false;
String message = "";
if (mixinClass.isInterface()) {
// Mixin can't be an interface
message = message("mixin.implements.mixin.type.error.mixin.is.an.interface", mixinQualifiedName);
} else if (isAConcern(mixinClass)) {
// Mixin can't be a concern
message = message("mixin.implements.mixin.type.error.mixin.is.a.concern", mixinQualifiedName);
} else if (isASideEffect(mixinClass)) {
// Mixin can't be a side effect
message = message("mixin.implements.mixin.type.error.mixin.is.a.side.effect", mixinQualifiedName);
} else {
// If doesn't implement any mixin type, it's a problem
if (!isImplementValidMixinType(mixinClass, validMixinsType)) {
message = message("mixin.implements.mixin.type.error.does.not.implement.any.mixin.type", mixinQualifiedName, psiClass.getQualifiedName());
} else {
isMixinsDeclarationValid = true;
}
}
if (!isMixinsDeclarationValid) {
ProblemDescriptor problemDescriptor = createProblemDescriptor(manager, mixinAnnotationValue, mixinClassReference, message);
problems.add(problemDescriptor);
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.PsiAnnotationMemberValue in project smali by JesusFreke.
the class SmaliAnnotationElement method getValue.
@Nullable
@Override
public PsiAnnotationMemberValue getValue() {
ASTNode equalNode = findChildByType(SmaliTokens.EQUAL);
if (equalNode == null) {
return null;
}
PsiElement nextElement = equalNode.getPsi().getNextSibling();
while (nextElement != null) {
if (nextElement instanceof PsiAnnotationMemberValue) {
return (PsiAnnotationMemberValue) nextElement;
}
nextElement = nextElement.getNextSibling();
}
return null;
}
Aggregations