Search in sources :

Example 36 with RefEntity

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

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

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

the class InitializationDependencyUtils method tabulateInitializationDependencyClasses.

@SuppressWarnings({ "MethodWithMultipleLoops" })
static void tabulateInitializationDependencyClasses(RefElement element, Set<RefClass> dependencies) {
    final Collection<RefElement> references = element.getOutReferences();
    final RefJavaUtil refUtil = RefJavaUtil.getInstance();
    for (RefElement reference : references) {
        final RefClass refClass = refUtil.getTopLevelClass(reference);
        if (refClass != null) {
            dependencies.add(refClass);
        }
    }
    final List<RefEntity> children = element.getChildren();
    for (RefEntity child : children) {
        if (child instanceof RefElement) {
            tabulateInitializationDependencyClasses((RefElement) child, dependencies);
        }
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefClass(com.intellij.codeInspection.reference.RefClass) RefEntity(com.intellij.codeInspection.reference.RefEntity) RefJavaUtil(com.intellij.codeInspection.reference.RefJavaUtil)

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