@Override public boolean iteration() { final CommonProblemDescriptor descriptor = myDescriptors[myCount++]; ProgressIndicator indicator = myTask.getIndicator(); if (indicator != null) { indicator.setFraction((double)myCount / myDescriptors.length); String presentableText = "usages"; if (descriptor instanceof ProblemDescriptor) { final PsiElement psiElement = ((ProblemDescriptor)descriptor).getPsiElement(); if (psiElement != null) { presentableText = SymbolPresentationUtil.getSymbolPresentableText(psiElement); } } indicator.setText("Processing " + presentableText); } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { myDocumentManager.commitAllDocuments(); applyFix(myProject, descriptor); } }); return isDone(); }
@Override public String getFullName(final Object element) { for(ChooseByNameContributor c: getContributors()) { if (c instanceof GotoClassContributor) { String result = ((GotoClassContributor) c).getQualifiedName((NavigationItem) element); if (result != null) { return result; } } } String elementName = getElementName(element); if (elementName == null) return null; if (element instanceof PsiElement) { return SymbolPresentationUtil.getSymbolContainerText((PsiElement)element) + "." + elementName; } return elementName; }
@Override public ItemPresentation getPresentation() { return new ItemPresentationWithSeparator() { @Override public String getPresentableText() { return getText(); } @Override public String getLocationString() { return SymbolPresentationUtil.getFilePathPresentation(getContainingFile()); } @Override public Icon getIcon(boolean open) { return null; } }; }
public void updateByteCode(PsiElement element, ByteCodeViewerComponent component, Content content, final String byteCode) { if (!StringUtil.isEmpty(byteCode)) { component.setText(byteCode, element); } else { PsiElement presentableElement = getContainingClass(element); if (presentableElement == null) { presentableElement = element.getContainingFile(); if (presentableElement == null && element instanceof PsiNamedElement) { presentableElement = element; } if (presentableElement == null) { component.setText("No bytecode found"); return; } } component.setText("No bytecode found for " + SymbolPresentationUtil.getSymbolPresentableText(presentableElement)); } content.setDisplayName(getTitle(element)); }
@Override public boolean iteration() { final CommonProblemDescriptor descriptor = myDescriptors[myCount++]; ProgressIndicator indicator = myTask.getIndicator(); if (indicator != null) { indicator.setFraction((double)myCount / myDescriptors.length); if (descriptor instanceof ProblemDescriptor) { final PsiElement psiElement = ((ProblemDescriptor)descriptor).getPsiElement(); if (psiElement != null) { indicator.setText("Processing " + SymbolPresentationUtil.getSymbolPresentableText(psiElement)); } } } applyFix(myProject, myContext, new CommonProblemDescriptor[]{descriptor}, myIgnoredElements); return isDone(); }
@Override public String getFullName(final Object element) { for(ChooseByNameContributor c: getContributors()) { if (c instanceof GotoClassContributor) { String result = ((GotoClassContributor) c).getQualifiedName((NavigationItem) element); if (result != null) return result; } } if (element instanceof PsiElement) { final PsiElement psiElement = (PsiElement)element; final String containerText = SymbolPresentationUtil.getSymbolContainerText(psiElement); return containerText + "." + getElementName(element); } return getElementName(element); }
private void showSiblings(boolean invokedByShortcut, @NotNull Project project, Editor editor, PsiFile file, boolean invokedFromEditor, @NotNull PsiElement element) { final PsiElement[] impls = getSelfAndImplementations(editor, element, createImplementationsSearcher(), false); final String text = SymbolPresentationUtil.getSymbolPresentableText(element); showImplementations(impls, project, text, editor, file, element, invokedFromEditor, invokedByShortcut); }
public static String getQualifiedNameForClass(PsiClass psiClass) { final String qName = psiClass.getQualifiedName(); if (qName != null) return qName; final String containerText = SymbolPresentationUtil.getSymbolContainerText(psiClass); return containerText + "." + psiClass.getName(); }
protected JTextField createSourceClassField() { JTextField result = new JTextField(); result.setEditable(false); final String qualifiedName = mySourceClass.getQualifiedName(); result.setText(qualifiedName != null ? qualifiedName : SymbolPresentationUtil.getSymbolPresentableText(mySourceClass)); return result; }
@Override protected boolean preprocessUsages(@NotNull final Ref<UsageInfo[]> refUsages) { final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); for (MemberInfo memberInfo : myDelegateMethodInfos) { if (memberInfo.isChecked() && memberInfo.isToAbstract()) { final PsiMember psiMember = memberInfo.getMember(); if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).findDeepestSuperMethods().length > 0) { conflicts.putValue(psiMember, SymbolPresentationUtil.getSymbolPresentableText(psiMember) + " will be deleted. Hierarchy will be broken"); } } } return showConflicts(conflicts, refUsages.get()); }
private void updateElementImplementations(final PsiElement element, final Editor editor, @NotNull Project project, final PsiFile file) { PsiElement[] impls = {}; String text = ""; if (element != null) { // if (element instanceof PsiPackage) return; PsiFile containingFile = element.getContainingFile(); if (containingFile == null || !containingFile.getViewProvider().isPhysical()) return; impls = getSelfAndImplementations(editor, element, createImplementationsSearcher()); text = SymbolPresentationUtil.getSymbolPresentableText(element); } showImplementations(impls, project, text, editor, file, element, false, false); }
private String getSymbolContainerText(String name, PsiElement element) { String text = SymbolPresentationUtil.getSymbolContainerText(element); if (myList.getWidth() == 0) return text; if (text == null) return null; if (text.startsWith("(") && text.endsWith(")")) { text = text.substring(1, text.length()-1); } boolean in = text.startsWith("in "); if (in) text = text.substring(3); final FontMetrics fm = myList.getFontMetrics(myList.getFont()); final int maxWidth = myList.getWidth() - fm.stringWidth(name) - 16 - myRightComponentWidth - 20; String left = in ? "(in " : "("; String right = ")"; if (fm.stringWidth(left + text + right) < maxWidth) return left + text + right; final LinkedList<String> parts = new LinkedList<String>(StringUtil.split(text, ".")); int index; while (parts.size() > 1) { index = parts.size() / 2 - 1; parts.remove(index); if (fm.stringWidth(StringUtil.join(parts, ".") + "...") < maxWidth) { parts.add(index, index == 0 ? "..." : "."); return left + StringUtil.join(parts, ".") + right; } } //todo return left + "..." + right; }
@Override protected void doOKAction() { mySelectedClass = calcSelectedClass(); if (mySelectedClass == null) return; if (!myClassFilter.isAccepted(mySelectedClass)) { Messages.showErrorDialog(myTabbedPane.getComponent(), SymbolPresentationUtil.getSymbolPresentableText(mySelectedClass) + " is not acceptable"); return; } super.doOKAction(); }
public static void checkGutterTargets(final GutterMark gutterMark, final String tooltip, final Icon icon, final String... expectedTargets) { assertNotNull(gutterMark); assertEquals(tooltip, gutterMark.getTooltipText()); assertEquals(icon, gutterMark.getIcon()); final Collection<PsiElement> targetElements; if (gutterMark instanceof LineMarkerInfo.LineMarkerGutterIconRenderer) { final LineMarkerInfo.LineMarkerGutterIconRenderer renderer = UsefulTestCase.assertInstanceOf(gutterMark, LineMarkerInfo.LineMarkerGutterIconRenderer.class); final LineMarkerInfo lineMarkerInfo = renderer.getLineMarkerInfo(); GutterIconNavigationHandler handler = lineMarkerInfo.getNavigationHandler(); if (handler instanceof NavigationGutterIconRenderer) { targetElements = ((NavigationGutterIconRenderer)handler).getTargetElements(); } else { throw new IllegalArgumentException(handler + ": handler not supported"); } } else { throw new IllegalArgumentException(gutterMark.getClass() + ": gutter not supported"); } UsefulTestCase.assertSameElements(ContainerUtil.map(targetElements, new Function<PsiElement, String>() { @Override public String fun(PsiElement element) { return SymbolPresentationUtil.getSymbolPresentableText(element); } }), expectedTargets); }
private void showSiblings(boolean invokedByShortcut, Project project, Editor editor, PsiFile file, boolean invokedFromEditor, PsiElement element) { final PsiElement[] impls = getSelfAndImplementations(editor, element, createImplementationsSearcher(), false); final String text = SymbolPresentationUtil.getSymbolPresentableText(element); showImplementations(impls, project, text, editor, file, element, invokedFromEditor, invokedByShortcut); }
@Override public String getQualifiedName(final NavigationItem item) { if (item instanceof PsiClass) { final PsiClass psiClass = (PsiClass)item; final String qName = psiClass.getQualifiedName(); if (qName != null) return qName; final String containerText = SymbolPresentationUtil.getSymbolContainerText(psiClass); return containerText + "." + psiClass.getName(); } return null; }
@Override protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) { final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); for (MemberInfo memberInfo : myDelegateMethodInfos) { if (memberInfo.isChecked() && memberInfo.isToAbstract()) { final PsiMember psiMember = memberInfo.getMember(); if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).findDeepestSuperMethods().length > 0) { conflicts.putValue(psiMember, SymbolPresentationUtil.getSymbolPresentableText(psiMember) + " will be deleted. Hierarchy will be broken"); } } } return showConflicts(conflicts, refUsages.get()); }
protected void updateElementImplementations(final PsiElement element, final Editor editor, final Project project, final PsiFile file) { PsiElement[] impls = null; String text = ""; if (element != null) { // if (element instanceof PsiPackage) return; PsiFile containingFile = element.getContainingFile(); if (containingFile == null || !containingFile.getViewProvider().isPhysical()) return; impls = getSelfAndImplementations(editor, element, createImplementationsSearcher()); text = SymbolPresentationUtil.getSymbolPresentableText(element); } showImplementations(impls, project, text, editor, file, element, false, false); }
public void updateByteCode(PsiElement element, ByteCodeViewerComponent component, Content content, final String byteCode) { if (!StringUtil.isEmpty(byteCode)) { component.setText(byteCode, element); } else { PsiClass containingClass = getContainingClass(element); PsiFile containingFile = element.getContainingFile(); component.setText("No bytecode found for " + SymbolPresentationUtil.getSymbolPresentableText(containingClass != null ? containingClass : containingFile)); } content.setDisplayName(getTitle(element)); }
@Nullable @Override protected String getContainerText(PsiElement element, String name) { VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element); if(virtualFile == null) { return SymbolPresentationUtil.getSymbolContainerText(element); } else { return "(" + virtualFile.getPath() + ")"; } }
@Override public String getElementText(PsiElement element) { PsiElement map = myMap.fun(element); if(map != null) { return SymbolPresentationUtil.getSymbolPresentableText(map); } return SymbolPresentationUtil.getSymbolPresentableText(element); }
@Override public String getContainerText(PsiElement element, final String name) { PsiElement map = myMap.fun(element); if(map != null) { return SymbolPresentationUtil.getSymbolContainerText(map); } return SymbolPresentationUtil.getSymbolContainerText(element); }
@Nullable @Override protected String getContainerText(PsiElement psiElement, String s) { // relative path else fallback to default name extraction PsiFile containingFile = psiElement.getContainingFile(); String relativePath = VfsUtil.getRelativePath(containingFile.getVirtualFile(), psiElement.getProject().getBaseDir(), '/'); return relativePath != null ? relativePath : SymbolPresentationUtil.getSymbolContainerText(psiElement); }
@Override public String getElementText(PsiElement psiElement) { return StringUtils.abbreviate( SymbolPresentationUtil.getSymbolPresentableText(psiElement), 50 ); }
private void updateElementImplementations(final PsiElement element, final Editor editor, @Nonnull Project project, final PsiFile file) { PsiElement[] impls = {}; String text = ""; if (element != null) { // if (element instanceof PsiPackage) return; PsiFile containingFile = element.getContainingFile(); if (containingFile == null || !containingFile.getViewProvider().isPhysical()) return; impls = getSelfAndImplementations(editor, element, createImplementationsSearcher()); text = SymbolPresentationUtil.getSymbolPresentableText(element); } showImplementations(impls, project, text, editor, file, element, false, false); }
private String getSymbolContainerText(String name, PsiElement element) { String text = SymbolPresentationUtil.getSymbolContainerText(element); if (myList.getWidth() == 0) return text; if (text == null) return null; if (text.startsWith("(") && text.endsWith(")")) { text = text.substring(1, text.length()-1); } boolean in = text.startsWith("in "); if (in) text = text.substring(3); final FontMetrics fm = myList.getFontMetrics(myList.getFont()); final int maxWidth = myList.getWidth() - fm.stringWidth(name) - 16 - myRightComponentWidth - 20; String left = "(" + (in ? "in " : " "); String right = ")"; if (fm.stringWidth(left + text + right) < maxWidth) return left + text + right; final LinkedList<String> parts = new LinkedList<String>(StringUtil.split(text, ".")); int index; while (parts.size() > 1) { index = parts.size() / 2 - 1; parts.remove(index); if (fm.stringWidth(StringUtil.join(parts, ".") + "...") < maxWidth) { parts.add(index, index == 0 ? "..." : "."); return left + StringUtil.join(parts, ".") + right; } } //todo return left + "..." + right; }
public static void checkSuperMethod(@NotNull PsiMethod method, @NotNull String actionString, @NotNull final PsiElementProcessor<PsiMethod> processor, @NotNull Editor editor) { PsiClass aClass = method.getContainingClass(); if (aClass == null) { processor.execute(method); return; } PsiMethod superMethod = method.findDeepestSuperMethod(); if (superMethod == null) { processor.execute(method); return; } final PsiClass containingClass = superMethod.getContainingClass(); if (containingClass == null) { processor.execute(method); return; } if (ApplicationManager.getApplication().isUnitTestMode()) { processor.execute(superMethod); return; } final PsiMethod[] methods = {superMethod, method}; final String renameBase = actionString + " base method"; final String renameCurrent = actionString + " only current method"; final JBList list = new JBList(renameBase, renameCurrent); JBPopupFactory.getInstance().createListPopupBuilder(list) .setTitle(method.getName() + (containingClass.isInterface() && !aClass.isInterface() ? " implements" : " overrides") + " method of " + SymbolPresentationUtil.getSymbolPresentableText(containingClass)) .setMovable(false) .setResizable(false) .setRequestFocus(true) .setItemChoosenCallback(new Runnable() { @Override public void run() { final Object value = list.getSelectedValue(); if (value instanceof String) { processor.execute(methods[value.equals(renameBase) ? 0 : 1]); } } }).createPopup().showInBestPositionFor(editor); }
public void customizeCellRenderer(@NotNull final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { final Object userObject = ((DefaultMutableTreeNode)value).getUserObject(); if (!(userObject instanceof MigrationNode)) return; final TypeMigrationUsageInfo usageInfo = ((MigrationNode)userObject).getInfo(); if (usageInfo != null) { final PsiElement element = usageInfo.getElement(); if (element != null) { PsiElement typeElement = null; if (element instanceof PsiVariable) { typeElement = ((PsiVariable)element).getTypeElement(); } else if (element instanceof PsiMethod) { typeElement = ((PsiMethod)element).getReturnTypeElement(); } if (typeElement == null) typeElement = element; PsiDocumentManager.getInstance(element.getProject()).commitAllDocuments(); final UsagePresentation presentation = UsageInfoToUsageConverter.convert(new PsiElement[]{typeElement}, new UsageInfo(typeElement)).getPresentation(); boolean isPrefix = true; //skip usage position for (TextChunk chunk : presentation.getText()) { if (!isPrefix) append(chunk.getText(), patchAttrs(usageInfo, chunk.getSimpleAttributesIgnoreBackground())); isPrefix = false; } setIcon(presentation.getIcon()); String location; if (element instanceof PsiMember) { location = SymbolPresentationUtil.getSymbolContainerText(element); } else { final PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class); if (member instanceof PsiField) { location = PsiFormatUtil.formatVariable((PsiVariable)member, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_FQ_NAME, PsiSubstitutor.EMPTY); } else if (member instanceof PsiMethod) { location = PsiFormatUtil.formatMethod((PsiMethod)member, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_FQ_NAME, PsiFormatUtilBase.SHOW_TYPE); } else if (member instanceof PsiClass) { location = PsiFormatUtil.formatClass((PsiClass)member, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME); } else { location = null; } if (location != null) location = PsiBundle.message("aux.context.display", location); } if (location != null) { append(location, SimpleTextAttributes.GRAYED_ATTRIBUTES); } } else { append(UsageViewBundle.message("node.invalid"), SimpleTextAttributes.ERROR_ATTRIBUTES); } } }
public void performForContext(@NotNull DataContext dataContext, boolean invokedByShortcut) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return; PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); Editor editor = getEditor(dataContext); PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); boolean isInvokedFromEditor = CommonDataKeys.EDITOR.getData(dataContext) != null; element = getElement(project, file, editor, element); if (element == null && file == null) return; PsiFile containingFile = element != null ? element.getContainingFile() : file; if (containingFile == null || !containingFile.getViewProvider().isPhysical()) return; PsiReference ref = null; if (editor != null) { ref = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()); if (element == null && ref != null) { element = TargetElementUtil.getInstance().adjustReference(ref); } } //check attached sources if any if (element instanceof PsiCompiledElement) { element = element.getNavigationElement(); } String text = ""; PsiElement[] impls = new PsiElement[0]; if (element != null) { //if (element instanceof PsiPackage) return; impls = getSelfAndImplementations(editor, element, createImplementationsSearcher()); text = SymbolPresentationUtil.getSymbolPresentableText(element); } if (impls.length == 0 && ref instanceof PsiPolyVariantReference) { final PsiPolyVariantReference polyReference = (PsiPolyVariantReference)ref; text = polyReference.getRangeInElement().substring(polyReference.getElement().getText()); final ResolveResult[] results = polyReference.multiResolve(false); final List<PsiElement> implsList = new ArrayList<PsiElement>(results.length); for (ResolveResult result : results) { final PsiElement resolvedElement = result.getElement(); if (resolvedElement != null && resolvedElement.isPhysical()) { implsList.add(resolvedElement); } } if (!implsList.isEmpty()) { implsList.toArray( impls = new PsiElement[implsList.size()] ); } } showImplementations(impls, project, text, editor, file, element, isInvokedFromEditor, invokedByShortcut); }
static String getTitle(@NotNull final PsiElement element, final boolean _short) { final String title = SymbolPresentationUtil.getSymbolPresentableText(element); return _short ? title != null ? title : element.getText() : CodeInsightBundle.message("javadoc.info.title", title != null ? title : element.getText()); }