use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class AbstractInClassConfigurationProducer method setupConfigurationFromContext.
protected boolean setupConfigurationFromContext(T configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
if (isMultipleElementsSelected(context)) {
return false;
}
final Location contextLocation = context.getLocation();
setupConfigurationParamName(configuration, contextLocation);
PsiClass psiClass = null;
PsiElement element = context.getPsiLocation();
while (element != null) {
if (element instanceof PsiClass && isTestClass((PsiClass) element)) {
psiClass = (PsiClass) element;
break;
} else if (element instanceof PsiMember) {
psiClass = contextLocation instanceof MethodLocation ? ((MethodLocation) contextLocation).getContainingClass() : ((PsiMember) element).getContainingClass();
if (isTestClass(psiClass)) {
break;
}
} else if (element instanceof PsiClassOwner) {
final PsiClass[] classes = ((PsiClassOwner) element).getClasses();
if (classes.length == 1) {
psiClass = classes[0];
break;
}
}
element = element.getParent();
}
if (!isTestClass(psiClass))
return false;
PsiElement psiElement = psiClass;
final Project project = context.getProject();
RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(context);
setupConfigurationModule(context, configuration);
final Module originalModule = configuration.getConfigurationModule().getModule();
configuration.beClassConfiguration(psiClass);
PsiMethod method = PsiTreeUtil.getParentOfType(context.getPsiLocation(), PsiMethod.class, false);
while (method != null) {
if (isTestMethod(false, method)) {
configuration.beMethodConfiguration(MethodLocation.elementInClass(method, psiClass));
psiElement = method;
}
method = PsiTreeUtil.getParentOfType(method, PsiMethod.class);
}
configuration.restoreOriginalModule(originalModule);
settings.setName(configuration.getName());
sourceElement.set(psiElement);
return true;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class JavaAwareTestConsoleProperties method getErrorNavigatable.
@Nullable
@Override
public Navigatable getErrorNavigatable(@NotNull Location<?> location, @NotNull String stacktrace) {
//navigate to the first stack trace
final String[] stackTrace = new LineTokenizer(stacktrace).execute();
final PsiLocation<?> psiLocation = location.toPsiLocation();
final PsiClass containingClass = psiLocation.getParentElement(PsiClass.class);
if (containingClass == null)
return null;
final String qualifiedName = containingClass.getQualifiedName();
if (qualifiedName == null)
return null;
String containingMethod = null;
for (Iterator<Location<PsiMethod>> iterator = psiLocation.getAncestors(PsiMethod.class, false); iterator.hasNext(); ) {
final PsiMethod psiMethod = iterator.next().getPsiElement();
if (containingClass.equals(psiMethod.getContainingClass()))
containingMethod = psiMethod.getName();
}
if (containingMethod == null)
return null;
StackTraceLine lastLine = null;
for (String aStackTrace : stackTrace) {
final StackTraceLine line = new StackTraceLine(containingClass.getProject(), aStackTrace);
if (containingMethod.equals(line.getMethodName()) && qualifiedName.equals(line.getClassName())) {
lastLine = line;
break;
}
}
return lastLine != null ? lastLine.getOpenFileDescriptor(containingClass.getContainingFile().getVirtualFile()) : null;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class JarApplicationConfigurationProducer method getJarFileFromContext.
@Nullable
private static VirtualFile getJarFileFromContext(ConfigurationContext context) {
Location location = context.getLocation();
if (location == null)
return null;
VirtualFile file = location.getVirtualFile();
return file != null && FileUtilRt.extensionEquals(file.getName(), "jar") ? file : null;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class PythonRunConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(PythonRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final Location location = context.getLocation();
if (location == null)
return false;
final PsiFile script = location.getPsiElement().getContainingFile();
if (!isAvailable(location, script))
return false;
final VirtualFile vFile = script.getVirtualFile();
if (vFile == null)
return false;
configuration.setScriptName(vFile.getPath());
final VirtualFile parent = vFile.getParent();
if (parent != null) {
configuration.setWorkingDirectory(parent.getPath());
}
final Module module = ModuleUtilCore.findModuleForPsiElement(script);
if (module != null) {
configuration.setUseModuleSdk(true);
configuration.setModule(module);
}
configuration.setName(configuration.suggestedName());
return true;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class PythonRunConfigurationProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(PythonRunConfiguration configuration, ConfigurationContext context) {
final Location location = context.getLocation();
if (location == null)
return false;
final PsiFile script = location.getPsiElement().getContainingFile();
if (!isAvailable(location, script))
return false;
final VirtualFile virtualFile = script.getVirtualFile();
if (virtualFile == null)
return false;
if (virtualFile instanceof LightVirtualFile)
return false;
final String workingDirectory = configuration.getWorkingDirectory();
final String scriptName = configuration.getScriptName();
final String path = virtualFile.getPath();
return scriptName.equals(path) || path.equals(new File(workingDirectory, scriptName).getAbsolutePath());
}
Aggregations