com.intellij.navigation.ItemPresentation Java Examples

The following examples show how to use com.intellij.navigation.ItemPresentation. 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: ThriftSubDeclarationPresentationProvider.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
@Override
public ItemPresentation getPresentation(final ThriftSubDeclaration item) {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return item.getName();
    }

    @Nullable
    @Override
    public String getLocationString() {
      ThriftTopLevelDeclaration topLevelDeclaration = PsiTreeUtil.getParentOfType(item, ThriftTopLevelDeclaration.class, true);
      return topLevelDeclaration != null ? topLevelDeclaration.getName() : item.getContainingFile().getName();
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return item.getIcon(Iconable.ICON_FLAG_VISIBILITY);
    }
  };
}
 
Example #2
Source File: HaxeNamedElementNode.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String buildPresentationText(HaxeNamedComponent haxeNamedComponent) {
  final ItemPresentation presentation = haxeNamedComponent.getPresentation();
  if (presentation == null) {
    return haxeNamedComponent.getName();
  }
  final StringBuilder result = new StringBuilder();
  if (haxeNamedComponent instanceof HaxeClass) {
    result.append(haxeNamedComponent.getName());
    final String location = presentation.getLocationString();
    if (location != null && !location.isEmpty()) {
      result.append(" ").append(location);
    }
  }
  else {
    result.append(presentation.getPresentableText());
  }
  return result.toString();
}
 
Example #3
Source File: PsiFunctorImpl.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            return getName();
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @NotNull
        @Override
        public Icon getIcon(boolean unused) {
            return ORIcons.FUNCTOR;
        }
    };
}
 
Example #4
Source File: PsiInnerModuleImpl.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            return getName();
        }

        @NotNull
        @Override
        public String getLocationString() {
            return "";
        }

        @NotNull
        @Override
        public Icon getIcon(boolean unused) {
            return isModuleType() ? ORIcons.MODULE_TYPE : ORIcons.MODULE;
        }
    };
}
 
Example #5
Source File: PsiExceptionImpl.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            return getName();
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @NotNull
        @Override
        public Icon getIcon(boolean unused) {
            return ORIcons.EXCEPTION;
        }
    };
}
 
Example #6
Source File: CustomRegionTreeElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return myProvider.getPlaceholderText(myStartElement.getText());
    }

    @Nullable
    @Override
    public String getLocationString() {
      return null;
    }

    @Nullable
    @Override
    public Image getIcon() {
      return AllIcons.Nodes.CustomRegion;
    }
  };
}
 
Example #7
Source File: BuckStructureViewElement.java    From buck with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return getValue().getName();
    }

    @Nullable
    @Override
    public String getLocationString() {
      return null;
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return AllIcons.Nodes.Method;
    }
  };
}
 
Example #8
Source File: AbstractBashCommand.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Override
public ItemPresentation getPresentation() {
    //fixme caching?
    return new ItemPresentation() {
        public String getPresentableText() {
            final PsiElement element = AbstractBashCommand.this.commandElement();
            return element == null ? "unknown" : element.getText();
        }

        public String getLocationString() {
            return null;
        }

        public Icon getIcon(boolean open) {
            return null;
        }
    };
}
 
Example #9
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            return "(impl)";
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean unused) {
            return null;
        }
    };
}
 
Example #10
Source File: SimplePsiImplUtil.java    From intellij-sdk-docs with Apache License 2.0 6 votes vote down vote up
public static ItemPresentation getPresentation(final SimpleProperty element) {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return element.getKey();
    }

    @Nullable
    @Override
    public String getLocationString() {
      PsiFile containingFile = element.getContainingFile();
      return containingFile == null ? null : containingFile.getName();
    }

    @Override
    public Icon getIcon(boolean unused) {
      return SimpleIcons.FILE;
    }
  };
}
 
Example #11
Source File: PsiClassField.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            return getName();
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @NotNull
        @Override
        public Icon getIcon(boolean unused) {
            return ORIcons.VAL;
        }
    };
}
 
Example #12
Source File: PsiStanza.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @NotNull
        @Override
        public String getPresentableText() {
            String name = getName();
            return name == null ? "unknown" : name;
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @NotNull
        @Override
        public Icon getIcon(boolean unused) {
            return ORIcons.OBJECT;
        }
    };
}
 
Example #13
Source File: PsiFileImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    @Override
    public String getPresentableText() {
      return getName();
    }

    @Override
    public String getLocationString() {
      final PsiDirectory psiDirectory = getParent();
      if (psiDirectory != null) {
        return psiDirectory.getVirtualFile().getPresentableUrl();
      }
      return null;
    }

    @Override
    public Image getIcon() {
      return IconDescriptorUpdaters.getIcon(PsiFileImpl.this, 0);
    }
  };
}
 
Example #14
Source File: HaskellVaridBaseImpl.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
@Override
@NotNull
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    @Override
    public String getPresentableText() {
      return HaskellVaridBaseImpl.this.getName();
    }

    /**
     * This is needed to decipher between files when resolving multiple references.
     */
    @Override
    @Nullable
    public String getLocationString() {
      final PsiFile psiFile = HaskellVaridBaseImpl.this.getContainingFile();
      return psiFile instanceof HaskellFile ? ((HaskellFile) psiFile).getModuleOrFileName() : null;
    }

    @Override
    public Icon getIcon(boolean unused) {
      return HaskellIcons.FILE;
    }
  };
}
 
Example #15
Source File: HaskellConidBaseImpl.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
@Override
@NotNull
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    @Override
    public String getPresentableText() {
      return HaskellConidBaseImpl.this.getName();
    }

    /**
     * This is needed to decipher between files when resolving multiple references.
     */
    @Override
    @Nullable
    public String getLocationString() {
      final PsiFile psiFile = HaskellConidBaseImpl.this.getContainingFile();
      return psiFile instanceof HaskellFile ? ((HaskellFile) psiFile).getModuleOrFileName() : null;
    }

    @Override
    public Icon getIcon(boolean unused) {
      return HaskellIcons.FILE;
    }
  };
}
 
Example #16
Source File: NASMPsiImplUtil.java    From JetBrains-NASM-Language with MIT License 6 votes vote down vote up
public static ItemPresentation getPresentation(final NASMLabelIdentifier element) {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            return element.getName();
        }

        @Nullable
        @Override
        public String getLocationString() {
            return element.getContainingFile().getName();
        }

        @Nullable
        @Override
        public Icon getIcon(boolean unused) {
            return NASMIcons.ASM_FILE;
        }
    };
}
 
Example #17
Source File: XQueryPsiImplUtil.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
public static ItemPresentation getPresentation(final XQueryFunctionDecl element) {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            String name = element.getFunctionName() != null ? element.getFunctionName().getText() : "";
            String tailText = (element.getParamList() != null ? element.getParamList().getText() : "") + " as ";
            String typeText = element.getSequenceType() != null ? element.getSequenceType()
                    .getText() : "item()*";
            return StringUtils.compressWhitespaces(name + tailText + typeText);
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean unused) {
            return element.isPublic() ? XQueryIcons.FUNCTION_PUBLIC_ICON : XQueryIcons.FUNCTION_PRIVATE_ICON;
        }
    };
}
 
Example #18
Source File: XQueryPsiImplUtil.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
public static ItemPresentation getPresentation(final XQueryQueryBody element) {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            return "Query Body";
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean unused) {
            return XQueryIcons.QUERY_BODY;
        }
    };
}
 
Example #19
Source File: XQueryPsiImplUtil.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
public static ItemPresentation getPresentation(final XQueryVarDecl element) {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            String name = element.getVarName() != null ? element.getVarName().getText() : "";
            String typeText = "item()*";
            if (element.getTypeDeclaration() != null) {
                typeText = element.getTypeDeclaration().getText();
            }
            return StringUtils.compressWhitespaces(name + " as " + typeText);
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean unused) {
            return isPublic(element) ? XQueryIcons.VARIABLE_PUBLIC_ICON : XQueryIcons.VARIABLE_PRIVATE_ICON;
        }
    };
}
 
Example #20
Source File: CppSymbolContributor.java    From CppTools with Apache License 2.0 6 votes vote down vote up
@Nullable
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    public String getPresentableText() {
      return qName;
    }

    @Nullable
    public String getLocationString() {
      return fu.getFileLocaton();
    }

    @Nullable
    public Icon getIcon(boolean b) {
      return CppSupportLoader.CPP_FILETYPE.getIcon();
    }

    @Nullable
    public TextAttributesKey getTextAttributesKey() {
      return null;
    }
  };
}
 
Example #21
Source File: PsiExternalImpl.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
            String aliasName = getName();

            String realName = getRealName();
            if (!realName.isEmpty()) {
                String realNameText = realName.substring(1, realName.length() - 1);
                if (!Objects.equals(aliasName, realNameText)) {
                    aliasName += " (" + realNameText + ")";
                }
            }

            String signature = getORSignature().asString(getLanguage());
            if (!signature.isEmpty()) {
                aliasName += " :  " + signature;
            }

            return aliasName;
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @Override
        public Icon getIcon(boolean unused) {
            return ORIcons.EXTERNAL;
        }
    };
}
 
Example #22
Source File: GraphQLDocumentationPsiElement.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public ItemPresentation getPresentation() {
    if(itemPresentation == null) {
        itemPresentation = new JSGraphQLDocItemPresentation();
    }
    return itemPresentation;
}
 
Example #23
Source File: CppStructureViewBuilder.java    From CppTools with Apache License 2.0 5 votes vote down vote up
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    public String getPresentableText() {
      if (myOutlineData != null && myOutlineData.structureItem != null) {
        final int index = myOutlineData.structureItem.indexOf(Communicator.DELIMITER, myOutlineData.structureItem.indexOf(Communicator.DELIMITER) + 1) + 1;
        return myOutlineData.structureItem.substring(index, myOutlineData.structureItem.lastIndexOf(Communicator.DELIMITER));
      }
      if (myElement instanceof CppKeyword) {
        PsiElement el = myElement.getNextSibling();
        if (el instanceof PsiWhiteSpace) el = el.getNextSibling();
        if (el != null) return myElement.getText() + " " + el.getText();
      }
      return myElement instanceof CppFile ? myElement.getName() : myElement.getText();
    }

    @Nullable
    public String getLocationString() {
      return null;
    }

    @Nullable
    public Icon getIcon(boolean b) {
      return CppStructureViewTreeElement.this.getIcon();
    }

    @Nullable
    public TextAttributesKey getTextAttributesKey() {
      return null;
    }
  };
}
 
Example #24
Source File: StructureViewCompositeModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static StructureViewTreeElement createRootNode(@Nonnull PsiFile file, @Nonnull List<? extends StructureViewComposite.StructureViewDescriptor> views) {
  JBIterable<TreeElement> children = JBIterable.from(views).map(o -> createTreeElementFromView(file, o));
  return new StructureViewTreeElement() {
    @Override
    public Object getValue() {
      return file;
    }

    @Override
    public void navigate(boolean requestFocus) {
      file.navigate(requestFocus);
    }

    @Override
    public boolean canNavigate() {
      return file.canNavigate();
    }

    @Override
    public boolean canNavigateToSource() {
      return file.canNavigateToSource();
    }

    @Nonnull
    @Override
    public ItemPresentation getPresentation() {
      return file.getPresentation();
    }

    @Nonnull
    @Override
    public TreeElement[] getChildren() {
      List<TreeElement> elements = children.toList();
      return elements.toArray(TreeElement.EMPTY_ARRAY);
    }
  };
}
 
Example #25
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();
}
 
Example #26
Source File: PsiValImpl.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public ItemPresentation getPresentation() {
    return new ItemPresentation() {
        @NotNull
        @Override
        public String getPresentableText() {
            String valName = getName();

            ORSignature signature = getORSignature();
            if (!signature.isEmpty()) {
                valName += ": " + signature.asString(getLanguage());
            }

            return valName;
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @NotNull
        @Override
        public Icon getIcon(boolean unused) {
            return ORIcons.VAL;
        }
    };
}
 
Example #27
Source File: Bookmark.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String getQualifiedName() {
  String presentableUrl = myFile.getPresentableUrl();
  if (myFile.isDirectory()) return presentableUrl;

  PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);

  if (psiFile == null) return presentableUrl;

  StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile);
  if (builder instanceof TreeBasedStructureViewBuilder) {
    StructureViewModel model = ((TreeBasedStructureViewBuilder)builder).createStructureViewModel(null);
    Object element;
    try {
      element = model.getCurrentEditorElement();
    }
    finally {
      model.dispose();
    }
    if (element instanceof NavigationItem) {
      ItemPresentation presentation = ((NavigationItem)element).getPresentation();
      if (presentation != null) {
        presentableUrl = ((NavigationItem)element).getName() + " " + presentation.getLocationString();
      }
    }
  }

  return IdeBundle.message("bookmark.file.X.line.Y", presentableUrl, getLine() + 1);
}
 
Example #28
Source File: PsiElementListCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
protected TextAttributes getNavigationItemAttributes(Object value) {
  TextAttributes attributes = null;

  if (value instanceof NavigationItem) {
    TextAttributesKey attributesKey = null;
    final ItemPresentation presentation = ((NavigationItem)value).getPresentation();
    if (presentation instanceof ColoredItemPresentation) attributesKey = ((ColoredItemPresentation)presentation).getTextAttributesKey();

    if (attributesKey != null) {
      attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
    }
  }
  return attributes;
}
 
Example #29
Source File: BuckStructureViewElement.java    From buck with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return getValue().getArgumentList().stream()
          .filter(arg -> "name".equals(arg.getName()))
          .findFirst()
          .map(BuckArgument::getExpression)
          .map(
              expression ->
                  Optional.of(expression)
                      .map(BuckExpression::getStringValue)
                      .orElse(expression.getText()))
          .orElse("<unnamed>");
    }

    @Nullable
    @Override
    public String getLocationString() {
      BuckExpressionTrailer expressionTrailer = (BuckExpressionTrailer) getValue().getParent();
      BuckPowerExpression powerExpression = (BuckPowerExpression) expressionTrailer.getParent();
      int startOffset = powerExpression.getTextRange().getStartOffset();
      int endOffset = getValue().getTextRange().getStartOffset();
      return "(" + powerExpression.getText().substring(0, endOffset - startOffset) + ")";
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return BuckIcons.FILE_TYPE;
    }
  };
}
 
Example #30
Source File: CsvStructureViewTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
private void doCheckTreeElement(TreeElement element, Class expectedClazz, String expectedText, String expectedLocation) {
    assertInstanceOf(element, expectedClazz);
    assertInstanceOf(element, ItemPresentation.class);

    ItemPresentation presentation = (ItemPresentation) element;
    assertEquals(expectedText, presentation.getPresentableText());
    if (expectedLocation != null) {
        assertEquals(expectedLocation, presentation.getLocationString());
    }
}