Search in sources :

Example 16 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.

the class ModuleWithTooFewClassesInspection method checkElement.

@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
    if (!(refEntity instanceof RefModule)) {
        return null;
    }
    final RefModule refModule = (RefModule) refEntity;
    final List<RefEntity> children = refModule.getChildren();
    int numClasses = 0;
    for (RefEntity child : children) {
        if (child instanceof RefClass) {
            numClasses++;
        }
    }
    if (numClasses >= limit || numClasses == 0) {
        return null;
    }
    final Project project = globalInspectionContext.getProject();
    final Module[] modules = ModuleManager.getInstance(project).getModules();
    if (modules.length == 1) {
        return null;
    }
    final String errorString = InspectionGadgetsBundle.message("module.with.too.few.classes.problem.descriptor", refModule.getName(), Integer.valueOf(numClasses), Integer.valueOf(limit));
    return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Also used : RefModule(com.intellij.codeInspection.reference.RefModule) Project(com.intellij.openapi.project.Project) RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) RefModule(com.intellij.codeInspection.reference.RefModule) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.

the class ModuleWithTooManyClassesInspection method checkElement.

@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
    if (!(refEntity instanceof RefModule)) {
        return null;
    }
    final List<RefEntity> children = refEntity.getChildren();
    int numClasses = 0;
    for (RefEntity child : children) {
        if (child instanceof RefClass) {
            numClasses++;
        }
    }
    if (numClasses <= limit) {
        return null;
    }
    final String errorString = InspectionGadgetsBundle.message("module.with.too.many.classes.problem.descriptor", refEntity.getName(), Integer.valueOf(numClasses), Integer.valueOf(limit));
    return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Also used : RefModule(com.intellij.codeInspection.reference.RefModule) RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.

the class MissingPackageInfoInspectionBase method checkElement.

@Nullable
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext) {
    if (!(refEntity instanceof RefPackage)) {
        return null;
    }
    final RefPackage refPackage = (RefPackage) refEntity;
    final String packageName = refPackage.getQualifiedName();
    final Project project = globalContext.getProject();
    final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
    if (hasPackageInfoFile(aPackage)) {
        return null;
    }
    final List<RefEntity> children = refPackage.getChildren();
    boolean hasClasses = false;
    for (RefEntity child : children) {
        if (child instanceof RefClass) {
            hasClasses = true;
            break;
        }
    }
    if (!hasClasses) {
        return null;
    }
    if (PsiUtil.isLanguageLevel5OrHigher(aPackage)) {
        return new CommonProblemDescriptor[] { manager.createProblemDescriptor(InspectionGadgetsBundle.message("missing.package.info.problem.descriptor", packageName)) };
    } else {
        return new CommonProblemDescriptor[] { manager.createProblemDescriptor(InspectionGadgetsBundle.message("missing.package.html.problem.descriptor", packageName)) };
    }
}
Also used : Project(com.intellij.openapi.project.Project) RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) RefPackage(com.intellij.codeInspection.reference.RefPackage) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.

the class ClassWithTooManyDependentsInspection method checkElement.

@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
    if (!(refEntity instanceof RefClass)) {
        return null;
    }
    final RefClass refClass = (RefClass) refEntity;
    final PsiClass aClass = refClass.getElement();
    if (ClassUtils.isInnerClass(aClass)) {
        return null;
    }
    final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
    final int numDependents = dependents.size();
    if (numDependents <= limit) {
        return null;
    }
    final String errorString = InspectionGadgetsBundle.message("class.with.too.many.dependents.problem.descriptor", refEntity.getName(), numDependents, limit);
    return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Also used : RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.

the class InspectionRVContentProviderImpl method appendDescriptor.

@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper, @NotNull final RefEntityContainer container, @NotNull final InspectionTreeNode pNode, final boolean canPackageRepeat) {
    final RefEntity refElement = container.getRefEntity();
    InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
    final CommonProblemDescriptor[] problems = ((RefEntityContainer<CommonProblemDescriptor>) container).getDescriptors();
    if (problems != null) {
        final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
        for (CommonProblemDescriptor problem : problems) {
            assert problem != null;
            elemNode.insertByOrder(ReadAction.compute(() -> new ProblemDescriptionNode(refElement, problem, toolWrapper, presentation)), true);
            elemNode.setProblem(elemNode.getChildCount() == 1 ? problems[0] : null);
        }
    } else {
        if (canPackageRepeat && pNode instanceof InspectionPackageNode) {
            final Set<RefEntity> currentElements = presentation.getContent().get(((InspectionPackageNode) pNode).getPackageName());
            if (currentElements != null) {
                final Set<RefEntity> currentEntities = new HashSet<>(currentElements);
                if (RefUtil.contains(refElement, currentEntities))
                    return;
            }
        }
        addNodeToParent(container, presentation, pNode);
    }
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) HashSet(com.intellij.util.containers.HashSet)

Aggregations

CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)30 Nullable (org.jetbrains.annotations.Nullable)20 RefClass (com.intellij.codeInspection.reference.RefClass)13 RefEntity (com.intellij.codeInspection.reference.RefEntity)12 RefPackage (com.intellij.codeInspection.reference.RefPackage)9 PsiClass (com.intellij.psi.PsiClass)9 PsiElement (com.intellij.psi.PsiElement)7 HashSet (java.util.HashSet)6 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)5 RefModule (com.intellij.codeInspection.reference.RefModule)4 PsiIdentifier (com.intellij.psi.PsiIdentifier)4 NotNull (org.jetbrains.annotations.NotNull)4 QuickFix (com.intellij.codeInspection.QuickFix)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiField (com.intellij.psi.PsiField)2 PsiType (com.intellij.psi.PsiType)2 TreePath (javax.swing.tree.TreePath)2 BatchQuickFix (com.intellij.codeInspection.BatchQuickFix)1 ProblemDescriptorBase (com.intellij.codeInspection.ProblemDescriptorBase)1