Search in sources :

Example 1 with RefJavaVisitor

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

the class ClassWithTooManyDependenciesInspection method runInspection.

@Override
public void runInspection(@NotNull AnalysisScope scope, @NotNull final InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext, @NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor) {
    final RefManager refManager = globalInspectionContext.getRefManager();
    refManager.iterate(new RefJavaVisitor() {

        @Override
        public void visitClass(@NotNull RefClass refClass) {
            super.visitClass(refClass);
            if (refClass.getOwner() instanceof RefClass) {
                return;
            }
            final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(refClass);
            final int numDependencies = dependencies.size();
            if (numDependencies <= limit) {
                return;
            }
            final String errorString = InspectionGadgetsBundle.message("class.with.too.many.dependencies.problem.descriptor", refClass.getName(), numDependencies, limit);
            final CommonProblemDescriptor[] descriptors = { inspectionManager.createProblemDescriptor(errorString) };
            problemDescriptionsProcessor.addProblemElement(refClass, descriptors);
        }
    });
}
Also used : RefJavaVisitor(com.intellij.codeInspection.reference.RefJavaVisitor) RefClass(com.intellij.codeInspection.reference.RefClass) Set(java.util.Set) RefManager(com.intellij.codeInspection.reference.RefManager)

Aggregations

RefClass (com.intellij.codeInspection.reference.RefClass)1 RefJavaVisitor (com.intellij.codeInspection.reference.RefJavaVisitor)1 RefManager (com.intellij.codeInspection.reference.RefManager)1 Set (java.util.Set)1