use of com.intellij.ide.util.MethodCellRenderer in project intellij-community by JetBrains.
the class CreateParameterForFieldIntention method performForField.
private static void performForField(PsiElement element, final Project project, Editor editor, List<GrMethod> constructors) {
final GrField field = PsiTreeUtil.getParentOfType(element, GrField.class);
if (constructors.isEmpty())
return;
if (ApplicationManager.getApplication().isUnitTestMode()) {
for (GrMethod constructor : constructors) {
addParameter(field, constructor, project);
}
return;
}
final JList list = new JBList(constructors.toArray(new GrMethod[constructors.size()]));
list.setCellRenderer(new MethodCellRenderer(true));
new PopupChooserBuilder(list).setTitle(GroovyIntentionsBundle.message("create.parameter.for.field.intention.name")).setMovable(true).setItemChoosenCallback(() -> {
final Object[] selectedValues = list.getSelectedValues();
Arrays.sort(selectedValues, (o1, o2) -> ((GrMethod) o2).getParameterList().getParametersCount() - ((GrMethod) o1).getParameterList().getParametersCount());
CommandProcessor.getInstance().executeCommand(project, () -> {
for (Object selectedValue : selectedValues) {
LOG.assertTrue(((GrMethod) selectedValue).isValid());
addParameter(field, ((GrMethod) selectedValue), project);
}
}, GroovyIntentionsBundle.message("create.parameter.for.field.intention.name"), null);
}).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.ide.util.MethodCellRenderer in project intellij-community by JetBrains.
the class ShowSiblingsAction method performForContext.
@Override
public void performForContext(@NotNull DataContext dataContext, final boolean invokedByShortcut) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
if (project == null)
return;
PsiDocumentManager.getInstance(project).commitAllDocuments();
final Editor editor = getEditor(dataContext);
PsiElement element = getElement(project, file, editor, CommonDataKeys.PSI_ELEMENT.getData(dataContext));
if (element == null && file == null)
return;
PsiFile containingFile = element != null ? element.getContainingFile() : file;
if (containingFile == null || !containingFile.getViewProvider().isPhysical())
return;
if (editor != null) {
PsiReference ref = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (element == null && ref != null) {
element = TargetElementUtil.getInstance().adjustReference(ref);
}
}
final PsiElement[] superElements = findSuperElements(element);
if (superElements.length == 0)
return;
final boolean isMethod = superElements[0] instanceof PsiMethod;
NavigatablePsiElement[] navigatablePsiElements = ContainerUtil.findAllAsArray(superElements, NavigatablePsiElement.class);
final JBPopup popup = PsiElementListNavigator.navigateOrCreatePopup(navigatablePsiElements, "Choose super " + (isMethod ? "method" : "class or interface"), "Super " + (isMethod ? "methods" : "classes/interfaces"), isMethod ? new MethodCellRenderer(false) : new PsiClassListCellRenderer(), null, objects -> showSiblings(invokedByShortcut, project, editor, file, editor != null, (PsiElement) objects[0]));
if (popup != null) {
if (editor != null) {
popup.showInBestPositionFor(editor);
} else {
popup.showCenteredInCurrentWindow(project);
}
}
}
use of com.intellij.ide.util.MethodCellRenderer in project intellij-community by JetBrains.
the class JavaGotoSuperHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(GotoSuperAction.FEATURE_ID);
int offset = editor.getCaretModel().getOffset();
PsiElement[] superElements = findSuperElements(file, offset);
if (superElements.length == 0)
return;
if (superElements.length == 1) {
PsiElement superElement = superElements[0].getNavigationElement();
final PsiFile containingFile = superElement.getContainingFile();
if (containingFile == null)
return;
final VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile == null)
return;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile, superElement.getTextOffset());
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
} else if (superElements[0] instanceof PsiMethod) {
boolean showMethodNames = !PsiUtil.allMethodsHaveSameSignature((PsiMethod[]) superElements);
PsiElementListNavigator.openTargets(editor, (PsiMethod[]) superElements, CodeInsightBundle.message("goto.super.method.chooser.title"), CodeInsightBundle.message("goto.super.method.findUsages.title", ((PsiMethod) superElements[0]).getName()), new MethodCellRenderer(showMethodNames));
} else {
NavigationUtil.getPsiElementPopup(superElements, CodeInsightBundle.message("goto.super.class.chooser.title")).showInBestPositionFor(editor);
}
}
use of com.intellij.ide.util.MethodCellRenderer in project intellij-community by JetBrains.
the class GroovyStaticImportMethodFix method chooseAndImport.
private void chooseAndImport(Editor editor) {
final JList list = new JBList(getCandidates().toArray(new PsiMethod[getCandidates().size()]));
list.setCellRenderer(new MethodCellRenderer(true));
new PopupChooserBuilder(list).setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")).setMovable(true).setItemChoosenCallback(() -> {
PsiMethod selectedValue = (PsiMethod) list.getSelectedValue();
if (selectedValue == null)
return;
LOG.assertTrue(selectedValue.isValid());
doImport(selectedValue);
}).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.ide.util.MethodCellRenderer in project intellij-community by JetBrains.
the class CopyAbstractMethodImplementationHandler method invoke.
public void invoke() {
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> searchExistingImplementations()), CodeInsightBundle.message("searching.for.implementations"), false, myProject);
if (mySourceMethods.isEmpty()) {
Messages.showErrorDialog(myProject, CodeInsightBundle.message("copy.abstract.method.no.existing.implementations.found"), CodeInsightBundle.message("copy.abstract.method.title"));
return;
}
if (mySourceMethods.size() == 1) {
copyImplementation(mySourceMethods.get(0));
} else {
Collections.sort(mySourceMethods, (o1, o2) -> {
PsiClass c1 = o1.getContainingClass();
PsiClass c2 = o2.getContainingClass();
return Comparing.compare(c1.getName(), c2.getName());
});
final PsiMethod[] methodArray = mySourceMethods.toArray(new PsiMethod[mySourceMethods.size()]);
final JList list = new JBList(methodArray);
list.setCellRenderer(new MethodCellRenderer(true));
final Runnable runnable = () -> {
int index = list.getSelectedIndex();
if (index < 0)
return;
PsiMethod element = (PsiMethod) list.getSelectedValue();
copyImplementation(element);
};
new PopupChooserBuilder(list).setTitle(CodeInsightBundle.message("copy.abstract.method.popup.title")).setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(myEditor);
}
}
Aggregations