Search in sources :

Example 11 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.

the class Html5CustomAttributeDescriptorsProvider method getAttributeDescriptors.

@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag tag) {
    if (tag == null || !HtmlUtil.isHtml5Context(tag)) {
        return XmlAttributeDescriptor.EMPTY;
    }
    final List<String> currentAttrs = new ArrayList<>();
    for (XmlAttribute attribute : tag.getAttributes()) {
        currentAttrs.add(attribute.getName());
    }
    final Project project = tag.getProject();
    final Collection<String> keys = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
        final Collection<String> keys1 = FileBasedIndex.getInstance().getAllKeys(Html5CustomAttributesIndex.INDEX_ID, project);
        final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
        return CachedValueProvider.Result.<Collection<String>>create(ContainerUtil.filter(keys1, key -> !FileBasedIndex.getInstance().processValues(Html5CustomAttributesIndex.INDEX_ID, key, null, (file, value) -> false, scope)), PsiModificationTracker.MODIFICATION_COUNT);
    });
    if (keys.isEmpty())
        return XmlAttributeDescriptor.EMPTY;
    final List<XmlAttributeDescriptor> result = new ArrayList<>();
    for (String key : keys) {
        boolean add = true;
        for (String attr : currentAttrs) {
            if (attr.startsWith(key)) {
                add = false;
            }
        }
        if (add) {
            result.add(new AnyXmlAttributeDescriptor(key));
        }
    }
    return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
Also used : HtmlUtil(com.intellij.xml.util.HtmlUtil) Html5CustomAttributesIndex(com.intellij.html.index.Html5CustomAttributesIndex) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlAttributeDescriptorsProvider(com.intellij.xml.XmlAttributeDescriptorsProvider) ContainerUtil(com.intellij.util.containers.ContainerUtil) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) ArrayList(java.util.ArrayList) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) List(java.util.List) Project(com.intellij.openapi.project.Project) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) XmlTag(com.intellij.psi.xml.XmlTag) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) Collection(java.util.Collection)

Example 12 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.

the class MicrodataAttributeDescriptorsProvider method getAttributeDescriptors.

@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag context) {
    if (!HtmlUtil.isHtml5Context(context)) {
        return XmlAttributeDescriptor.EMPTY;
    }
    final String tagName = context.getName();
    List<XmlAttributeDescriptor> result = new ArrayList<>();
    final boolean goodContextForProps = "div".equalsIgnoreCase(tagName) || "span".equalsIgnoreCase(tagName) || "a".equalsIgnoreCase(tagName);
    if (goodContextForProps && hasScopeTag(context)) {
        result.add(new MicrodataPropertyAttributeDescriptor(context));
    }
    if (context.getAttribute(ITEM_SCOPE) == null) {
        result.add(new AnyXmlAttributeDescriptor(ITEM_SCOPE));
    } else {
        result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_ID));
        result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_TYPE));
        result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_REF));
    }
    return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
Also used : AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) ArrayList(java.util.ArrayList)

Example 13 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.

the class XmlHighlightingTest method testAnyAttributeNavigation.

public void testAnyAttributeNavigation() throws Exception {
    configureByFiles(null, getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xml"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xsd"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/library.xsd"));
    PsiReference at = getFile().findReferenceAt(getEditor().getCaretModel().getOffset());
    XmlTag tag = PsiTreeUtil.getParentOfType(at.getElement(), XmlTag.class);
    XmlElementDescriptorImpl descriptor = (XmlElementDescriptorImpl) tag.getDescriptor();
    XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag);
    System.out.println(Arrays.asList(descriptors));
    doDoTest(true, false);
    PsiElement resolve = at.resolve();
    assertTrue(resolve instanceof XmlTag);
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptorImpl(com.intellij.xml.impl.schema.XmlElementDescriptorImpl)

Example 14 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.

the class PsiDocumentNavigator method getElementById.

public Object getElementById(Object object, final String elementId) {
    final XmlTag rootTag = ((XmlFile) ((XmlElement) object).getContainingFile()).getRootTag();
    if (rootTag == null) {
        return null;
    }
    final Ref<XmlTag> ref = new Ref<>();
    rootTag.accept(new XmlRecursiveElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (ref.get() == null) {
                super.visitElement(element);
            }
        }

        @Override
        public void visitXmlAttribute(XmlAttribute attribute) {
            final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
            final String value = attribute.getValue();
            if ((value != null && (descriptor != null && descriptor.hasIdType()))) {
                if (elementId.equals(value)) {
                    ref.set(attribute.getParent());
                }
            }
        }
    });
    return ref.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlRecursiveElementVisitor(com.intellij.psi.XmlRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement)

Example 15 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.

the class XmlAttributeReferenceCompletionProvider method addAttributeReferenceCompletionVariants.

public static void addAttributeReferenceCompletionVariants(XmlAttributeReference reference, CompletionResultSet result, @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
    final XmlTag declarationTag = reference.getElement().getParent();
    LOG.assertTrue(declarationTag.isValid());
    final XmlElementDescriptor parentDescriptor = declarationTag.getDescriptor();
    if (parentDescriptor != null) {
        final XmlAttribute[] attributes = declarationTag.getAttributes();
        XmlAttributeDescriptor[] descriptors = parentDescriptor.getAttributesDescriptors(declarationTag);
        descriptors = HtmlUtil.appendHtmlSpecificAttributeCompletions(declarationTag, descriptors, reference.getElement());
        addVariants(result, attributes, descriptors, reference.getElement(), replacementInsertHandler);
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) NamespaceAwareXmlAttributeDescriptor(com.intellij.xml.NamespaceAwareXmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)89 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)54 XmlTag (com.intellij.psi.xml.XmlTag)46 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)32 XmlAttribute (com.intellij.psi.xml.XmlAttribute)18 NotNull (org.jetbrains.annotations.NotNull)11 PsiElement (com.intellij.psi.PsiElement)10 ArrayList (java.util.ArrayList)8 XmlFile (com.intellij.psi.xml.XmlFile)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)6 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)6 Nullable (org.jetbrains.annotations.Nullable)6 Project (com.intellij.openapi.project.Project)5 HtmlTag (com.intellij.psi.html.HtmlTag)5 NamespaceAwareXmlAttributeDescriptor (com.intellij.xml.NamespaceAwareXmlAttributeDescriptor)5 AnyXmlAttributeDescriptor (com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor)5 JavaFxPropertyAttributeDescriptor (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyAttributeDescriptor)5 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)3 PsiReference (com.intellij.psi.PsiReference)3 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2