Search in sources :

Example 6 with LocalInspectionToolWrapper

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

the class InspectionEngine method runInspectionOnFile.

@NotNull
public static List<ProblemDescriptor> runInspectionOnFile(@NotNull final PsiFile file, @NotNull InspectionToolWrapper toolWrapper, @NotNull final GlobalInspectionContext inspectionContext) {
    final InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
    toolWrapper.initialize(inspectionContext);
    RefManagerImpl refManager = (RefManagerImpl) inspectionContext.getRefManager();
    refManager.inspectionReadActionStarted();
    try {
        if (toolWrapper instanceof LocalInspectionToolWrapper) {
            return inspect(Collections.singletonList((LocalInspectionToolWrapper) toolWrapper), file, inspectionManager, new EmptyProgressIndicator());
        }
        if (toolWrapper instanceof GlobalInspectionToolWrapper) {
            final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper) toolWrapper).getTool();
            final List<ProblemDescriptor> descriptors = new ArrayList<>();
            if (globalTool instanceof GlobalSimpleInspectionTool) {
                GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool) globalTool;
                ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, file, false);
                ProblemDescriptionsProcessor collectProcessor = new ProblemDescriptionsProcessor() {

                    @Nullable
                    @Override
                    public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
                        return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
                    }

                    @Override
                    public void ignoreElement(@NotNull RefEntity refEntity) {
                        throw new RuntimeException();
                    }

                    @Override
                    public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
                        if (!(refEntity instanceof RefElement))
                            return;
                        PsiElement element = ((RefElement) refEntity).getElement();
                        convertToProblemDescriptors(element, commonProblemDescriptors, descriptors);
                    }

                    @Override
                    public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
                        throw new RuntimeException();
                    }
                };
                simpleTool.checkFile(file, inspectionManager, problemsHolder, inspectionContext, collectProcessor);
                return descriptors;
            }
            RefElement fileRef = refManager.getReference(file);
            final AnalysisScope scope = new AnalysisScope(file);
            assert fileRef != null;
            fileRef.accept(new RefVisitor() {

                @Override
                public void visitElement(@NotNull RefEntity elem) {
                    CommonProblemDescriptor[] elemDescriptors = globalTool.checkElement(elem, scope, inspectionManager, inspectionContext);
                    if (elemDescriptors != null) {
                        convertToProblemDescriptors(file, elemDescriptors, descriptors);
                    }
                    for (RefEntity child : elem.getChildren()) {
                        child.accept(this);
                    }
                }
            });
            return descriptors;
        }
    } finally {
        refManager.inspectionReadActionFinished();
        toolWrapper.cleanup(file.getProject());
        inspectionContext.cleanup();
    }
    return Collections.emptyList();
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) NotNull(org.jetbrains.annotations.NotNull) RefElement(com.intellij.codeInspection.reference.RefElement) AnalysisScope(com.intellij.analysis.AnalysisScope) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefEntity(com.intellij.codeInspection.reference.RefEntity) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with LocalInspectionToolWrapper

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

the class InspectionEngine method getToolsToSpecifiedLanguages.

// returns map tool -> set of languages and dialects for that tool specified in plugin.xml
@NotNull
public static Map<LocalInspectionToolWrapper, Set<String>> getToolsToSpecifiedLanguages(@NotNull List<LocalInspectionToolWrapper> toolWrappers) {
    Map<LocalInspectionToolWrapper, Set<String>> toolToLanguages = new THashMap<>();
    for (LocalInspectionToolWrapper wrapper : toolWrappers) {
        ProgressManager.checkCanceled();
        Set<String> specifiedLangIds = getDialectIdsSpecifiedForTool(wrapper);
        toolToLanguages.put(wrapper, specifiedLangIds);
    }
    return toolToLanguages;
}
Also used : THashSet(gnu.trove.THashSet) SmartHashSet(com.intellij.util.containers.SmartHashSet) THashMap(gnu.trove.THashMap) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LocalInspectionToolWrapper

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

the class HighlightStressTest method configureLocalInspectionTools.

@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
    if ("RandomEditingForUnused".equals(getTestName(false))) {
        return new LocalInspectionTool[] { new UnusedImportLocalInspection() };
    }
    List<InspectionToolWrapper> all = InspectionToolRegistrar.getInstance().createTools();
    List<LocalInspectionTool> locals = new ArrayList<>();
    for (InspectionToolWrapper tool : all) {
        if (tool instanceof LocalInspectionToolWrapper) {
            LocalInspectionTool e = ((LocalInspectionToolWrapper) tool).getTool();
            locals.add(e);
        }
    }
    return locals.toArray(new LocalInspectionTool[locals.size()]);
}
Also used : UnusedImportLocalInspection(com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with LocalInspectionToolWrapper

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

the class RedundantCast15Test method doTest.

private void doTest() throws Exception {
    final LocalInspectionToolWrapper toolWrapper = new LocalInspectionToolWrapper(new RedundantCastInspection());
    doTest("redundantCast/generics/" + getTestName(false), toolWrapper, "java 1.5");
}
Also used : RedundantCastInspection(com.intellij.codeInspection.redundantCast.RedundantCastInspection) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Example 10 with LocalInspectionToolWrapper

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

the class RedundantCast15Test method testIgnore.

public void testIgnore() throws Exception {
    final RedundantCastInspection castInspection = new RedundantCastInspection();
    castInspection.IGNORE_ANNOTATED_METHODS = true;
    castInspection.IGNORE_SUSPICIOUS_METHOD_CALLS = true;
    final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(castInspection);
    doTest("redundantCast/generics/" + getTestName(false), tool, "java 1.5");
}
Also used : RedundantCastInspection(com.intellij.codeInspection.redundantCast.RedundantCastInspection) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Aggregations

LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)26 NotNull (org.jetbrains.annotations.NotNull)11 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)6 Nullable (org.jetbrains.annotations.Nullable)6 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 RefElement (com.intellij.codeInspection.reference.RefElement)3 TextRange (com.intellij.openapi.util.TextRange)3 List (java.util.List)3 AnalysisScope (com.intellij.analysis.AnalysisScope)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 IntentionManager (com.intellij.codeInsight.intention.IntentionManager)2 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 InspectionManager (com.intellij.codeInspection.InspectionManager)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)2 RedundantCastInspection (com.intellij.codeInspection.redundantCast.RedundantCastInspection)2 RefEntity (com.intellij.codeInspection.reference.RefEntity)2 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)2 RefVisitor (com.intellij.codeInspection.reference.RefVisitor)2