Search in sources :

Example 16 with Location

use of com.intellij.execution.Location in project intellij-community by JetBrains.

the class FileUrlLocationTest method doTest.

private void doTest(int expectedOffset, String filePath, int lineNum) {
    SMTestProxy testProxy = new SMTestProxy("myTest", false, "file://" + filePath + ":" + lineNum);
    testProxy.setLocator(FileUrlProvider.INSTANCE);
    Location location = testProxy.getLocation(getProject(), GlobalSearchScope.allScope(getProject()));
    assertNotNull(location);
    PsiElement element = location.getPsiElement();
    assertNotNull(element);
    assertEquals(expectedOffset, element.getTextOffset());
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Example 17 with Location

use of com.intellij.execution.Location in project intellij-community by JetBrains.

the class TestTreeView method getData.

public Object getData(final String dataId) {
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return this;
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        TreePath[] paths = getSelectionPaths();
        if (paths != null && paths.length > 1) {
            final List<PsiElement> els = new ArrayList<>(paths.length);
            for (TreePath path : paths) {
                if (isPathSelected(path.getParentPath()))
                    continue;
                AbstractTestProxy test = getSelectedTest(path);
                if (test != null) {
                    final PsiElement psiElement = (PsiElement) TestsUIUtil.getData(test, CommonDataKeys.PSI_ELEMENT.getName(), myModel);
                    if (psiElement != null) {
                        els.add(psiElement);
                    }
                }
            }
            return els.isEmpty() ? null : els.toArray(new PsiElement[els.size()]);
        }
    }
    if (Location.DATA_KEYS.is(dataId)) {
        TreePath[] paths = getSelectionPaths();
        if (paths != null && paths.length > 1) {
            final List<Location<?>> locations = new ArrayList<>(paths.length);
            for (TreePath path : paths) {
                if (isPathSelected(path.getParentPath()))
                    continue;
                AbstractTestProxy test = getSelectedTest(path);
                if (test != null) {
                    final Location<?> location = (Location<?>) TestsUIUtil.getData(test, Location.DATA_KEY.getName(), myModel);
                    if (location != null) {
                        locations.add(location);
                    }
                }
            }
            return locations.isEmpty() ? null : locations.toArray(new Location[locations.size()]);
        }
    }
    if (MODEL_DATA_KEY.is(dataId)) {
        return myModel;
    }
    final TreePath selectionPath = getSelectionPath();
    if (selectionPath == null)
        return null;
    final AbstractTestProxy testProxy = getSelectedTest(selectionPath);
    if (testProxy == null)
        return null;
    try {
        return TestsUIUtil.getData(testProxy, dataId, myModel);
    } catch (IndexNotReadyException ignore) {
        return null;
    }
}
Also used : TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Example 18 with Location

use of com.intellij.execution.Location in project intellij-community by JetBrains.

the class TestsUIUtil method getOpenFileDescriptor.

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);
        }
        final OpenFileDescriptor openFileDescriptor = location == null ? null : location.getOpenFileDescriptor();
        if (openFileDescriptor != null && openFileDescriptor.getFile().isValid()) {
            return openFileDescriptor;
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Location(com.intellij.execution.Location)

Example 19 with Location

use of com.intellij.execution.Location in project intellij-community by JetBrains.

the class FileUrlProvider method getLocation.

@NotNull
@Override
public List<Location> getLocation(@NotNull String protocol, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
    if (!URLUtil.FILE_PROTOCOL.equals(protocol)) {
        return Collections.emptyList();
    }
    final String normalizedPath = path.replace(File.separatorChar, '/');
    final int lineNoSeparatorIndex = normalizedPath.lastIndexOf(':');
    final String filePath;
    final int lineNumber;
    // if line is specified
    if (lineNoSeparatorIndex > 3) {
        // on Windows, paths start with /C: and that colon is not a line number separator 
        lineNumber = StringUtil.parseInt(normalizedPath.substring(lineNoSeparatorIndex + 1), -1);
        filePath = normalizedPath.substring(0, lineNoSeparatorIndex);
    } else {
        lineNumber = -1;
        filePath = normalizedPath;
    }
    // Now we should search file with most suitable path
    // here path may be absolute or relative
    final String systemIndependentPath = FileUtil.toSystemIndependentName(filePath);
    final List<VirtualFile> virtualFiles = TestsLocationProviderUtil.findSuitableFilesFor(systemIndependentPath, project);
    if (virtualFiles.isEmpty()) {
        return Collections.emptyList();
    }
    final List<Location> locations = new ArrayList<>(2);
    for (VirtualFile file : virtualFiles) {
        locations.add(createLocationFor(project, file, lineNumber));
    }
    return locations;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with Location

use of com.intellij.execution.Location in project intellij-community by JetBrains.

the class TrackCoverageAction method selectSubCoverage.

private void selectSubCoverage() {
    final CoverageDataManager coverageDataManager = CoverageDataManager.getInstance(myProperties.getProject());
    final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();
    if (currentSuite != null) {
        final AbstractTestProxy test = myModel.getTreeView().getSelectedTest();
        List<String> testMethods = new ArrayList<>();
        if (test != null && !test.isInProgress()) {
            final List<? extends AbstractTestProxy> list = test.getAllTests();
            for (AbstractTestProxy proxy : list) {
                final Location location = proxy.getLocation(myProperties.getProject(), myProperties.getScope());
                if (location != null) {
                    final PsiElement element = location.getPsiElement();
                    final String name = currentSuite.getCoverageEngine().getTestMethodName(element, proxy);
                    if (name != null) {
                        testMethods.add(name);
                    }
                }
            }
        }
        coverageDataManager.selectSubCoverage(currentSuite, testMethods);
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) CoverageDataManager(com.intellij.coverage.CoverageDataManager) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)62 PsiElement (com.intellij.psi.PsiElement)20 PsiClass (com.intellij.psi.PsiClass)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)17 PsiLocation (com.intellij.execution.PsiLocation)16 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)16 Project (com.intellij.openapi.project.Project)15 Module (com.intellij.openapi.module.Module)13 PsiMethod (com.intellij.psi.PsiMethod)11 PsiFile (com.intellij.psi.PsiFile)8 Nullable (org.jetbrains.annotations.Nullable)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3