com.intellij.psi.presentation.java.SymbolPresentationUtil Java Examples

The following examples show how to use com.intellij.psi.presentation.java.SymbolPresentationUtil. 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: TestToolWindow.java    From intellij-reference-diagram with Apache License 2.0 6 votes vote down vote up
private static TestToolWindow createViewTab(Project project, PsiElement baseElement) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_ID);
    if (toolWindow == null) {
        toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_ID,
                true,
                ToolWindowAnchor.BOTTOM);
    }
    final TestToolWindow view = new TestToolWindow(project);
    ToolWindow finalToolWindow = toolWindow;
    toolWindow.activate(() -> {
        final String text = SymbolPresentationUtil.getSymbolPresentableText(baseElement);
        final ContentImpl content = new ContentImpl(view, "to " + text, true);
        finalToolWindow.getContentManager().addContent(content);
        finalToolWindow.getContentManager().setSelectedContent(content, true);
    });
    return view;
}
 
Example #2
Source File: GotoSymbolModel2.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: QuickFixAction.java    From consulo with Apache License 2.0 6 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);
    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();
}
 
Example #4
Source File: AbstractTreeClassChooserDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #5
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 #6
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 #7
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public String getElementText(PsiElement psiElement) {
    return StringUtils.abbreviate(
        SymbolPresentationUtil.getSymbolPresentableText(psiElement),
        50
    );
}
 
Example #8
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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(), ProjectUtil.getProjectDir(psiElement), '/');
    return relativePath != null ? relativePath : SymbolPresentationUtil.getSymbolContainerText(psiElement);
}
 
Example #9
Source File: JavaExtractSuperBaseDialog.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: PsiMappedElementListCellRender.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
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 #12
Source File: PartialTypeCollector.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@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() + ")";
	}
}
 
Example #13
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 #14
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 #15
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 #16
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);
}
 
Example #17
Source File: DefaultPsiElementCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String getContainerText(PsiElement element, final String name){
  return SymbolPresentationUtil.getSymbolContainerText(element);
}
 
Example #18
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();
}