Search in sources :

Example 6 with PsiLocation

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;
}
Also used : TestDataPath(com.intellij.testFramework.TestDataPath) Parameterized(com.intellij.testFramework.Parameterized) PsiLocation(com.intellij.execution.PsiLocation) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) PsiLocation(com.intellij.execution.PsiLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PsiLocation

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)));
}
Also used : Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiLocation(com.intellij.execution.PsiLocation) Test(org.testng.annotations.Test)

Example 8 with PsiLocation

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;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) StackTraceLine(com.intellij.execution.stacktrace.StackTraceLine) LineTokenizer(com.intellij.openapi.diff.LineTokenizer) PsiClass(com.intellij.psi.PsiClass) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PsiLocation

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) PsiLocation(com.intellij.execution.PsiLocation) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location)

Aggregations

PsiLocation (com.intellij.execution.PsiLocation)9 Location (com.intellij.execution.Location)6 PsiClass (com.intellij.psi.PsiClass)4 PsiFile (com.intellij.psi.PsiFile)3 PsiMethod (com.intellij.psi.PsiMethod)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.testng.annotations.Test)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)1 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)1 StackTraceLine (com.intellij.execution.stacktrace.StackTraceLine)1 LineTokenizer (com.intellij.openapi.diff.LineTokenizer)1 Document (com.intellij.openapi.editor.Document)1 MapDataContext (com.intellij.testFramework.MapDataContext)1