Java Code Examples for com.intellij.psi.presentation.java.SymbolPresentationUtil#getSymbolPresentableText()

The following examples show how to use com.intellij.psi.presentation.java.SymbolPresentationUtil#getSymbolPresentableText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiMappedElementListCellRender.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public String getElementText(PsiElement element)
{
	PsiElement map = myMap.fun(element);
	if(map != null)
	{
		return SymbolPresentationUtil.getSymbolPresentableText(map);
	}
	return SymbolPresentationUtil.getSymbolPresentableText(element);
}
 
Example 2
Source File: PerformFixesModalTask.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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);
  }

  final boolean[] runInReadAction = {false};
  final QuickFix[] fixes = descriptor.getFixes();
  if (fixes != null) {
    for (QuickFix fix : fixes) {
      if (!fix.startInWriteAction()) {
        runInReadAction[0] = true;
      } else {
        runInReadAction[0] = false;
        break;
      }
    }
  }

  ApplicationManager.getApplication().runWriteAction(() -> {
    myDocumentManager.commitAllDocuments();
    if (!runInReadAction[0]) {
      applyFix(myProject, descriptor);
    }
  });
  if (runInReadAction[0]) {
    applyFix(myProject, descriptor);
  }
  return isDone();
}
 
Example 3
Source File: ShowImplementationsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: PartialTypeCollector.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public String getElementText(PsiElement element)
{
	VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
	return virtualFile == null ? SymbolPresentationUtil.getSymbolPresentableText(element) : virtualFile.getName();
}
 
Example 5
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public String getElementText(PsiElement psiElement) {
    String symbolPresentableText = SymbolPresentationUtil.getSymbolPresentableText(psiElement);
    return StringUtils.abbreviate(symbolPresentableText, 50);
}
 
Example 6
Source File: ShowImplementationsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void performForContext(@Nonnull DataContext dataContext, boolean invokedByShortcut) {
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) return;
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  PsiFile file = dataContext.getData(CommonDataKeys.PSI_FILE);
  Editor editor = getEditor(dataContext);

  PsiElement element = dataContext.getData(CommonDataKeys.PSI_ELEMENT);
  boolean isInvokedFromEditor = dataContext.getData(CommonDataKeys.EDITOR) != 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.adjustReference(ref);
    }
  }

  //check attached sources if any
  if (element instanceof PsiCompiledElement) {
    element = element.getNavigationElement();
  }

  String text = "";
  PsiElement[] impls = PsiElement.EMPTY_ARRAY;
  if (element != null) {
    impls = getSelfAndImplementations(editor, element, createImplementationsSearcher());
    text = SymbolPresentationUtil.getSymbolPresentableText(element);
  }

  if (impls.length == 0 && ref instanceof PsiPolyVariantReference) {
    final PsiPolyVariantReference polyReference = (PsiPolyVariantReference)ref;
    PsiElement refElement = polyReference.getElement();
    TextRange rangeInElement = polyReference.getRangeInElement();
    String refElementText = refElement.getText();
    LOG.assertTrue(rangeInElement.getEndOffset() <= refElementText.length(), "Ref:" + polyReference + "; refElement: " + refElement + "; refText:" + refElementText);
    text = rangeInElement.substring(refElementText);
    final ResolveResult[] results = polyReference.multiResolve(false);
    final List<PsiElement> implsList = new ArrayList<>(results.length);

    for (ResolveResult result : results) {
      final PsiElement resolvedElement = result.getElement();

      if (resolvedElement != null && resolvedElement.isPhysical()) {
        implsList.add(resolvedElement);
      }
    }

    if (!implsList.isEmpty()) {
      impls = implsList.toArray(new PsiElement[implsList.size()]);
    }
  }


  showImplementations(impls, project, text, editor, file, element, isInvokedFromEditor, invokedByShortcut);
}
 
Example 7
Source File: DocumentationManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
static String getTitle(@Nonnull PsiElement element, boolean isShort) {
  String title = SymbolPresentationUtil.getSymbolPresentableText(element);
  return isShort ? title != null ? title : element.getText() : CodeInsightBundle.message("javadoc.info.title", title != null ? title : element.getText());
}
 
Example 8
Source File: DefaultPsiElementCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String getElementText(PsiElement element){
  return SymbolPresentationUtil.getSymbolPresentableText(element);
}