public static String getElementDescription(String prefix, PsiElement element, String suffix) { PsiElement elementToSlice = element; if(element instanceof PsiReferenceExpression) { elementToSlice = ((PsiReferenceExpression) element).resolve(); } if(elementToSlice == null) { elementToSlice = element; } String desc = ElementDescriptionUtil.getElementDescription(elementToSlice, RefactoringDescriptionLocation.WITHOUT_PARENT); return "<html><head>" + UIUtil.getCssFontDeclaration(getLabelFont()) + "</head><body>" + (prefix == null ? "" : prefix) + StringUtil.first(desc, 100, true) + (suffix == null ? "" : suffix) + "</body></html>"; }
@NotNull @Override public String getType(@NotNull PsiElement element) { return ElementDescriptionUtil.getElementDescription(element, UsageViewTypeLocation.INSTANCE); }
@NotNull @Override public String getDescriptiveName(@NotNull PsiElement element) { return ElementDescriptionUtil.getElementDescription(element, UsageViewLongNameLocation.INSTANCE); }
@NotNull @Override public String getNodeText(@NotNull PsiElement element, boolean useFullName) { return ElementDescriptionUtil.getElementDescription(element, UsageViewNodeTextLocation.INSTANCE); }
private static void highlightPsiElement(@NotNull Project project, @NotNull PsiElement psiElement, @NotNull Editor editor, @NotNull PsiFile file, boolean shouldClear) { final PsiElement target = SmartPointerManager.getInstance(psiElement.getProject()) .createSmartPsiElementPointer(psiElement) .getElement(); if (target == null) { return; } if (file instanceof PsiCompiledFile) { file = ((PsiCompiledFile) file).getDecompiledPsiFile(); } final Couple<List<TextRange>> usages = getUsages(target, file); final List<TextRange> readRanges = usages.first; final List<TextRange> writeRanges = usages.second; final HighlightManager highlightManager = HighlightManager.getInstance(project); if (shouldClear) { clearHighlights(editor, highlightManager, readRanges); clearHighlights(editor, highlightManager, writeRanges); WindowManager.getInstance().getStatusBar(project).setInfo(""); return; } // TODO: 10/02/2017 pass target? final TextAttributes ta = TextAttributesFactory.getInstance().get(); final Color scrollMarkColor; if (ta.getErrorStripeColor() != null) { scrollMarkColor = ta.getErrorStripeColor(); } else if (ta.getBackgroundColor() != null) { scrollMarkColor = ta.getBackgroundColor().darker(); } else { scrollMarkColor = null; } final String elementName = ElementDescriptionUtil.getElementDescription(target, HighlightUsagesDescriptionLocation.INSTANCE); // TODO: 06/02/2017 highlight write and read access ArrayList<RangeHighlighter> highlighters = new ArrayList<>(); highlight(highlightManager, readRanges, editor, ta, highlighters, scrollMarkColor); highlight(highlightManager, writeRanges, editor, ta, highlighters, scrollMarkColor); final Document doc = editor.getDocument(); for (RangeHighlighter highlighter : highlighters) { highlighter.setErrorStripeTooltip( HighlightHandlerBase.getLineTextErrorStripeTooltip(doc, highlighter.getStartOffset(), true)); } int refCount = readRanges.size() + writeRanges.size(); String msg; if (refCount > 0) { msg = MessageFormat.format("{0} {0, choice, 1#usage|2#usages} of {1} found", refCount, elementName); } else { msg = MessageFormat.format("No usages of {0} found", elementName); } WindowManager.getInstance().getStatusBar(project).setInfo(msg); }
public static String createNodeText(PsiElement element) { return ElementDescriptionUtil.getElementDescription(element, UsageViewNodeTextLocation.INSTANCE); }
public static String getShortName(final PsiElement psiElement) { LOG.assertTrue(psiElement.isValid(), psiElement); return ElementDescriptionUtil.getElementDescription(psiElement, UsageViewShortNameLocation.INSTANCE); }
public static String getLongName(final PsiElement psiElement) { LOG.assertTrue(psiElement.isValid(), psiElement); return ElementDescriptionUtil.getElementDescription(psiElement, UsageViewLongNameLocation.INSTANCE); }
public static String getType(@NotNull PsiElement psiElement) { return ElementDescriptionUtil.getElementDescription(psiElement, UsageViewTypeLocation.INSTANCE); }
public static String getDescription(@NotNull PsiElement element, boolean includeParent) { return ElementDescriptionUtil.getElementDescription(element, includeParent ? RefactoringDescriptionLocation.WITH_PARENT : RefactoringDescriptionLocation.WITHOUT_PARENT); }
@NotNull @Override public String getType(PsiElement psiElement) { return ElementDescriptionUtil.getElementDescription(psiElement, UsageViewTypeLocation.INSTANCE); }
@NotNull @Override public String getDescriptiveName(@NotNull PsiElement psiElement) { return ElementDescriptionUtil.getElementDescription(psiElement, UsageViewLongNameLocation.INSTANCE); }
@NotNull @Override public String getNodeText(@NotNull PsiElement psiElement, boolean b) { return ElementDescriptionUtil.getElementDescription(psiElement, UsageViewNodeTextLocation.INSTANCE); }
public static String getType(@Nonnull PsiElement psiElement) { return ElementDescriptionUtil.getElementDescription(psiElement, UsageViewTypeLocation.INSTANCE); }
public static String getDescription(@Nonnull PsiElement element, boolean includeParent) { return ElementDescriptionUtil.getElementDescription(element, includeParent ? RefactoringDescriptionLocation.WITH_PARENT : RefactoringDescriptionLocation.WITHOUT_PARENT); }