Example usage for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor

List of usage examples for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor

Introduction

In this page you can find the example usage for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor.

Prototype

public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int offset) 

Source Link

Usage

From source file:org.sonarlint.intellij.ui.SonarLintIssuesPanel.java

License:Open Source License

private OccurenceInfo occurrence(IssueNode node) {
    if (node == null) {
        return null;
    }/*from  w w w  .  java  2 s. c  om*/

    TreePath path = new TreePath(node.getPath());
    tree.getSelectionModel().setSelectionPath(path);
    tree.scrollPathToVisible(path);

    RangeMarker range = node.issue().range();
    int startOffset = (range != null) ? range.getStartOffset() : 0;
    return new OccurenceInfo(
            new OpenFileDescriptor(project, node.issue().psiFile().getVirtualFile(), startOffset), -1, -1);
}

From source file:org.sonarlint.intellij.ui.tree.FlowsTree.java

License:Open Source License

private void navigateToSelected() {
    DefaultMutableTreeNode node = getSelectedNode();
    if (!(node instanceof LocationNode)) {
        return;//from   w  w w .ja v a  2  s  .  c om
    }
    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);
    }
}

From source file:org.sonarlint.intellij.ui.tree.IssueTree.java

License:Open Source License

@Nullable
@Override/*from w ww  .  j  av a2 s  .  c  o m*/
public Object getData(@NonNls String dataId) {
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        TreePath path = getSelectionPath();
        if (path == null) {
            return null;
        }
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (!(node instanceof IssueNode)) {
            return null;
        }
        IssuePointer issue = ((IssueNode) node).issue();
        int offset;

        RangeMarker range = issue.range();
        if (range != null) {
            offset = range.getStartOffset();
        } else {
            offset = 0;
        }
        return new OpenFileDescriptor(project, issue.psiFile().getVirtualFile(), offset);
    }

    return null;
}

From source file:ru.crazyproger.plugins.webtoper.nls.codeinsight.CreateNlsQuickFix.java

License:Apache License

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final String nameText = nlsName;
    VirtualFile[] nlsRoots = NlsUtils.getNlsRoots(module);
    assert nlsRoots.length > 0 : "Nls files without nls roots should not exists";

    final VirtualFile nlsRoot = nlsRoots[0]; // todo #WT-24
    assert nlsRoot != null;
    assert nlsRoot.isValid();

    VirtualFile child = nlsRoot.findFileByRelativePath(NlsUtils.nlsNameToPath(nameText, "/"));
    assert child == null : "QuickFix called on unresolved name, but file exists!";

    final String[] chunks = NlsUtils.nlsNameToPathChunks(nameText);
    if (ArrayUtils.isEmpty(chunks))
        return;//from  ww  w.j a  v a 2  s  .c o  m

    VirtualFile createdFile = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
        @Override
        public VirtualFile compute() {
            try {
                return createNlsByPath(nlsRoot, chunks);
            } catch (IOException e) {
                LOG.error("On create nls ''{0}''", e, nameText);
            }
            return null;
        }
    });

    if (createdFile != null) {
        OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, createdFile, 0);
        FileEditorManager.getInstance(project).openTextEditor(openFileDescriptor, true);
    }
}