use of org.jetbrains.idea.devkit.util.ComponentType in project intellij-community by JetBrains.
the class ComponentNotRegisteredInspection method checkClass.
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass checkedClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
PsiFile psiFile = checkedClass.getContainingFile();
PsiIdentifier classIdentifier = checkedClass.getNameIdentifier();
if (checkedClass.getQualifiedName() != null && classIdentifier != null && psiFile != null && psiFile.getVirtualFile() != null && !checkedClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
if (PsiUtil.isInnerClass(checkedClass)) {
// don't check inner classes (make this an option?)
return null;
}
PsiManager psiManager = checkedClass.getManager();
GlobalSearchScope scope = checkedClass.getResolveScope();
if (CHECK_ACTIONS) {
PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope);
if (actionClass == null) {
// stop if action class cannot be found (non-devkit module/project)
return null;
}
if (checkedClass.isInheritor(actionClass, true)) {
if (IGNORE_NON_PUBLIC && !checkedClass.hasModifierProperty(PsiModifier.PUBLIC)) {
return null;
}
if (!isActionRegistered(checkedClass) && canFix(checkedClass)) {
LocalQuickFix fix = new RegisterActionFix(org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message("new.menu.action.text")), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
return new ProblemDescriptor[] { problem };
} else {
// action IS registered, stop here
return null;
}
}
}
ComponentType[] types = ComponentType.values();
for (ComponentType type : types) {
PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope);
if (compClass == null) {
// stop if component classes cannot be found (non-devkit module/project)
return null;
}
if (checkedClass.isInheritor(compClass, true)) {
if (RegistrationCheckerUtil.getRegistrationTypes(checkedClass, false) == null && canFix(checkedClass)) {
LocalQuickFix fix = new RegisterComponentFix(type, org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message(type.myPropertyKey)), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
return new ProblemDescriptor[] { problem };
} else {
// component IS registered, stop here
return null;
}
}
}
}
return null;
}
Aggregations