Search in sources :

Example 26 with Location

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

the class TestMethodGradleConfigurationProducer method doSetupConfigurationFromContext.

@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    PsiMethod psiMethod = getPsiMethodForLocation(contextLocation);
    if (psiMethod == null)
        return false;
    sourceElement.set(psiMethod);
    final PsiClass containingClass = psiMethod.getContainingClass();
    if (containingClass == null)
        return false;
    if (context.getModule() == null)
        return false;
    if (!applyTestMethodConfiguration(configuration, context, psiMethod, containingClass))
        return false;
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
    return true;
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) GradleRunnerUtil.getMethodLocation(org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation) Location(com.intellij.execution.Location)

Example 27 with Location

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

the class AndroidConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(AndroidRunConfiguration configuration, ConfigurationContext context) {
    final Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    final PsiClass activity = getActivityClass(location, context);
    if (activity == null) {
        return false;
    }
    final String activityName = activity.getQualifiedName();
    if (activityName == null) {
        return false;
    }
    final Module contextModule = AndroidUtils.getAndroidModule(context);
    final Module confModule = configuration.getConfigurationModule().getModule();
    return Comparing.equal(contextModule, confModule) && configuration.isLaunchingActivity(activityName);
}
Also used : PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Example 28 with Location

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

the class TestPatternConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(AndroidJUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    LinkedHashSet<String> classes = new LinkedHashSet<String>();
    PsiElement element = checkPatterns(context, classes);
    if (element == null) {
        return false;
    }
    sourceElement.set(element);
    JUnitConfiguration.Data data = configuration.getPersistentData();
    data.setPatterns(classes);
    data.TEST_OBJECT = JUnitConfiguration.TEST_PATTERN;
    data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
    configuration.setGeneratedName();
    Location contextLocation = context.getLocation();
    if (contextLocation instanceof PsiMemberParameterizedLocation) {
        String paramSetName = ((PsiMemberParameterizedLocation) contextLocation).getParamSetName();
        if (paramSetName != null) {
            configuration.setProgramParameters(paramSetName);
        }
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Example 29 with Location

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

the class AndroidTestConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(AndroidTestRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Module module = AndroidUtils.getAndroidModule(context);
    if (module == null) {
        return false;
    }
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    location = JavaExecutionUtil.stepIntoSingleClass(location);
    if (location == null) {
        return false;
    }
    final PsiElement element = location.getPsiElement();
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return false;
    }
    // TODO: Resolve direct AndroidGradleModel dep (b/22596984)
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel != null) {
        // Only suggest the android test run configuration if it makes sense for the selected test artifact.
        if (androidModel.getAndroidTestArtifactInSelectedVariant() == null) {
            return false;
        }
        TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
        if (testScopes == null) {
            return false;
        }
        VirtualFile virtualFile = null;
        if (element instanceof PsiDirectory) {
            virtualFile = ((PsiDirectory) element).getVirtualFile();
        } else {
            PsiFile psiFile = element.getContainingFile();
            if (psiFile != null) {
                virtualFile = psiFile.getVirtualFile();
            }
        }
        if (virtualFile == null) {
            return false;
        }
        if (!testScopes.isAndroidTestSource(virtualFile)) {
            return false;
        }
    }
    setupInstrumentationTestRunner(configuration, facet);
    if (setupAllInPackageConfiguration(configuration, element, context, sourceElement)) {
        return true;
    }
    if (setupMethodConfiguration(configuration, element, context, sourceElement)) {
        return true;
    }
    return setupClassConfiguration(configuration, element, context, sourceElement);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Location(com.intellij.execution.Location)

Example 30 with Location

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

the class CfmlRunConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(CfmlRunConfiguration configuration, ConfigurationContext context) {
    final Location location = context.getLocation();
    if (location == null)
        return false;
    final PsiElement anchor = location.getPsiElement();
    final PsiFile containingFile = anchor.getContainingFile();
    if (isValid(containingFile)) {
        final String path;
        path = buildPageUrl(context, containingFile.getVirtualFile());
        URL url;
        final String urlFromRunnerParameters = configuration.getRunnerParameters().getUrl();
        if (urlFromRunnerParameters.isEmpty())
            return false;
        try {
            url = new URL(urlFromRunnerParameters);
            return StringUtil.equals(url.getPath(), path);
        } catch (MalformedURLException e) {
            LOG.error(CfmlBundle.message("cfml.producer.error.url", urlFromRunnerParameters));
        }
    }
    return false;
}
Also used : MalformedURLException(java.net.MalformedURLException) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) URL(java.net.URL) PsiLocation(com.intellij.execution.PsiLocation) 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