use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class JavaTestLocator method collectMethodNavigatables.
private static List<Location> collectMethodNavigatables(@NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope, String paramName) {
List<Location> results = Collections.emptyList();
String className = StringUtil.getPackageName(path);
if (!StringUtil.isEmpty(className)) {
String methodName = StringUtil.getShortName(path);
PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className, null, true, scope);
if (aClass != null) {
results = ContainerUtil.newSmartList();
if (methodName.trim().equals(aClass.getName())) {
results.add(createClassNavigatable(paramName, aClass));
} else {
PsiMethod[] methods = aClass.findMethodsByName(methodName.trim(), true);
if (methods.length > 0) {
for (PsiMethod method : methods) {
results.add(paramName != null ? new PsiMemberParameterizedLocation(project, method, aClass, paramName) : MethodLocation.elementInClass(method, aClass));
}
}
}
}
}
return results;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class JavaTestLocator method getLocation.
@NotNull
@Override
public List<Location> getLocation(@NotNull String protocol, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
List<Location> results = Collections.emptyList();
String paramName = null;
int idx = path.indexOf('[');
if (idx >= 0) {
paramName = path.substring(idx);
path = path.substring(0, idx);
}
if (SUITE_PROTOCOL.equals(protocol)) {
path = StringUtil.trimEnd(path, ".");
PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), path, null, true, scope);
if (aClass != null) {
results = ContainerUtil.newSmartList();
results.add(createClassNavigatable(paramName, aClass));
} else {
results = collectMethodNavigatables(path, project, scope, paramName);
}
} else if (TEST_PROTOCOL.equals(protocol)) {
results = collectMethodNavigatables(path, project, scope, paramName);
}
return results;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class DeadTestsCleaner method processUrl.
private void processUrl(final String url) {
final Ref<Location> locationRef = Ref.create();
ApplicationManager.getApplication().runReadAction(() -> {
Location location = myTestLocator.getLocation(url);
locationRef.set(location);
});
if (locationRef.get() == null) {
myTestStorage.removeState(url);
}
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class RecentTestRunnerImpl method run.
private void run(@NotNull String url) {
Location location = myTestLocator.getLocation(url);
if (location == null) {
return;
}
DataContext data = new DataContext() {
@Nullable
@Override
public Object getData(@NonNls String dataId) {
if (Location.DATA_KEY.is(dataId)) {
return location;
}
return null;
}
};
myCurrentAction.actionPerformed(AnActionEvent.createFromAnAction(myCurrentAction, null, "", data));
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class InheritorChooser method runMethodInAbstractClass.
public boolean runMethodInAbstractClass(final ConfigurationContext context, final Runnable performRunnable, final PsiMethod psiMethod, final PsiClass containingClass, final Condition<PsiClass> acceptAbstractCondition) {
if (containingClass != null && acceptAbstractCondition.value(containingClass)) {
final Location location = context.getLocation();
if (location instanceof MethodLocation) {
final PsiClass aClass = ((MethodLocation) location).getContainingClass();
if (aClass != null && !aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return false;
}
} else if (location instanceof PsiMemberParameterizedLocation) {
return false;
}
final List<PsiClass> classes = new ArrayList<>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final boolean isJUnit5 = ReadAction.compute(() -> JUnitUtil.isJUnit5(containingClass));
ClassInheritorsSearch.search(containingClass).forEach(aClass -> {
if (isJUnit5 && JUnitUtil.isJUnit5TestClass(aClass, true) || PsiClassUtil.isRunnableClass(aClass, true, true)) {
classes.add(aClass);
}
return true;
});
}, "Search for " + containingClass.getQualifiedName() + " inheritors", true, containingClass.getProject())) {
return true;
}
if (classes.size() == 1) {
runForClass(classes.get(0), psiMethod, context, performRunnable);
return true;
}
if (classes.isEmpty())
return false;
final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context.getDataContext());
if (fileEditor instanceof TextEditor) {
final Document document = ((TextEditor) fileEditor).getEditor().getDocument();
final PsiFile containingFile = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(document);
if (containingFile instanceof PsiClassOwner) {
final List<PsiClass> psiClasses = new ArrayList<>(Arrays.asList(((PsiClassOwner) containingFile).getClasses()));
psiClasses.retainAll(classes);
if (psiClasses.size() == 1) {
runForClass(psiClasses.get(0), psiMethod, context, performRunnable);
return true;
}
}
}
final int numberOfInheritors = classes.size();
final PsiClassListCellRenderer renderer = new PsiClassListCellRenderer() {
@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
renderer.append("All (" + numberOfInheritors + ")");
return true;
}
return super.customizeNonPsiElementLeftRenderer(renderer, list, value, index, selected, hasFocus);
}
};
Collections.sort(classes, renderer.getComparator());
//suggest to run all inherited tests
classes.add(0, null);
final JBList list = new JBList(classes);
list.setCellRenderer(renderer);
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose executable classes to run " + (psiMethod != null ? psiMethod.getName() : containingClass.getName())).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
final Object[] values = list.getSelectedValues();
if (values == null)
return;
chooseAndPerform(values, psiMethod, context, performRunnable, classes);
}).createPopup().showInBestPositionFor(context.getDataContext());
return true;
}
return false;
}
Aggregations