use of com.intellij.execution.Location in project intellij-plugins by JetBrains.
the class BndRunConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(BndRunConfigurationBase configuration, ConfigurationContext context, Ref<PsiElement> source) {
Location location = context.getLocation();
if (location != null) {
VirtualFile file = location.getVirtualFile();
if (file != null && !file.isDirectory()) {
String extension = file.getExtension();
if (BndFileType.BND_RUN_EXT.equals(extension) || BndFileType.BND_EXT.equals(extension)) {
Boolean hasTestCases = BndLaunchUtil.hasTestCases(file.getPath());
if (hasTestCases == Boolean.FALSE && configuration instanceof BndRunConfigurationBase.Launch || hasTestCases == Boolean.TRUE && configuration instanceof BndRunConfigurationBase.Test) {
configuration.setName(context.getModule().getName());
configuration.bndRunFile = file.getPath();
return true;
}
}
}
}
return false;
}
use of com.intellij.execution.Location in project Intellij-Plugin by getgauge.
the class GaugeExecutionProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context) {
if (!(configuration.getType() instanceof GaugeRunTaskConfigurationType))
return false;
Location location = context.getLocation();
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context.getDataContext());
if (location == null || location.getVirtualFile() == null || element == null)
return false;
if (!isInSpecScope(context.getPsiLocation()))
return false;
String specsToExecute = ((GaugeRunConfiguration) configuration).getSpecsToExecute();
return specsToExecute != null && (specsToExecute.equals(location.getVirtualFile().getPath()));
}
use of com.intellij.execution.Location in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestLocator method getLocation.
@NotNull
@Override
public List<Location> getLocation(@NotNull String protocolId, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
if (PROTOCOL.equals(protocolId)) {
IdFilter idFilter = GoIdFilter.getTestsFilter(project);
List<String> locationDataItems = StringUtil.split(path, ".");
// Location is a function name, e.g. `TestCheckItOut`
if (locationDataItems.size() == 1) {
return ContainerUtil.mapNotNull(GoFunctionIndex.find(path, project, scope, idFilter), function -> PsiLocation.fromPsiElement(project, function));
}
// Location is a method name, e.g. `FooSuite.TestCheckItOut`
if (locationDataItems.size() == 2) {
List<Location> locations = ContainerUtil.newArrayList();
for (GoTypeSpec typeSpec : GoTypesIndex.find(locationDataItems.get(0), project, scope, idFilter)) {
for (GoMethodDeclaration method : typeSpec.getMethods()) {
if (locationDataItems.get(1).equals(method.getName())) {
ContainerUtil.addIfNotNull(locations, PsiLocation.fromPsiElement(method));
}
}
}
return locations;
}
} else if (SUITE_PROTOCOL.equals(protocolId)) {
IdFilter idFilter = GoIdFilter.getTestsFilter(project);
return ContainerUtil.mapNotNull(GoTypesIndex.find(path, project, scope, idFilter), spec -> PsiLocation.fromPsiElement(project, spec));
} else {
return Collections.emptyList();
}
throw new RuntimeException("Unsupported location: " + path);
}
use of com.intellij.execution.Location in project android by JetBrains.
the class AndroidConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(AndroidRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
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;
}
sourceElement.set(activity);
configuration.setLaunchActivity(activityName);
configuration.setName(JavaExecutionUtil.getPresentableClassName(activityName));
setupConfigurationModule(context, configuration);
final TargetSelectionMode targetSelectionMode = AndroidUtils.getDefaultTargetSelectionMode(context.getModule(), AndroidRunConfigurationType.getInstance(), AndroidTestRunConfigurationType.getInstance());
if (targetSelectionMode != null) {
configuration.getDeployTargetContext().setTargetSelectionMode(targetSelectionMode);
}
return true;
}
use of com.intellij.execution.Location in project android by JetBrains.
the class AndroidJUnitConfigurations method isFromContext.
// Copy of JUnitConfigurationProducer#isConfigurationFromContext using AndroidJUnitConfigurationType instead of JUnitConfigurationType
public static boolean isFromContext(@NotNull JUnitConfiguration unitConfiguration, @NotNull ConfigurationContext context, @NotNull ConfigurationFactory configurationFactory) {
if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
return false;
}
RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(AndroidJUnitConfigurationType.getInstance());
Location contextLocation = context.getLocation();
String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null;
assert contextLocation != null;
Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
if (location == null) {
return false;
}
PsiElement element = location.getPsiElement();
PsiClass testClass = getTestClass(element);
PsiMethod testMethod = getTestMethod(element, false);
PsiPackage testPackage;
if (element instanceof PsiPackage) {
testPackage = (PsiPackage) element;
} else {
if (element instanceof PsiDirectory) {
testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element));
} else {
testPackage = null;
}
}
PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null;
RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()).getConfigurationTemplate(configurationFactory);
Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule();
String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null;
if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) {
return false;
}
if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) {
return false;
}
TestObject testobject = unitConfiguration.getTestObject();
if (testobject != null) {
if (testobject.isConfiguredByElement(unitConfiguration, testClass, testMethod, testPackage, testDir)) {
Module configurationModule = unitConfiguration.getConfigurationModule().getModule();
if (Comparing.equal(location.getModule(), configurationModule)) {
return true;
}
if (Comparing.equal(predefinedModule, configurationModule)) {
return true;
}
}
}
return false;
}
Aggregations