use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.
the class PsiElement2UsageTargetAdapter method update.
private void update(PsiElement element) {
if (element != null && element.isValid()) {
final ItemPresentation presentation = ((NavigationItem) element).getPresentation();
myIconOpen = presentation == null ? null : ComputableIcon.create(presentation, true);
myIconClosed = presentation == null ? null : ComputableIcon.create(presentation, false);
myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
if (myIconOpen == null || myIconClosed == 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 (myIconOpen == null)
myIconOpen = ComputableIcon.create(psiPresentableMetaData);
if (myIconClosed == null)
myIconClosed = ComputableIcon.create(psiPresentableMetaData);
}
} else if (element instanceof PsiFile) {
final PsiFile psiFile = (PsiFile) element;
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
myIconOpen = ComputableIcon.create(virtualFile);
myIconClosed = ComputableIcon.create(virtualFile);
}
}
}
}
}
use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.
the class SearchEverywherePsiRenderer method customizeNonPsiElementLeftRenderer.
@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (!(value instanceof NavigationItem))
return false;
NavigationItem item = (NavigationItem) value;
TextAttributes attributes = getNavigationItemAttributes(item);
SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
Color color = list.getForeground();
if (nameAttributes == null)
nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
renderer.append(item + " ", nameAttributes);
ItemPresentation itemPresentation = item.getPresentation();
assert itemPresentation != null;
renderer.setIcon(itemPresentation.getIcon(true));
String locationString = itemPresentation.getLocationString();
if (!StringUtil.isEmpty(locationString)) {
renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
}
return true;
}
use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.
the class NavigationUtil method openFileWithPsiElement.
public static boolean openFileWithPsiElement(PsiElement element, boolean searchForOpen, boolean requestFocus) {
boolean openAsNative = false;
if (element instanceof PsiFile) {
VirtualFile virtualFile = ((PsiFile) element).getVirtualFile();
if (virtualFile != null) {
openAsNative = ElementBase.isNativeFileType(virtualFile.getFileType());
}
}
if (searchForOpen) {
element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, null);
} else {
element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, true);
}
if (openAsNative || !activatePsiElementIfOpen(element, searchForOpen, requestFocus)) {
final NavigationItem navigationItem = (NavigationItem) element;
if (!navigationItem.canNavigate())
return false;
navigationItem.navigate(requestFocus);
return true;
}
element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, null);
return false;
}
use of com.intellij.navigation.NavigationItem in project kotlin by JetBrains.
the class ReferenceUtils method renderAsGotoImplementation.
public static String renderAsGotoImplementation(@NotNull PsiElement element) {
PsiElement navigationElement = element.getNavigationElement();
if (navigationElement instanceof KtObjectDeclaration && ((KtObjectDeclaration) navigationElement).isCompanion()) {
//default presenter return null for companion object
KtClass containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass.class);
assert containingClass != null;
return "companion object of " + renderAsGotoImplementation(containingClass);
}
if (navigationElement instanceof KtStringTemplateExpression) {
return KtPsiUtilKt.getPlainContent((KtStringTemplateExpression) navigationElement);
}
Assert.assertTrue(navigationElement instanceof NavigationItem);
ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation();
if (presentation == null) {
String elementText = element.getText();
return elementText != null ? elementText : navigationElement.getText();
}
String presentableText = presentation.getPresentableText();
String locationString = presentation.getLocationString();
if (locationString == null && element.getParent() instanceof PsiAnonymousClass) {
locationString = "<anonymous>";
}
return locationString == null || navigationElement instanceof PsiPackage ? // for PsiPackage, presentableText is FQ name of current package
presentableText : locationString + "." + presentableText;
}
use of com.intellij.navigation.NavigationItem in project intellij-plugins by JetBrains.
the class GoToPackageSymbolProvider method addItems.
protected void addItems(@NotNull final Module module, final String name, final List<NavigationItem> result) {
final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
if (strutsModel == null) {
return;
}
final List<StrutsPackage> strutsPackageList = strutsModel.getStrutsPackages();
for (final StrutsPackage strutsPackage : strutsPackageList) {
if (Comparing.strEqual(name, strutsPackage.getName().getStringValue())) {
final NavigationItem item = createNavigationItem(strutsPackage.getXmlTag(), name, StrutsIcons.STRUTS_PACKAGE);
result.add(item);
}
}
}
Aggregations