Search in sources :

Example 6 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class XmlFindUsagesProvider method getNodeText.

@Override
@NotNull
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
    if (element instanceof XmlTag) {
        final XmlTag xmlTag = (XmlTag) element;
        final PsiMetaData metaData = xmlTag.getMetaData();
        final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName();
        String presentableName = metaData == null ? "<" + name + ">" : name;
        return presentableName + " of file " + xmlTag.getContainingFile().getName();
    }
    if (element instanceof XmlAttributeValue) {
        return ((XmlAttributeValue) element).getValue();
    }
    if (element instanceof PsiNamedElement) {
        return ((PsiNamedElement) element).getName();
    }
    return element.getText();
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiNamedElement(com.intellij.psi.PsiNamedElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class HtmlDocumentationProvider method findDocumentationDescriptor.

private static EntityDescriptor findDocumentationDescriptor(PsiElement element, XmlTag context) {
    boolean isTag = true;
    PsiElement nameElement = null;
    String key = null;
    if (element instanceof XmlElementDecl) {
        nameElement = ((XmlElementDecl) element).getNameElement();
    } else if (element instanceof XmlAttributeDecl) {
        nameElement = ((XmlAttributeDecl) element).getNameElement();
        isTag = false;
    } else if (element instanceof XmlTag) {
        final XmlTag xmlTag = ((XmlTag) element);
        final PsiMetaData metaData = xmlTag.getMetaData();
        key = (metaData != null) ? metaData.getName() : null;
        isTag = xmlTag.getLocalName().equals(ELEMENT_ELEMENT_NAME);
    } else if (element.getParent() instanceof XmlAttributeValue) {
        isTag = false;
        key = ((XmlAttribute) element.getParent().getParent()).getName();
    } else if (element instanceof XmlAttributeValue) {
        isTag = false;
        final XmlAttribute xmlAttribute = (XmlAttribute) element.getParent();
        key = xmlAttribute.getName();
    } else if (element instanceof XmlAttribute) {
        final XmlAttribute xmlAttribute = (XmlAttribute) element;
        isTag = false;
        key = xmlAttribute.getName();
    } else if (element instanceof XmlElement) {
        nameElement = element;
        isTag = !(element.getParent() instanceof XmlAttribute);
    } else {
        nameElement = element;
        if (context != null) {
            String text = element.getText();
            isTag = text != null && text.startsWith(context.getName());
        }
    }
    if (nameElement != null) {
        key = nameElement.getText();
    }
    key = StringUtil.notNullize(key).toLowerCase(Locale.US);
    int dotIndex = key.indexOf('.');
    if (dotIndex > 0) {
        key = key.substring(0, dotIndex);
    }
    if (isTag) {
        return HtmlDescriptorsTable.getTagDescriptor(key);
    } else {
        return getDescriptor(key, context);
    }
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) PsiMetaData(com.intellij.psi.meta.PsiMetaData) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner)

Example 9 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class JavaFindUsagesHelper method getElementNames.

@NotNull
public static Set<String> getElementNames(@NotNull final PsiElement element) {
    if (element instanceof PsiDirectory) {
        // normalize a directory to a corresponding package
        PsiPackage aPackage = ReadAction.compute(() -> JavaDirectoryService.getInstance().getPackage((PsiDirectory) element));
        return aPackage == null ? Collections.emptySet() : getElementNames(aPackage);
    }
    final Set<String> result = new HashSet<>();
    ApplicationManager.getApplication().runReadAction(() -> {
        if (element instanceof PsiPackage) {
            ContainerUtil.addIfNotNull(result, ((PsiPackage) element).getQualifiedName());
        } else if (element instanceof PsiClass) {
            final String qname = ((PsiClass) element).getQualifiedName();
            if (qname != null) {
                result.add(qname);
                PsiClass topLevelClass = PsiUtil.getTopLevelClass(element);
                if (topLevelClass != null && !(topLevelClass instanceof PsiSyntheticClass)) {
                    String topName = topLevelClass.getQualifiedName();
                    assert topName != null : "topLevelClass : " + topLevelClass + "; element: " + element + " (" + qname + ") top level file: " + InjectedLanguageManager.getInstance(element.getProject()).getTopLevelFile(element);
                    if (qname.length() > topName.length()) {
                        result.add(topName + qname.substring(topName.length()).replace('.', '$'));
                    }
                }
            }
        } else if (element instanceof PsiMethod) {
            ContainerUtil.addIfNotNull(result, ((PsiMethod) element).getName());
        } else if (element instanceof PsiVariable) {
            ContainerUtil.addIfNotNull(result, ((PsiVariable) element).getName());
        } else if (element instanceof PsiMetaOwner) {
            final PsiMetaData metaData = ((PsiMetaOwner) element).getMetaData();
            if (metaData != null) {
                ContainerUtil.addIfNotNull(result, metaData.getName());
            }
        } else if (element instanceof PsiNamedElement) {
            ContainerUtil.addIfNotNull(result, ((PsiNamedElement) element).getName());
        } else if (element instanceof XmlAttributeValue) {
            ContainerUtil.addIfNotNull(result, ((XmlAttributeValue) element).getValue());
        } else {
            LOG.error("Unknown element type: " + element);
        }
    });
    return result;
}
Also used : XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class LookupItemUtil method objectToLookupItem.

/**
   * @deprecated
   * @see LookupElementBuilder
  */
@NotNull
public static LookupElement objectToLookupItem(Object object) {
    if (object instanceof LookupElement)
        return (LookupElement) object;
    if (object instanceof PsiClass) {
        return JavaClassNameCompletionContributor.createClassLookupItem((PsiClass) object, true);
    }
    if (object instanceof PsiMethod) {
        return new JavaMethodCallElement((PsiMethod) object);
    }
    if (object instanceof PsiVariable) {
        return new VariableLookupItem((PsiVariable) object);
    }
    if (object instanceof PsiExpression) {
        return new ExpressionLookupItem((PsiExpression) object);
    }
    if (object instanceof PsiType) {
        return PsiTypeLookupItem.createLookupItem((PsiType) object, null);
    }
    if (object instanceof PsiPackage) {
        return new PackageLookupItem((PsiPackage) object);
    }
    String s = null;
    LookupItem item = new LookupItem(object, "");
    if (object instanceof PsiElement) {
        s = PsiUtilCore.getName((PsiElement) object);
    }
    TailType tailType = TailType.NONE;
    if (object instanceof PsiMetaData) {
        s = ((PsiMetaData) object).getName();
    } else if (object instanceof String) {
        s = (String) object;
    } else if (object instanceof Template) {
        s = ((Template) object).getKey();
    } else if (object instanceof PresentableLookupValue) {
        s = ((PresentableLookupValue) object).getPresentation();
    }
    if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
        item.setBold();
    }
    if (s == null) {
        LOG.error("Null string for object: " + object + " of class " + (object != null ? object.getClass() : null));
    }
    item.setLookupString(s);
    item.setTailType(tailType);
    return item;
}
Also used : JavaMethodCallElement(com.intellij.codeInsight.completion.JavaMethodCallElement) TailType(com.intellij.codeInsight.TailType) Template(com.intellij.codeInsight.template.Template) PsiMetaData(com.intellij.psi.meta.PsiMetaData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiMetaData (com.intellij.psi.meta.PsiMetaData)24 PsiMetaOwner (com.intellij.psi.meta.PsiMetaOwner)10 XmlDocument (com.intellij.psi.xml.XmlDocument)5 NotNull (org.jetbrains.annotations.NotNull)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 Nullable (org.jetbrains.annotations.Nullable)3 TailType (com.intellij.codeInsight.TailType)2 Template (com.intellij.codeInsight.template.Template)2 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)2 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)2 JavaMethodCallElement (com.intellij.codeInsight.completion.JavaMethodCallElement)1