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());
}
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;
}
}
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;
}
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;
}
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);
}
}
Aggregations