Search in sources :

Example 6 with RefEntity

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

the class InspectionResultsViewUtil method getNavigatableForInvalidNode.

@Nullable
static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
    RefEntity element = node.getElement();
    while (element != null && !element.isValid()) {
        element = element.getOwner();
    }
    if (!(element instanceof RefElement))
        return null;
    PsiElement containingElement = ((RefElement) element).getElement();
    if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid())
        return null;
    final int lineNumber = node.getLineNumber();
    if (lineNumber != -1) {
        final PsiFile containingFile = containingElement.getContainingFile();
        if (containingFile != null) {
            final VirtualFile file = containingFile.getVirtualFile();
            final Document document = FileDocumentManager.getInstance().getDocument(file);
            if (document != null && document.getLineCount() > lineNumber) {
                return new OpenFileDescriptor(containingElement.getProject(), file, lineNumber, 0);
            }
        }
    }
    return (Navigatable) containingElement;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefEntity(com.intellij.codeInspection.reference.RefEntity) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Document(com.intellij.openapi.editor.Document) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with RefEntity

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

the class InspectionTree method getSelectedElements.

@NotNull
public RefEntity[] getSelectedElements() {
    TreePath[] selectionPaths = getSelectionPaths();
    if (selectionPaths != null) {
        InspectionToolWrapper toolWrapper = getSelectedToolWrapper(true);
        if (toolWrapper == null)
            return RefEntity.EMPTY_ELEMENTS_ARRAY;
        Set<RefEntity> result = new LinkedHashSet<>();
        for (TreePath selectionPath : selectionPaths) {
            final InspectionTreeNode node = (InspectionTreeNode) selectionPath.getLastPathComponent();
            addElementsInNode(node, result);
        }
        return ArrayUtil.reverseArray(result.toArray(new RefEntity[result.size()]));
    }
    return RefEntity.EMPTY_ELEMENTS_ARRAY;
}
Also used : TreePath(javax.swing.tree.TreePath) RefEntity(com.intellij.codeInspection.reference.RefEntity) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with RefEntity

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

the class InspectionTreeCellRenderer method getMainForegroundAttributes.

private static SimpleTextAttributes getMainForegroundAttributes(InspectionTreeNode node) {
    SimpleTextAttributes foreground = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    if (node instanceof RefElementNode) {
        RefEntity refElement = ((RefElementNode) node).getElement();
        if (refElement instanceof RefElement) {
            refElement = ((RefElement) refElement).getContainingEntry();
            if (((RefElement) refElement).isEntry() && ((RefElement) refElement).isPermanentEntry()) {
                foreground = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.blue);
            }
        }
    }
    final FileStatus nodeStatus = node.getNodeStatus();
    if (nodeStatus != FileStatus.NOT_CHANGED) {
        foreground = new SimpleTextAttributes(foreground.getBgColor(), nodeStatus.getColor(), foreground.getWaveColor(), foreground.getStyle());
    }
    return foreground;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) FileStatus(com.intellij.openapi.vcs.FileStatus) RefEntity(com.intellij.codeInspection.reference.RefEntity) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 9 with RefEntity

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

the class InspectionTreeNode method getContainingFileLocalEntity.

public RefEntity getContainingFileLocalEntity() {
    final Enumeration children = children();
    RefEntity current = null;
    while (children.hasMoreElements()) {
        InspectionTreeNode child = (InspectionTreeNode) children.nextElement();
        final RefEntity entity = child.getContainingFileLocalEntity();
        if (entity == null || current != null) {
            return null;
        }
        current = entity;
    }
    return current;
}
Also used : Enumeration(java.util.Enumeration) RefEntity(com.intellij.codeInspection.reference.RefEntity)

Example 10 with RefEntity

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

the class GlobalInspectionContextImpl method exportResults.

private void exportResults(@NotNull List<File> inspectionsResults, @Nullable String outputPath) {
    @NonNls final String ext = ".xml";
    final Map<Element, Tools> globalTools = new HashMap<>();
    for (Map.Entry<String, Tools> entry : getTools().entrySet()) {
        final Tools sameTools = entry.getValue();
        boolean hasProblems = false;
        String toolName = entry.getKey();
        if (sameTools != null) {
            for (ScopeToolState toolDescr : sameTools.getTools()) {
                InspectionToolWrapper toolWrapper = toolDescr.getTool();
                if (toolWrapper instanceof LocalInspectionToolWrapper) {
                    hasProblems = new File(outputPath, toolName + ext).exists();
                } else {
                    InspectionToolPresentation presentation = getPresentation(toolWrapper);
                    presentation.updateContent();
                    if (presentation.hasReportedProblems()) {
                        final Element root = new Element(InspectionsBundle.message("inspection.problems"));
                        globalTools.put(root, sameTools);
                        LOG.assertTrue(!hasProblems, toolName);
                        break;
                    }
                }
            }
        }
        if (hasProblems) {
            try {
                new File(outputPath).mkdirs();
                final File file = new File(outputPath, toolName + ext);
                inspectionsResults.add(file);
                FileUtil.writeToFile(file, ("</" + InspectionsBundle.message("inspection.problems") + ">").getBytes(CharsetToolkit.UTF8_CHARSET), true);
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    }
    getRefManager().iterate(new RefVisitor() {

        @Override
        public void visitElement(@NotNull final RefEntity refEntity) {
            for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
                Tools tools = entry.getValue();
                Element element = entry.getKey();
                for (ScopeToolState state : tools.getTools()) {
                    try {
                        InspectionToolWrapper toolWrapper = state.getTool();
                        InspectionToolPresentation presentation = getPresentation(toolWrapper);
                        presentation.exportResults(element, refEntity, d -> false);
                    } catch (Throwable e) {
                        LOG.error("Problem when exporting: " + refEntity.getExternalName(), e);
                    }
                }
            }
        }
    });
    for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
        final String toolName = entry.getValue().getShortName();
        Element element = entry.getKey();
        element.setAttribute(LOCAL_TOOL_ATTRIBUTE, Boolean.toString(false));
        final org.jdom.Document doc = new org.jdom.Document(element);
        PathMacroManager.getInstance(getProject()).collapsePaths(doc.getRootElement());
        try {
            new File(outputPath).mkdirs();
            final File file = new File(outputPath, toolName + ext);
            inspectionsResults.add(file);
            try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), CharsetToolkit.UTF8_CHARSET)) {
                JDOMUtil.writeDocument(doc, writer, "\n");
            }
        } catch (IOException e) {
            LOG.error(e);
        }
    }
}
Also used : DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) com.intellij.openapi.util(com.intellij.openapi.util) UIUtil(com.intellij.util.ui.UIUtil) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) MessageType(com.intellij.openapi.ui.MessageType) ToggleAction(com.intellij.openapi.actionSystem.ToggleAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) Document(com.intellij.openapi.editor.Document) HashSet(com.intellij.util.containers.HashSet) DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) THashSet(gnu.trove.THashSet) TripleFunction(com.intellij.util.TripleFunction) com.intellij.openapi.application(com.intellij.openapi.application) ProjectUtilCore(com.intellij.openapi.project.ProjectUtilCore) ProblemHighlightFilter(com.intellij.codeInsight.daemon.ProblemHighlightFilter) FileIndex(com.intellij.openapi.roots.FileIndex) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) FileModificationService(com.intellij.codeInsight.FileModificationService) com.intellij.openapi.progress(com.intellij.openapi.progress) RefElement(com.intellij.codeInspection.reference.RefElement) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PathMacroManager(com.intellij.openapi.components.PathMacroManager) java.util.concurrent(java.util.concurrent) InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) ProjectUtil(com.intellij.openapi.project.ProjectUtil) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) Stream(java.util.stream.Stream) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) JobLauncherImpl(com.intellij.concurrency.JobLauncherImpl) com.intellij.ui.content(com.intellij.ui.content) java.util(java.util) LocalInspectionsPass(com.intellij.codeInsight.daemon.impl.LocalInspectionsPass) CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) CleanupInspectionIntention(com.intellij.codeInspection.actions.CleanupInspectionIntention) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption) JobLauncher(com.intellij.concurrency.JobLauncher) GlobalInspectionContextExtension(com.intellij.codeInspection.lang.GlobalInspectionContextExtension) SensitiveProgressWrapper(com.intellij.concurrency.SensitiveProgressWrapper) NonNls(org.jetbrains.annotations.NonNls) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) Constructor(java.lang.reflect.Constructor) ThreadDumper(com.intellij.diagnostic.ThreadDumper) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) ProblemGroup(com.intellij.lang.annotation.ProblemGroup) NotificationGroup(com.intellij.notification.NotificationGroup) ToolWindowId(com.intellij.openapi.wm.ToolWindowId) Project(com.intellij.openapi.project.Project) OutputStreamWriter(java.io.OutputStreamWriter) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) HighlightInfoProcessor(com.intellij.codeInsight.daemon.impl.HighlightInfoProcessor) AnalysisScope(com.intellij.analysis.AnalysisScope) FileOutputStream(java.io.FileOutputStream) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) IOException(java.io.IOException) com.intellij.codeInspection(com.intellij.codeInspection) AnalysisUIOptions(com.intellij.analysis.AnalysisUIOptions) GuiUtils(com.intellij.ui.GuiUtils) InspectionTreeState(com.intellij.codeInspection.ui.InspectionTreeState) Disposable(com.intellij.openapi.Disposable) File(java.io.File) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) Element(org.jdom.Element) RefEntity(com.intellij.codeInspection.reference.RefEntity) HashMap(com.intellij.util.containers.HashMap) RefElement(com.intellij.codeInspection.reference.RefElement) Element(org.jdom.Element) Document(com.intellij.openapi.editor.Document) NonNls(org.jetbrains.annotations.NonNls) IOException(java.io.IOException) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefEntity(com.intellij.codeInspection.reference.RefEntity) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) HashMap(com.intellij.util.containers.HashMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

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