Search in sources :

Example 36 with Location

use of com.intellij.execution.Location in project android by JetBrains.

the class AndroidTestConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(AndroidTestRunConfiguration configuration, ConfigurationContext context) {
    Location location = context.getLocation();
    Module contextModule = AndroidUtils.getAndroidModule(context);
    if (contextModule == null || location == null) {
        return false;
    }
    location = JavaExecutionUtil.stepIntoSingleClass(location);
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    VirtualFile directoryOrFile = element instanceof PsiDirectory ? ((PsiDirectory) element).getVirtualFile() : element.getContainingFile().getVirtualFile();
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(contextModule);
    if (directoryOrFile != null && testScopes != null && !testScopes.isAndroidTestSource(directoryOrFile)) {
        return false;
    }
    PsiPackage psiPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
    String packageName = psiPackage == null ? null : psiPackage.getQualifiedName();
    PsiClass elementClass = getParentOfType(element, PsiClass.class, false);
    String className = elementClass == null ? null : elementClass.getQualifiedName();
    PsiMethod elementMethod = getParentOfType(element, PsiMethod.class, false);
    String methodName = elementMethod == null ? null : elementMethod.getName();
    Module moduleInConfig = configuration.getConfigurationModule().getModule();
    if (!Comparing.equal(contextModule, moduleInConfig)) {
        return false;
    }
    switch(configuration.TESTING_TYPE) {
        case AndroidTestRunConfiguration.TEST_ALL_IN_MODULE:
            return psiPackage != null && packageName.isEmpty();
        case AndroidTestRunConfiguration.TEST_ALL_IN_PACKAGE:
            return packageName != null && packageName.equals(configuration.PACKAGE_NAME);
        case AndroidTestRunConfiguration.TEST_CLASS:
            return elementMethod == null && className != null && className.equals(configuration.CLASS_NAME);
        case AndroidTestRunConfiguration.TEST_METHOD:
            return methodName != null && methodName.equals(configuration.METHOD_NAME) && className != null && className.equals(configuration.CLASS_NAME);
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Example 37 with Location

use of com.intellij.execution.Location in project android by JetBrains.

the class TestMethodAndroidConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    Location<PsiMethod> methodLocation = getTestMethod(contextLocation);
    if (methodLocation == null)
        return false;
    if (contextLocation instanceof PsiMemberParameterizedLocation) {
        final String paramSetName = ((PsiMemberParameterizedLocation) contextLocation).getParamSetName();
        if (paramSetName != null) {
            configuration.setProgramParameters(paramSetName);
        }
        PsiClass containingClass = ((PsiMemberParameterizedLocation) contextLocation).getContainingClass();
        if (containingClass != null) {
            methodLocation = MethodLocation.elementInClass(methodLocation.getPsiElement(), containingClass);
        }
    }
    sourceElement.set(methodLocation.getPsiElement());
    setupConfigurationModule(context, configuration);
    final Module originalModule = configuration.getConfigurationModule().getModule();
    configuration.beMethodConfiguration(methodLocation);
    configuration.restoreOriginalModule(originalModule);
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
    configuration.setForkMode(JUnitConfiguration.FORK_NONE);
    return true;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Example 38 with Location

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

the class CfmlRunConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(CfmlRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location location = context.getLocation();
    if (!(location instanceof PsiLocation))
        return false;
    final VirtualFile file;
    PsiElement element = location.getPsiElement();
    final PsiFile containingFile = element.getContainingFile();
    if (isValid(containingFile)) {
        file = containingFile.getVirtualFile();
        sourceElement.set(containingFile);
    } else {
        return false;
    }
    if (!FileTypeManager.getInstance().isFileOfType(file, ScratchFileType.INSTANCE)) {
        final VirtualFile root = ProjectRootManager.getInstance(element.getProject()).getFileIndex().getContentRootForFile(file);
        if (root == null)
            return false;
    }
    if (configuration == null) {
        return false;
    }
    CfmlRunnerParameters params = configuration.getRunnerParameters();
    String urlStr = configuration.getRunnerParameters().getUrl();
    String serverUrl;
    if (!urlStr.isEmpty()) {
        //generated from default run configuration
        try {
            URL url = new URL(urlStr);
            serverUrl = url.getProtocol() + "://" + url.getAuthority();
        } catch (MalformedURLException e) {
            LOG.error(CfmlBundle.message("cfml.producer.error.url", urlStr));
            return false;
        }
    } else {
        // if default configuration is not defined
        serverUrl = DEFAULT_HOST;
        configuration.setFromDefaultHost(true);
    }
    String path = buildPageUrl(context, file);
    //check that serverUrl ends with '/' and fix it if neccessary
    if (StringUtil.endsWith(serverUrl, "/") && !StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + path);
    } else if (!StringUtil.endsWith(serverUrl, "/") && !StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + "/" + path);
    } else if (!StringUtil.endsWith(serverUrl, "/") && StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + path);
    } else if (StringUtil.endsWith(serverUrl, "/") && StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + path.substring(1, path.length()));
    }
    configuration.setName(generateName(containingFile));
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) PsiLocation(com.intellij.execution.PsiLocation) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) URL(java.net.URL) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location)

Example 39 with Location

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

the class DartTestLocationProviderTest method doTest.

private void doTest(@NotNull final String locationHint, @NotNull final String fileContents) {
    final int caretOffset = fileContents.indexOf("<caret>");
    assertTrue(caretOffset != -1);
    final String realContents = fileContents.substring(0, caretOffset) + fileContents.substring(caretOffset + "<caret>".length());
    myFixture.configureByText("test.dart", realContents);
    final PsiFile file = myFixture.getFile();
    final PsiElement elementAtOffset = file.findElementAt(caretOffset);
    final PsiElement targetId = elementAtOffset == null ? null : elementAtOffset.getParent();
    final List<Location> locations = DartTestLocationProvider.INSTANCE.getLocationForTest(file, locationHint);
    assertEquals(1, locations.size());
    final Location location = locations.get(0);
    final PsiElement element = location.getPsiElement();
    final DartId foundId = PsiTreeUtil.findChildOfType(element, DartId.class);
    assertEquals(targetId, foundId);
}
Also used : PsiFile(com.intellij.psi.PsiFile) DartId(com.jetbrains.lang.dart.psi.DartId) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Example 40 with Location

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

the class CucumberJavaRunConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(CucumberJavaRunConfiguration runConfiguration, ConfigurationContext context) {
    final Location location = JavaExecutionUtil.stepIntoSingleClass(context.getLocation());
    if (location == null) {
        return false;
    }
    final VirtualFile fileToRun = getFileToRun(context);
    if (fileToRun == null) {
        return false;
    }
    if (!fileToRun.getPath().equals(runConfiguration.getFilePath())) {
        return false;
    }
    if (!Comparing.strEqual(getNameFilter(context), runConfiguration.getNameFilter())) {
        return false;
    }
    final Module configurationModule = runConfiguration.getConfigurationModule().getModule();
    if (!Comparing.equal(location.getModule(), configurationModule)) {
        return false;
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)64 PsiElement (com.intellij.psi.PsiElement)21 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