Search in sources :

Example 11 with PsiMetaOwner

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

the class DefinitionReference method getVariants.

@Override
@NotNull
public Object[] getVariants() {
    final RngGrammar scope = getScope();
    if (scope == null) {
        return ResolveResult.EMPTY_ARRAY;
    }
    final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(scope);
    if (map == null || map.size() == 0)
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    return ContainerUtil.mapNotNull(map.values(), defines -> {
        final Define define = defines.iterator().next();
        if (defines.size() == 0) {
            return null;
        } else {
            final PsiElement element = define.getPsiElement();
            if (element != null) {
                final PsiPresentableMetaData data = (PsiPresentableMetaData) ((PsiMetaOwner) element).getMetaData();
                if (data != null) {
                    return LookupValueFactory.createLookupValue(data.getName(), data.getIcon());
                } else {
                    return define.getName();
                }
            } else {
                return define.getName();
            }
        }
    }).toArray();
}
Also used : PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) ArrayUtil(com.intellij.util.ArrayUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) LookupValueFactory(com.intellij.codeInsight.lookup.LookupValueFactory) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) LocalQuickFixProvider(com.intellij.codeInspection.LocalQuickFixProvider) PsiReferenceBase(com.intellij.psi.PsiReferenceBase) RngParentRef(org.intellij.plugins.relaxNG.xml.dom.RngParentRef) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) Define(org.intellij.plugins.relaxNG.model.Define) XmlTag(com.intellij.psi.xml.XmlTag) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue) Set(java.util.Set) DefinitionResolver(org.intellij.plugins.relaxNG.model.resolve.DefinitionResolver) Nullable(org.jetbrains.annotations.Nullable) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar) Function(com.intellij.util.Function) XmlElement(com.intellij.psi.xml.XmlElement) EmptyResolveMessageProvider(com.intellij.codeInsight.daemon.EmptyResolveMessageProvider) NotNull(org.jetbrains.annotations.NotNull) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) Set(java.util.Set) Define(org.intellij.plugins.relaxNG.model.Define) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) PsiElement(com.intellij.psi.PsiElement) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PsiMetaOwner

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

the class TagNameReference method bindToElement.

@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
    PsiMetaData metaData = null;
    if (element instanceof PsiMetaOwner) {
        final PsiMetaOwner owner = (PsiMetaOwner) element;
        metaData = owner.getMetaData();
        if (metaData instanceof XmlElementDescriptor) {
            // TODO: need to evaluate new ns prefix
            return getTagElement().setName(metaData.getName(getElement()));
        }
    } else if (element instanceof PsiFile) {
        final XmlTag tagElement = getTagElement();
        if (tagElement == null || !myStartTagFlag)
            return tagElement;
        String newElementName = ((PsiFile) element).getName();
        final int index = newElementName.lastIndexOf('.');
        // TODO: need to evaluate new ns prefix
        newElementName = prependNamespacePrefix(newElementName.substring(0, index), tagElement.getNamespacePrefix());
        return getTagElement().setName(newElementName);
    }
    final XmlTag tag = getTagElement();
    throw new IncorrectOperationException("Cant bind to not a xml element definition!" + element + "," + metaData + "," + tag + "," + (tag != null ? tag.getDescriptor() : "unknown descriptor"));
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

PsiMetaOwner (com.intellij.psi.meta.PsiMetaOwner)12 PsiMetaData (com.intellij.psi.meta.PsiMetaData)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 PsiPresentableMetaData (com.intellij.psi.meta.PsiPresentableMetaData)2 PsiWritableMetaData (com.intellij.psi.meta.PsiWritableMetaData)2 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)2 XmlTag (com.intellij.psi.xml.XmlTag)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 Nullable (org.jetbrains.annotations.Nullable)2 EmptyResolveMessageProvider (com.intellij.codeInsight.daemon.EmptyResolveMessageProvider)1 LookupValueFactory (com.intellij.codeInsight.lookup.LookupValueFactory)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1 Language (com.intellij.lang.Language)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 NavigationItem (com.intellij.navigation.NavigationItem)1 PsiElementNavigationItem (com.intellij.navigation.PsiElementNavigationItem)1