Java Code Examples for com.intellij.navigation.ItemPresentation#getPresentableText()

The following examples show how to use com.intellij.navigation.ItemPresentation#getPresentableText() . 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: GotoImplementationHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
protected String getChooserTitle(@Nonnull PsiElement sourceElement, String name, int length, boolean finished) {
  ItemPresentation presentation = ((NavigationItem)sourceElement).getPresentation();
  String fullName;
  if (presentation == null) {
    fullName = name;
  }
  else {
    PsiElement container = getContainer(sourceElement);
    ItemPresentation containerPresentation = container == null || container instanceof PsiFile ? null : ((NavigationItem)container).getPresentation();
    String containerText = containerPresentation == null ? null : containerPresentation.getPresentableText();
    fullName = (containerText == null ? "" : containerText+".") + presentation.getPresentableText();
  }
  return CodeInsightBundle.message("goto.implementation.chooserTitle", fullName, length, finished ? "" : " so far");
}
 
Example 2
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String doGenerateInfo(@Nonnull PsiElement element) {
  if (element instanceof PsiFile) {
    final VirtualFile virtualFile = ((PsiFile)element).getVirtualFile();
    if (virtualFile != null) {
      return virtualFile.getPresentableUrl();
    }
  }

  String info = getQuickNavigateInfo(element);
  if (info != null) {
    return info;
  }

  if (element instanceof NavigationItem) {
    final ItemPresentation presentation = ((NavigationItem)element).getPresentation();
    if (presentation != null) {
      return presentation.getPresentableText();
    }
  }

  return null;
}
 
Example 3
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void update(PsiElement element) {
  if (element != null && element.isValid()) {
    final ItemPresentation presentation = ((NavigationItem)element).getPresentation();
    myIcon = presentation == null ? null : presentation.getIcon();
    myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
    if (myIcon == null) {
      if (element instanceof PsiMetaOwner) {
        final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
        final PsiMetaData metaData = psiMetaOwner.getMetaData();
        if (metaData instanceof PsiPresentableMetaData) {
          final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData)metaData;
          if (myIcon == null) myIcon = psiPresentableMetaData.getIcon();
        }
      }
      else if (element instanceof PsiFile) {
        final PsiFile psiFile = (PsiFile)element;
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null) {
          myIcon = VirtualFilePresentation.getIcon(virtualFile);
        }
      }
    }
  }
}
 
Example 4
Source File: HaxeLookupElementFactory.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Nullable
public static LookupElementBuilder create(@NotNull HaxeModel model, @Nullable String alias) {
  PsiElement basePsi = model.getBasePsi();
  HaxeNamedComponent namedComponent = getNamedComponent(basePsi);

  if (namedComponent == null) return null;

  String name = StringUtil.defaultIfEmpty(alias, model.getName());
  String presentableText = null;
  String tailText = getParentPath(model);
  Icon icon = null;

  ItemPresentation presentation = namedComponent.getPresentation();
  if (presentation != null) {
    icon = presentation.getIcon(false);
    presentableText = presentation.getPresentableText();
  }

  LookupElementBuilder lookupElement = LookupElementBuilder.create(basePsi, name);

  if (presentableText != null) {
    if (alias != null && presentableText.startsWith(model.getName())) {
      presentableText = presentableText.replace(model.getName(), alias);
    }
    lookupElement = lookupElement.withPresentableText(presentableText);
  }

  if (icon != null) lookupElement = lookupElement.withIcon(icon);

  if (tailText != null) {
    if (alias != null) {
      tailText = HaxeBundle.message("haxe.lookup.alias", tailText + "." + model.getName());
    }
    tailText = " " + tailText;
    lookupElement = lookupElement.withTailText(tailText, true);
  }

  return lookupElement;
}
 
Example 5
Source File: HaxeLookupElement.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void renderElement(LookupElementPresentation presentation) {
  final ItemPresentation myComponentNamePresentation = myComponentName.getPresentation();
  if (myComponentNamePresentation == null) {
    presentation.setItemText(getLookupString());
    return;
  }

  String presentableText = myComponentNamePresentation.getPresentableText();

  // Check for members: methods and fields
  HaxeBaseMemberModel model = HaxeBaseMemberModel.fromPsi(myComponentName);

  if (model != null) {
    // TODO: Specialization support required
    presentableText = model.getPresentableText(context);

    // Check deprecated modifiers
    if (model instanceof HaxeMemberModel && ((HaxeMemberModel)model).getModifiers().hasModifier(HaxePsiModifier.DEPRECATED)) {
      presentation.setStrikeout(true);
    }

    // Check for non-inherited members to highlight them as intellij-java does
    // @TODO: Self members should be displayed first!
    if (leftReference != null) {
      if (model.getDeclaringClass().getPsi() == leftReference.getHaxeClass()) {
        presentation.setItemTextBold(true);
      }
    }
  }

  presentation.setItemText(presentableText);
  presentation.setIcon(myComponentNamePresentation.getIcon(true));
  final String pkg = myComponentNamePresentation.getLocationString();
  if (StringUtil.isNotEmpty(pkg)) {
    presentation.setTailText(" " + pkg, true);
  }
}
 
Example 6
Source File: ImplementationViewComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getPresentation(PsiElement element) {
  if (element instanceof NavigationItem) {
    final ItemPresentation presentation = ((NavigationItem)element).getPresentation();
    if (presentation != null) {
      return presentation.getPresentableText();
    }
  }

  if (element instanceof PsiNamedElement) return ((PsiNamedElement)element).getName();
  return null;
}
 
Example 7
Source File: SymbolPresentationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String getSymbolPresentableText(@Nonnull PsiElement element) {
  if (element instanceof NavigationItem) {
    final ItemPresentation presentation = ((NavigationItem)element).getPresentation();
    if (presentation != null){
      return presentation.getPresentableText();
    }
  }

  if (element instanceof PsiNamedElement) return ((PsiNamedElement)element).getName();
  return element.getText();
}