use of com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes 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.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes in project android by JetBrains.
the class AndroidTestConsoleProperties method initScope.
@NotNull
@Override
protected GlobalSearchScope initScope() {
GlobalSearchScope scope = super.initScope();
Module[] modules = ((ModuleRunProfile) getConfiguration()).getModules();
for (Module each : modules) {
// UnitTest scope in each module is excluded from the scope used to find JUnitTests
TestArtifactSearchScopes testArtifactSearchScopes = TestArtifactSearchScopes.get(each);
if (testArtifactSearchScopes != null) {
scope = scope.intersectWith(GlobalSearchScope.notScope(testArtifactSearchScopes.getUnitTestSourceScope()));
}
}
return scope;
}
Aggregations