Search in sources :

Example 1 with ComponentType

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;
}
Also used : ComponentType(org.jetbrains.idea.devkit.util.ComponentType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) AnAction(com.intellij.openapi.actionSystem.AnAction) RegisterActionFix(org.jetbrains.idea.devkit.inspections.quickfix.RegisterActionFix) RegisterComponentFix(org.jetbrains.idea.devkit.inspections.quickfix.RegisterComponentFix) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 Nullable (org.jetbrains.annotations.Nullable)1 RegisterActionFix (org.jetbrains.idea.devkit.inspections.quickfix.RegisterActionFix)1 RegisterComponentFix (org.jetbrains.idea.devkit.inspections.quickfix.RegisterComponentFix)1 ComponentType (org.jetbrains.idea.devkit.util.ComponentType)1