use of com.intellij.execution.PsiLocation in project intellij-community by JetBrains.
the class TestLocationDataRule method getLocation.
@Nullable
private static Location getLocation(Project project, String fileName, String nameWithoutExtension, PsiClass aClass) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, TestDataPath.class.getName());
if (annotation != null) {
final Location parameterizedLocation = PsiMemberParameterizedLocation.getParameterizedLocation(aClass, "[" + fileName + "]", Parameterized.class.getName());
if (parameterizedLocation != null) {
return parameterizedLocation;
}
if (StringUtil.isJavaIdentifier(nameWithoutExtension)) {
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
PsiMethod method = aClass.findMethodBySignature(elementFactory.createMethod("test" + nameWithoutExtension, PsiType.VOID), true);
if (method != null) {
return MethodLocation.elementInClass(method, aClass);
}
method = aClass.findMethodBySignature(elementFactory.createMethod("test" + StringUtil.capitalize(nameWithoutExtension), PsiType.VOID), true);
if (method != null) {
return MethodLocation.elementInClass(method, aClass);
}
}
return new PsiLocation<PsiElement>(project, aClass);
}
return null;
}
use of com.intellij.execution.PsiLocation in project intellij-community by JetBrains.
the class ConfigurationsTest method testReuseOrCreateNewConfiguration.
@Test
public void testReuseOrCreateNewConfiguration() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final TestNGConfiguration configuration = createConfiguration(project);
final TestNGConfigurationType type = (TestNGConfigurationType) configuration.getFactory().getType();
//class config
configuration.beClassConfiguration(psiClass);
PsiMethod testMethod = findTestMethod(psiClass);
Assert.assertTrue(type.isConfigurationByLocation(configuration, new PsiLocation(project, psiClass)));
Assert.assertFalse(type.isConfigurationByLocation(configuration, new PsiLocation(project, testMethod)));
//method config
configuration.beMethodConfiguration(new PsiLocation<>(project, testMethod));
Assert.assertTrue(type.isConfigurationByLocation(configuration, new PsiLocation(project, testMethod)));
Assert.assertFalse(type.isConfigurationByLocation(configuration, new PsiLocation(project, psiClass)));
}
use of com.intellij.execution.PsiLocation in project intellij-community by JetBrains.
the class JavaAwareTestConsoleProperties method getErrorNavigatable.
@Nullable
@Override
public Navigatable getErrorNavigatable(@NotNull Location<?> location, @NotNull String stacktrace) {
//navigate to the first stack trace
final String[] stackTrace = new LineTokenizer(stacktrace).execute();
final PsiLocation<?> psiLocation = location.toPsiLocation();
final PsiClass containingClass = psiLocation.getParentElement(PsiClass.class);
if (containingClass == null)
return null;
final String qualifiedName = containingClass.getQualifiedName();
if (qualifiedName == null)
return null;
String containingMethod = null;
for (Iterator<Location<PsiMethod>> iterator = psiLocation.getAncestors(PsiMethod.class, false); iterator.hasNext(); ) {
final PsiMethod psiMethod = iterator.next().getPsiElement();
if (containingClass.equals(psiMethod.getContainingClass()))
containingMethod = psiMethod.getName();
}
if (containingMethod == null)
return null;
StackTraceLine lastLine = null;
for (String aStackTrace : stackTrace) {
final StackTraceLine line = new StackTraceLine(containingClass.getProject(), aStackTrace);
if (containingMethod.equals(line.getMethodName()) && qualifiedName.equals(line.getClassName())) {
lastLine = line;
break;
}
}
return lastLine != null ? lastLine.getOpenFileDescriptor(containingClass.getContainingFile().getVirtualFile()) : null;
}
use of com.intellij.execution.PsiLocation in project intellij-community by JetBrains.
the class PythonUnitTestUtil method findLocations.
public static List<Location> findLocations(@NotNull final Project project, @NotNull String fileName, @Nullable String className, @Nullable String methodName) {
if (fileName.contains("%")) {
fileName = fileName.substring(0, fileName.lastIndexOf("%"));
}
final List<Location> locations = new ArrayList<>();
if (methodName == null && className == null) {
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(fileName);
if (virtualFile == null)
return locations;
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile != null) {
locations.add(new PsiLocation<>(project, psiFile));
}
}
if (className != null) {
for (PyClass cls : PyClassNameIndex.find(className, project, false)) {
ProgressManager.checkCanceled();
final PsiFile containingFile = cls.getContainingFile();
final VirtualFile virtualFile = containingFile.getVirtualFile();
final String clsFileName = virtualFile == null ? containingFile.getName() : virtualFile.getPath();
final String clsFileNameWithoutExt = FileUtil.getNameWithoutExtension(clsFileName);
if (!clsFileNameWithoutExt.endsWith(fileName) && !fileName.equals(clsFileName)) {
continue;
}
if (methodName == null) {
locations.add(new PsiLocation<>(project, cls));
} else {
final PyFunction method = cls.findMethodByName(methodName, true, null);
if (method == null) {
continue;
}
locations.add(new PyPsiLocationWithFixedClass(project, method, cls));
}
}
} else if (methodName != null) {
for (PyFunction function : PyFunctionNameIndex.find(methodName, project)) {
ProgressManager.checkCanceled();
if (function.getContainingClass() == null) {
final PsiFile containingFile = function.getContainingFile();
final VirtualFile virtualFile = containingFile.getVirtualFile();
final String clsFileName = virtualFile == null ? containingFile.getName() : virtualFile.getPath();
final String clsFileNameWithoutExt = FileUtil.getNameWithoutExtension(clsFileName);
if (!clsFileNameWithoutExt.endsWith(fileName)) {
continue;
}
locations.add(new PsiLocation<>(project, function));
}
}
}
return locations;
}
Aggregations