Search in sources :

Example 16 with RefEntity

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

the class PackageWithTooFewClassesInspection method checkElement.

@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
    if (!(refEntity instanceof RefPackage)) {
        return null;
    }
    final List<RefEntity> children = refEntity.getChildren();
    int numClasses = 0;
    boolean subpackage = false;
    for (RefEntity child : children) {
        if (child instanceof RefClass) {
            numClasses++;
        } else if (child instanceof RefPackage) {
            subpackage = true;
        }
    }
    if (numClasses >= limit || (numClasses == 0 && subpackage)) {
        return null;
    }
    final String errorString = InspectionGadgetsBundle.message("package.with.too.few.classes.problem.descriptor", refEntity.getQualifiedName(), Integer.valueOf(numClasses), Integer.valueOf(limit));
    return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Also used : 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 17 with RefEntity

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

the class PackageWithTooManyClassesInspection method checkElement.

@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
    if (!(refEntity instanceof RefPackage)) {
        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("package.with.too.many.classes.problem.descriptor", refEntity.getQualifiedName(), Integer.valueOf(numClasses), Integer.valueOf(limit));
    return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Also used : 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 18 with RefEntity

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

the class ClassUnconnectedToPackageInspection method checkElement.

@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalInspectionContext) {
    if (!(refEntity instanceof RefClass)) {
        return null;
    }
    final RefClass refClass = (RefClass) refEntity;
    final RefEntity owner = refClass.getOwner();
    if (!(owner instanceof RefPackage)) {
        return null;
    }
    final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(refClass);
    for (RefClass dependency : dependencies) {
        if (inSamePackage(refClass, dependency)) {
            return null;
        }
    }
    final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
    for (RefClass dependent : dependents) {
        if (inSamePackage(refClass, dependent)) {
            return null;
        }
    }
    final PsiClass aClass = refClass.getElement();
    final PsiIdentifier identifier = aClass.getNameIdentifier();
    if (identifier == null) {
        return null;
    }
    return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.unconnected.to.package.problem.descriptor"), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
Also used : RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) RefPackage(com.intellij.codeInspection.reference.RefPackage) PsiClass(com.intellij.psi.PsiClass) PsiIdentifier(com.intellij.psi.PsiIdentifier) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with RefEntity

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

the class SuppressableInspectionTreeNode method getSuppressContent.

@NotNull
public final Pair<PsiElement, CommonProblemDescriptor> getSuppressContent() {
    RefEntity refElement = getElement();
    CommonProblemDescriptor descriptor = getDescriptor();
    PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
    return Pair.create(element, descriptor);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with RefEntity

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

the class GlobalInspectionContextImpl method ignoreElementRecursively.

private void ignoreElementRecursively(@NotNull InspectionToolWrapper toolWrapper, final RefEntity refElement) {
    if (refElement != null) {
        InspectionToolPresentation presentation = getPresentation(toolWrapper);
        presentation.ignoreCurrentElement(refElement);
        final List<RefEntity> children = refElement.getChildren();
        for (RefEntity child : children) {
            ignoreElementRecursively(toolWrapper, child);
        }
    }
}
Also used : DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) RefEntity(com.intellij.codeInspection.reference.RefEntity)

Aggregations

RefEntity (com.intellij.codeInspection.reference.RefEntity)38 RefElement (com.intellij.codeInspection.reference.RefElement)17 Nullable (org.jetbrains.annotations.Nullable)15 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)12 RefClass (com.intellij.codeInspection.reference.RefClass)11 NotNull (org.jetbrains.annotations.NotNull)9 PsiElement (com.intellij.psi.PsiElement)8 RefPackage (com.intellij.codeInspection.reference.RefPackage)7 HashSet (com.intellij.util.containers.HashSet)5 RefModule (com.intellij.codeInspection.reference.RefModule)4 Project (com.intellij.openapi.project.Project)4 DefaultInspectionToolPresentation (com.intellij.codeInspection.ui.DefaultInspectionToolPresentation)3 InspectionToolPresentation (com.intellij.codeInspection.ui.InspectionToolPresentation)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 THashSet (gnu.trove.THashSet)3 AnalysisScope (com.intellij.analysis.AnalysisScope)2 RefJavaUtil (com.intellij.codeInspection.reference.RefJavaUtil)2 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)2 RefVisitor (com.intellij.codeInspection.reference.RefVisitor)2 ProblemGroup (com.intellij.lang.annotation.ProblemGroup)2