Search in sources :

Example 6 with RefModule

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

the class ClassOnlyUsedInOneModuleInspection method checkElement.

@Nullable
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext) {
    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);
    RefModule otherModule = null;
    for (RefClass dependency : dependencies) {
        final RefModule module = dependency.getModule();
        if (refClass.getModule() == module) {
            return null;
        }
        if (otherModule != module) {
            if (otherModule == null) {
                otherModule = module;
            } else {
                return null;
            }
        }
    }
    final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
    for (RefClass dependent : dependents) {
        final RefModule module = dependent.getModule();
        if (refClass.getModule() == module) {
            return null;
        }
        if (otherModule != module) {
            if (otherModule == null) {
                otherModule = module;
            } else {
                return null;
            }
        }
    }
    if (otherModule == null) {
        return null;
    }
    final PsiClass aClass = refClass.getElement();
    final PsiIdentifier identifier = aClass.getNameIdentifier();
    if (identifier == null) {
        return null;
    }
    final String moduleName = otherModule.getName();
    return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.only.used.in.one.module.problem.descriptor", moduleName), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
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) RefPackage(com.intellij.codeInspection.reference.RefPackage) PsiClass(com.intellij.psi.PsiClass) PsiIdentifier(com.intellij.psi.PsiIdentifier) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with RefModule

use of com.intellij.codeInspection.reference.RefModule 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 8 with RefModule

use of com.intellij.codeInspection.reference.RefModule 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)

Aggregations

RefModule (com.intellij.codeInspection.reference.RefModule)8 Module (com.intellij.openapi.module.Module)5 Nullable (org.jetbrains.annotations.Nullable)5 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)4 RefClass (com.intellij.codeInspection.reference.RefClass)4 RefEntity (com.intellij.codeInspection.reference.RefEntity)4 RefManager (com.intellij.codeInspection.reference.RefManager)2 RefPackage (com.intellij.codeInspection.reference.RefPackage)2 PsiElement (com.intellij.psi.PsiElement)2 UnnecessaryModuleDependencyInspection (com.intellij.codeInspection.unnecessaryModuleDependency.UnnecessaryModuleDependencyInspection)1 Project (com.intellij.openapi.project.Project)1 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 OrderEntry (com.intellij.openapi.roots.OrderEntry)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 PsiIdentifier (com.intellij.psi.PsiIdentifier)1 THashSet (gnu.trove.THashSet)1