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