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