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

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

Introduction

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

Prototype

@NotNull
    public VirtualFile getFile() 

Source Link

Usage

From source file:com.android.tools.idea.gradle.project.sync.issues.UnresolvedDependenciesReporterTest.java

License:Apache License

public void testReportWithRegularJavaLibrary() throws Exception {
    loadSimpleApplication();/*  w  w w .ja  v  a 2  s  .  c  o m*/
    mySyncMessagesStub.clearReportedMessages();

    when(mySyncIssue.getData()).thenReturn("com.google.guava:guava:19.0");

    Module appModule = myModules.getAppModule();
    VirtualFile buildFile = getGradleBuildFile(appModule);
    myReporter.report(mySyncIssue, appModule, buildFile);

    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    assertThat(message.getText()).hasLength(1);

    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Unresolved dependencies")
            .hasMessageLine("Failed to resolve: com.google.guava:guava:19.0", 0);
    // @formatter:on

    assertThat(message.getNavigatable()).isInstanceOf(OpenFileDescriptor.class);
    OpenFileDescriptor navigatable = (OpenFileDescriptor) message.getNavigatable();
    assertEquals(buildFile, navigatable.getFile());

    PositionInFile position = message.getPosition();
    assertNotNull(position);
    assertSame(buildFile, position.file);
}

From source file:com.goide.runconfig.GoConsoleFilterTest.java

License:Apache License

private void doFileLineTest(@Nonnull String line, int startOffset, int endOffset, String targetPath,
        int targetLine, int targetColumn) {
    Filter.Result result = myFilter.applyFilter(line, line.length());
    assertNotNull(result);/*  w  w  w  . j av a 2 s. com*/
    HyperlinkInfo info = assertResultAndGetHyperlink(result, startOffset, endOffset);
    assertInstanceOf(info, OpenFileHyperlinkInfo.class);
    OpenFileDescriptor fileDescriptor = ((OpenFileHyperlinkInfo) info).getDescriptor();
    assertNotNull(fileDescriptor);
    assertEquals(targetPath, fileDescriptor.getFile().getPath());
    assertEquals("line", targetLine, fileDescriptor.getLine() + 1);
    assertEquals("column", targetColumn, fileDescriptor.getColumn() + 1);
}

From source file:com.google.idea.blaze.android.project.BlazeBuildSystemServiceTest.java

License:Open Source License

@Test
public void testAddDependencyWithBuildTargetPsi() throws Exception {
    PsiElement buildTargetPsi = mock(PsiElement.class);
    PsiFile psiFile = mock(PsiFile.class);

    BuildReferenceManager buildReferenceManager = BuildReferenceManager.getInstance(project);
    when(buildReferenceManager.resolveLabel(new Label("//foo:bar"))).thenReturn(buildTargetPsi);
    when(buildTargetPsi.getContainingFile()).thenReturn(psiFile);
    when(buildTargetPsi.getTextOffset()).thenReturn(1337);

    VirtualFile buildFile = TempFileSystem.getInstance().findFileByPath("/foo/BUILD");
    assertThat(buildFile).isNotNull();//from w  w w.ja v a  2  s.c  o  m
    when(psiFile.getVirtualFile()).thenReturn(buildFile);

    String dependency = "com.android.foo:bar"; // Doesn't matter.

    service.addDependency(module, dependency);

    ArgumentCaptor<OpenFileDescriptor> descriptorCaptor = ArgumentCaptor.forClass(OpenFileDescriptor.class);
    verify(FileEditorManager.getInstance(project)).openTextEditor(descriptorCaptor.capture(), eq(true));
    OpenFileDescriptor descriptor = descriptorCaptor.getValue();
    assertThat(descriptor.getProject()).isEqualTo(project);
    assertThat(descriptor.getFile()).isEqualTo(buildFile);
    assertThat(descriptor.getOffset()).isEqualTo(1337);
    verifyNoMoreInteractions(FileEditorManager.getInstance(project));
}

From source file:com.intellij.execution.filters.OpenFileHyperlinkInfo.java

License:Apache License

public OpenFileHyperlinkInfo(@NotNull OpenFileDescriptor descriptor) {
    this(descriptor.getProject(), descriptor.getFile(), descriptor.getLine(), descriptor.getColumn());
}

From source file:com.intellij.execution.impl.ConsoleViewImpl.java

License:Apache License

@Override
public Object getData(final String dataId) {
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        if (myEditor == null) {
            return null;
        }//from   w ww  .j  a va2s. co  m
        final LogicalPosition pos = myEditor.getCaretModel().getLogicalPosition();
        final HyperlinkInfo info = myHyperlinks.getHyperlinkInfoByLineAndCol(pos.line, pos.column);
        final OpenFileDescriptor openFileDescriptor = info instanceof FileHyperlinkInfo
                ? ((FileHyperlinkInfo) info).getDescriptor()
                : null;
        if (openFileDescriptor == null || !openFileDescriptor.getFile().isValid()) {
            return null;
        }
        return openFileDescriptor;
    }

    if (CommonDataKeys.EDITOR.is(dataId)) {
        return myEditor;
    }
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return myHelpId;
    }
    if (LangDataKeys.CONSOLE_VIEW.is(dataId)) {
        return this;
    }
    return null;
}

From source file:com.intellij.execution.testframework.export.TestResultsXmlFormatter.java

License:Apache License

private void writeOutput(ConsoleViewContentType type, StringBuilder text, Filter filter) throws SAXException {
    StringBuilder output = new StringBuilder();
    StringTokenizer t = new StringTokenizer(text.toString(), "\n");
    while (t.hasMoreTokens()) {
        String line = StringUtil.escapeXml(t.nextToken()) + "\n";
        Filter.Result result = null;//filter.applyFilter(line, line.length());
        if (result != null && result.hyperlinkInfo instanceof OpenFileHyperlinkInfo) {
            output.append(line.substring(0, result.highlightStartOffset));
            OpenFileDescriptor descriptor = ((OpenFileHyperlinkInfo) result.hyperlinkInfo).getDescriptor();
            output.append("<a href=\"javascript://\" onclick=\"Activator.doOpen('file?file=");
            output.append(descriptor.getFile().getPresentableUrl());
            output.append("&line=");
            output.append(descriptor.getLine());
            output.append("')\">");
            output.append(line.substring(result.highlightStartOffset, result.highlightEndOffset));
            output.append("</a>");
            output.append(line.substring(result.highlightEndOffset));
        } else {//from  w ww.j a v a2 s  .c om
            output.append(line);
        }
    }

    Map<String, String> a = new HashMap<String, String>();
    a.put(ATTR_OUTPUT_TYPE, getTypeString(type));
    startElement(ELEM_OUTPUT, a);
    writeText(output.toString());
    text.delete(0, text.length());
    endElement(ELEM_OUTPUT);
}

From source file:com.intellij.execution.testframework.TestsUIUtil.java

License:Apache License

private static Navigatable getOpenFileDescriptor(final AbstractTestProxy proxy,
        final TestConsoleProperties testConsoleProperties, final boolean openFailureLine) {
    final Project project = testConsoleProperties.getProject();

    if (proxy != null) {
        final Location location = proxy.getLocation(project, testConsoleProperties.getScope());
        if (openFailureLine) {
            return proxy.getDescriptor(location, testConsoleProperties);
        }//w ww.  j a  va  2s . co m
        final OpenFileDescriptor openFileDescriptor = location == null ? null
                : location.getOpenFileDescriptor();
        if (openFileDescriptor != null && openFileDescriptor.getFile().isValid()) {
            return openFileDescriptor;
        }
    }
    return null;
}

From source file:com.intellij.ide.impl.dataRules.NavigatableRule.java

License:Apache License

@Override
public Object getData(DataProvider dataProvider) {
    final Navigatable navigatable = PlatformDataKeys.NAVIGATABLE.getData(dataProvider);
    if (navigatable != null && navigatable instanceof OpenFileDescriptor) {
        final OpenFileDescriptor openFileDescriptor = (OpenFileDescriptor) navigatable;

        if (openFileDescriptor.getFile().isValid()) {
            return openFileDescriptor;
        }/*from  w w w. j av  a  2 s  . co  m*/
    }
    final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataProvider);
    if (element instanceof Navigatable) {
        return element;
    }
    if (element != null) {
        return EditSourceUtil.getDescriptor(element);
    }

    final Object selection = PlatformDataKeys.SELECTED_ITEM.getData(dataProvider);
    if (selection instanceof Navigatable) {
        return selection;
    }

    return null;
}

From source file:com.intellij.lang.ant.config.execution.TreeView.java

License:Apache License

@Nullable
public Object getData(Key<?> dataId) {
    if (PlatformDataKeys.NAVIGATABLE == dataId) {
        MessageNode item = getSelectedItem();
        if (item == null)
            return null;
        if (isValid(item.getFile())) {
            return new OpenFileDescriptor(myProject, item.getFile(), item.getOffset());
        }//  ww w .ja  va  2 s.c  o m
        if (item.getType() == AntBuildMessageView.MessageType.TARGET) {
            final OpenFileDescriptor descriptor = getDescriptorForTargetNode(item);
            if (descriptor != null && isValid(descriptor.getFile())) {
                return descriptor;
            }
        }
        if (item.getType() == AntBuildMessageView.MessageType.TASK) {
            final OpenFileDescriptor descriptor = getDescriptorForTaskNode(item);
            if (descriptor != null && isValid(descriptor.getFile())) {
                return descriptor;
            }
        }
    }
    return null;
}

From source file:com.intellij.lang.ant.config.explorer.AntExplorer.java

License:Apache License

@Nullable
public Object getData(@NonNls Key<?> dataId) {
    if (PlatformDataKeys.NAVIGATABLE == dataId) {
        final AntBuildFile buildFile = getCurrentBuildFile();
        if (buildFile == null) {
            return null;
        }/*from w ww  .  j a  v  a2s . c o m*/
        final VirtualFile file = buildFile.getVirtualFile();
        if (file == null) {
            return null;
        }
        final TreePath treePath = myTree.getLeadSelectionPath();
        if (treePath == null) {
            return null;
        }
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        if (node == null) {
            return null;
        }
        if (node.getUserObject() instanceof AntTargetNodeDescriptor) {
            final AntTargetNodeDescriptor targetNodeDescriptor = (AntTargetNodeDescriptor) node.getUserObject();
            final AntBuildTargetBase buildTarget = targetNodeDescriptor.getTarget();
            final OpenFileDescriptor descriptor = buildTarget.getOpenFileDescriptor();
            if (descriptor != null) {
                final VirtualFile descriptorFile = descriptor.getFile();
                if (descriptorFile.isValid()) {
                    return descriptor;
                }
            }
        }
        if (file.isValid()) {
            return new OpenFileDescriptor(myProject, file);
        }
    } else if (PlatformDataKeys.TREE_EXPANDER == dataId) {
        return myProject != null ? myTreeExpander : null;
    } else if (PlatformDataKeys.VIRTUAL_FILE_ARRAY == dataId) {
        final TreePath[] paths = myTree.getSelectionPaths();
        if (paths == null) {
            return null;
        }
        final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>();
        for (final TreePath path : paths) {
            for (DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
                    .getLastPathComponent(); node != null; node = (DefaultMutableTreeNode) node.getParent()) {
                final Object userObject = node.getUserObject();
                if (!(userObject instanceof AntBuildFileNodeDescriptor)) {
                    continue;
                }
                final AntBuildFile buildFile = ((AntBuildFileNodeDescriptor) userObject).getBuildFile();
                if (buildFile != null) {
                    final VirtualFile virtualFile = buildFile.getVirtualFile();
                    if (virtualFile != null && virtualFile.isValid()) {
                        result.add(virtualFile);
                    }
                }
                break;
            }
        }
        if (result.size() == 0) {
            return null;
        }
        return VfsUtil.toVirtualFileArray(result);
    }
    return super.getData(dataId);
}