Search in sources :

Example 1 with LocationNode

use of org.sonarlint.intellij.ui.nodes.LocationNode in project sonarlint-intellij by SonarSource.

the class FlowsTreeModelBuilder method setSingleFlow.

private void setSingleFlow(LiveIssue.Flow flow, RangeMarker rangeMarker, @Nullable String message) {
    summary = new SummaryNode();
    LocationNode primaryLocation = new LocationNode(rangeMarker, message);
    primaryLocation.setBold(true);
    summary.add(primaryLocation);
    List<LiveIssue.IssueLocation> reversedLocations = new ArrayList<>(flow.locations());
    Collections.reverse(reversedLocations);
    int i = 1;
    for (LiveIssue.IssueLocation location : reversedLocations) {
        LocationNode locationNode = new LocationNode(i++, location.location(), location.message());
        primaryLocation.add(locationNode);
    }
    model.setRoot(summary);
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) SummaryNode(org.sonarlint.intellij.ui.nodes.SummaryNode) LocationNode(org.sonarlint.intellij.ui.nodes.LocationNode) ArrayList(java.util.ArrayList)

Example 2 with LocationNode

use of org.sonarlint.intellij.ui.nodes.LocationNode in project sonarlint-intellij by SonarSource.

the class FlowsTreeModelBuilder method setMultipleFlows.

private void setMultipleFlows(List<LiveIssue.Flow> flows, RangeMarker rangeMarker, @Nullable String message) {
    summary = new SummaryNode();
    LocationNode primaryLocation = new LocationNode(rangeMarker, message);
    summary.add(primaryLocation);
    int i = 1;
    for (LiveIssue.Flow f : flows) {
        LabelNode label = new LabelNode("Flow " + i);
        primaryLocation.add(label);
        List<LiveIssue.IssueLocation> reversedLocations = new ArrayList<>(f.locations());
        Collections.reverse(reversedLocations);
        int j = 1;
        for (LiveIssue.IssueLocation location : reversedLocations) {
            LocationNode locationNode = new LocationNode(j, location.location(), location.message());
            label.add(locationNode);
            j++;
        }
        i++;
    }
    model.setRoot(summary);
}
Also used : LabelNode(org.sonarlint.intellij.ui.nodes.LabelNode) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) SummaryNode(org.sonarlint.intellij.ui.nodes.SummaryNode) LocationNode(org.sonarlint.intellij.ui.nodes.LocationNode) ArrayList(java.util.ArrayList)

Example 3 with LocationNode

use of org.sonarlint.intellij.ui.nodes.LocationNode in project sonarlint-intellij by SonarSource.

the class FlowsTreeModelBuilder method setFlatList.

private void setFlatList(List<LiveIssue.Flow> flows, RangeMarker rangeMarker, @Nullable String message) {
    summary = new SummaryNode();
    LocationNode primaryLocation = new LocationNode(rangeMarker, message);
    primaryLocation.setBold(true);
    summary.add(primaryLocation);
    flows.stream().flatMap(flow -> flow.locations().stream()).sorted(Comparator.comparing(i -> i.location().getStartOffset())).forEachOrdered(location -> {
        LocationNode locationNode = new LocationNode(location.location(), location.message());
        primaryLocation.add(locationNode);
    });
    model.setRoot(summary);
}
Also used : SummaryNode(org.sonarlint.intellij.ui.nodes.SummaryNode) LocationNode(org.sonarlint.intellij.ui.nodes.LocationNode)

Example 4 with LocationNode

use of org.sonarlint.intellij.ui.nodes.LocationNode in project sonarlint-intellij by SonarSource.

the class FlowsTree method init.

private void init() {
    setRootVisible(false);
    setShowsRootHandles(false);
    setCellRenderer(new TreeCellRenderer());
    this.selectionModel.addTreeSelectionListener(e -> {
        if (e.getSource() != null) {
            TreePath newPath = e.getNewLeadSelectionPath();
            if (newPath != null) {
                Object o = newPath.getLastPathComponent();
                if (!(o instanceof LocationNode)) {
                    FlowsTree.this.setSelectionPath(e.getOldLeadSelectionPath());
                } else {
                    navigateToSelected();
                }
            }
        }
    });
    TreeWillExpandListener l = new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
        // nothing to do
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
            throw new ExpandVetoException(event);
        }
    };
    addTreeWillExpandListener(l);
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) TreePath(javax.swing.tree.TreePath) LocationNode(org.sonarlint.intellij.ui.nodes.LocationNode) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) ExpandVetoException(javax.swing.tree.ExpandVetoException)

Example 5 with LocationNode

use of org.sonarlint.intellij.ui.nodes.LocationNode in project sonarlint-intellij by SonarSource.

the class FlowsTree method navigateToSelected.

private void navigateToSelected() {
    DefaultMutableTreeNode node = getSelectedNode();
    if (!(node instanceof LocationNode)) {
        return;
    }
    RangeMarker rangeMarker = ((LocationNode) node).rangeMarker();
    if (rangeMarker == null || !rangeMarker.isValid()) {
        return;
    }
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(rangeMarker.getDocument());
    if (psiFile != null) {
        new OpenFileDescriptor(project, psiFile.getVirtualFile(), rangeMarker.getStartOffset()).navigate(false);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LocationNode(org.sonarlint.intellij.ui.nodes.LocationNode) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) RangeMarker(com.intellij.openapi.editor.RangeMarker)

Aggregations

LocationNode (org.sonarlint.intellij.ui.nodes.LocationNode)6 SummaryNode (org.sonarlint.intellij.ui.nodes.SummaryNode)3 ArrayList (java.util.ArrayList)2 LiveIssue (org.sonarlint.intellij.issue.LiveIssue)2 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 PsiFile (com.intellij.psi.PsiFile)1 TreeExpansionEvent (javax.swing.event.TreeExpansionEvent)1 TreeWillExpandListener (javax.swing.event.TreeWillExpandListener)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 ExpandVetoException (javax.swing.tree.ExpandVetoException)1 TreePath (javax.swing.tree.TreePath)1 LabelNode (org.sonarlint.intellij.ui.nodes.LabelNode)1