Search in sources :

Example 16 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class SliceTreeTest method configureTree.

private SliceTreeStructure configureTree(@NonNls final String name) throws Exception {
    configureByFile("/codeInsight/slice/backward/" + name + ".java");
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    PsiElement element = new SliceHandler(true).getExpressionAtCaret(getEditor(), getFile());
    assertNotNull(element);
    Collection<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    SliceAnalysisParams params = new SliceAnalysisParams();
    params.scope = new AnalysisScope(getProject());
    params.dataFlowToThis = true;
    SliceUsage usage = LanguageSlicing.getProvider(element).createRootUsage(element, params);
    ToolWindowHeadlessManagerImpl.MockToolWindow toolWindow = new ToolWindowHeadlessManagerImpl.MockToolWindow(myProject);
    SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, toolWindow) {

        @Override
        protected void close() {
        }

        @Override
        public boolean isAutoScroll() {
            return false;
        }

        @Override
        public void setAutoScroll(boolean autoScroll) {
        }

        @Override
        public boolean isPreview() {
            return false;
        }

        @Override
        public void setPreview(boolean preview) {
        }
    };
    Disposer.register(getProject(), panel);
    return (SliceTreeStructure) panel.getBuilder().getTreeStructure();
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) AnalysisScope(com.intellij.analysis.AnalysisScope) ToolWindowHeadlessManagerImpl(com.intellij.openapi.wm.impl.ToolWindowHeadlessManagerImpl)

Example 17 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class SliceBackwardTest method doTest.

private void doTest() throws Exception {
    configureByFile("/codeInsight/slice/backward/" + getTestName(false) + ".java");
    Map<String, RangeMarker> sliceUsageName2Offset = SliceTestUtil.extractSliceOffsetsFromDocument(getEditor().getDocument());
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    PsiElement element = new SliceHandler(true).getExpressionAtCaret(getEditor(), getFile());
    assertNotNull(element);
    SliceTestUtil.calcRealOffsets(element, sliceUsageName2Offset, myFlownOffsets);
    Collection<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    SliceAnalysisParams params = new SliceAnalysisParams();
    params.scope = new AnalysisScope(getProject());
    params.dataFlowToThis = true;
    SliceUsage usage = LanguageSlicing.getProvider(element).createRootUsage(element, params);
    SliceTestUtil.checkUsages(usage, myFlownOffsets);
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) RangeMarker(com.intellij.openapi.editor.RangeMarker) PsiElement(com.intellij.psi.PsiElement)

Example 18 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class MethodDuplicatesHandler method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) {
    final int offset = editor.getCaretModel().getOffset();
    final PsiElement element = file.findElementAt(offset);
    final PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class);
    final String cannotRefactorMessage = getCannotRefactorMessage(member);
    if (cannotRefactorMessage != null) {
        String message = RefactoringBundle.getCannotRefactorMessage(cannotRefactorMessage);
        showErrorMessage(message, project, editor);
        return;
    }
    final AnalysisScope scope = new AnalysisScope(file);
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(RefactoringBundle.message("replace.method.duplicates.scope.chooser.title", REFACTORING_NAME), RefactoringBundle.message("replace.method.duplicates.scope.chooser.message"), project, scope, module != null ? module.getName() : null, false, AnalysisUIOptions.getInstance(project), element);
    if (dlg.showAndGet()) {
        AnalysisScope selectedScope = dlg.getScope(AnalysisUIOptions.getInstance(project), scope, project, module);
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Locate duplicates", true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                indicator.setIndeterminate(true);
                invokeOnScope(project, member, selectedScope);
            }
        });
    }
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Module(com.intellij.openapi.module.Module) BaseAnalysisActionDialog(com.intellij.analysis.BaseAnalysisActionDialog)

Example 19 with AnalysisScope

use of com.intellij.analysis.AnalysisScope 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 20 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class CleanupIntention method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
    if (!FileModificationService.getInstance().preparePsiElementForWrite(file))
        return;
    final InspectionManager managerEx = InspectionManager.getInstance(project);
    final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase) managerEx.createNewGlobalContext(false);
    final AnalysisScope scope = getScope(project, file);
    if (scope != null) {
        globalContext.codeCleanup(scope, InspectionProjectProfileManager.getInstance(project).getCurrentProfile(), getText(), null, false);
    }
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) InspectionManager(com.intellij.codeInspection.InspectionManager) GlobalInspectionContextBase(com.intellij.codeInspection.ex.GlobalInspectionContextBase)

Aggregations

AnalysisScope (com.intellij.analysis.AnalysisScope)56 Module (com.intellij.openapi.module.Module)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 Project (com.intellij.openapi.project.Project)12 NotNull (org.jetbrains.annotations.NotNull)10 PsiPackage (com.intellij.psi.PsiPackage)8 File (java.io.File)8 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)7 PsiElement (com.intellij.psi.PsiElement)6 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)6 Nullable (org.jetbrains.annotations.Nullable)6 AnalysisUIOptions (com.intellij.analysis.AnalysisUIOptions)5 BaseAnalysisActionDialog (com.intellij.analysis.BaseAnalysisActionDialog)5 PsiFile (com.intellij.psi.PsiFile)4 SearchScope (com.intellij.psi.search.SearchScope)4 HashMap (com.intellij.util.containers.HashMap)4 LintDriver (com.android.tools.lint.client.api.LintDriver)3 LintRequest (com.android.tools.lint.client.api.LintRequest)3 Issue (com.android.tools.lint.detector.api.Issue)3