Search in sources :

Example 21 with PsiMetaData

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

the class DomNameSuggestionProvider method getSuggestedNames.

@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, final PsiElement nameSuggestionContext, final Set<String> result) {
    if (element instanceof PsiMetaOwner) {
        final PsiMetaData psiMetaData = ((PsiMetaOwner) element).getMetaData();
        if (psiMetaData instanceof DomMetaData) {
            final DomMetaData domMetaData = (DomMetaData) psiMetaData;
            final GenericDomValue value = domMetaData.getNameElement(domMetaData.getElement());
            ContainerUtil.addIfNotNull(result, getNameFromNameValue(value, true));
        }
    }
    return null;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner)

Example 22 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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)

Example 23 with PsiMetaData

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

the class XmlElementDescriptorImpl method collectAttributeDescriptors.

// Read-only calculation
@Override
protected final XmlAttributeDescriptor[] collectAttributeDescriptors(final XmlTag context) {
    final List<XmlAttributeDescriptor> result = new SmartList<>();
    for (XmlAttlistDecl attlistDecl : findAttlistDeclarations(getName())) {
        for (XmlAttributeDecl attributeDecl : attlistDecl.getAttributeDecls()) {
            final PsiMetaData psiMetaData = attributeDecl.getMetaData();
            assert psiMetaData instanceof XmlAttributeDescriptor;
            result.add((XmlAttributeDescriptor) psiMetaData);
        }
    }
    return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) SmartList(com.intellij.util.SmartList)

Example 24 with PsiMetaData

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

the class CreateNSDeclarationIntentionFix method processExternalUrisImpl.

private static void processExternalUrisImpl(final MetaHandler metaHandler, final PsiFile file, final ExternalUriProcessor processor) {
    final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
    final String searchFor = metaHandler.searchFor();
    if (pi != null)
        pi.setText(XmlErrorMessages.message("looking.in.schemas"));
    final ExternalResourceManager instanceEx = ExternalResourceManager.getInstance();
    final String[] availableUrls = instanceEx.getResourceUrls(null, true);
    int i = 0;
    for (String url : availableUrls) {
        if (pi != null) {
            pi.setFraction((double) i / availableUrls.length);
            pi.setText2(url);
            ++i;
        }
        final XmlFile xmlFile = XmlUtil.findNamespace(file, url);
        if (xmlFile != null) {
            final boolean wordFound = checkIfGivenXmlHasTheseWords(searchFor, xmlFile);
            if (!wordFound)
                continue;
            final XmlDocument document = xmlFile.getDocument();
            assert document != null;
            final PsiMetaData metaData = document.getMetaData();
            if (metaHandler.isAcceptableMetaData(metaData, url)) {
                final XmlNSDescriptorImpl descriptor = metaData instanceof XmlNSDescriptorImpl ? (XmlNSDescriptorImpl) metaData : null;
                final String defaultNamespace = descriptor != null ? descriptor.getDefaultNamespace() : url;
                // Skip rare stuff
                if (!XmlUtil.XML_SCHEMA_URI2.equals(defaultNamespace) && !XmlUtil.XML_SCHEMA_URI3.equals(defaultNamespace)) {
                    processor.process(defaultNamespace, url);
                }
            }
        }
    }
}
Also used : ExternalResourceManager(com.intellij.javaee.ExternalResourceManager) PsiMetaData(com.intellij.psi.meta.PsiMetaData) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl)

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