Search in sources :

Example 1 with AbstractDomChildrenDescription

use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.

the class DomAnchorImpl method createAnchor.

public static <T extends DomElement> DomAnchor<T> createAnchor(@NotNull T t, boolean usePsi) {
    DomInvocationHandler handler = DomManagerImpl.getNotNullHandler(t);
    if (handler.getStub() != null) {
        return new StubAnchor<>(handler);
    }
    if (usePsi) {
        final XmlElement element = t.getXmlElement();
        if (element != null) {
            return new PsiBasedDomAnchor<>(PsiAnchor.create(element), element.getProject());
        }
    }
    final DomElement parent = t.getParent();
    if (parent == null) {
        LOG.error("Parent null: " + t);
    }
    if (parent instanceof DomFileElementImpl) {
        final DomFileElementImpl fileElement = (DomFileElementImpl) parent;
        //noinspection unchecked
        return new RootAnchor<>(fileElement.getFile(), fileElement.getRootElementClass());
    }
    final DomAnchor<DomElement> parentAnchor = createAnchor(parent);
    final String name = t.getGenericInfo().getElementName(t);
    final AbstractDomChildrenDescription description = t.getChildDescription();
    final List<? extends DomElement> values = description.getValues(parent);
    if (name != null) {
        int i = 0;
        for (DomElement value : values) {
            if (value.equals(t)) {
                return new NamedAnchor<>(parentAnchor, description, name, i);
            }
            if (name.equals(value.getGenericInfo().getElementName(value))) {
                i++;
            }
        }
    }
    final int index = values.indexOf(t);
    if (index < 0) {
        diagnoseNegativeIndex2(t, parent, description, values);
    }
    return new IndexedAnchor<>(parentAnchor, description, index);
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription)

Example 2 with AbstractDomChildrenDescription

use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.

the class BasicDomElementComponent method bindProperties.

protected final void bindProperties(final DomElement domElement) {
    if (domElement == null)
        return;
    DomElementAnnotationsManager.getInstance(domElement.getManager().getProject()).addHighlightingListener(new DomElementAnnotationsManager.DomHighlightingListener() {

        @Override
        public void highlightingFinished(@NotNull final DomFileElement element) {
            ApplicationManager.getApplication().invokeLater(() -> {
                if (getComponent().isShowing() && element.isValid()) {
                    updateHighlighting();
                }
            });
        }
    }, this);
    for (final AbstractDomChildrenDescription description : domElement.getGenericInfo().getChildrenDescriptions()) {
        final JComponent boundComponent = getBoundComponent(description);
        if (boundComponent != null) {
            if (description instanceof DomFixedChildDescription && DomUtil.isGenericValueType(description.getType())) {
                if ((description.getValues(domElement)).size() == 1) {
                    final GenericDomValue element = domElement.getManager().createStableValue(() -> domElement.isValid() ? (GenericDomValue) description.getValues(domElement).get(0) : null);
                    doBind(DomUIFactory.createControl(element, commitOnEveryChange(element)), boundComponent);
                } else {
                //todo not bound
                }
            } else if (description instanceof DomCollectionChildDescription) {
                doBind(DomUIFactory.getDomUIFactory().createCollectionControl(domElement, (DomCollectionChildDescription) description), boundComponent);
            }
        }
    }
    reset();
}
Also used : DomCollectionChildDescription(com.intellij.util.xml.reflect.DomCollectionChildDescription) DomFileElement(com.intellij.util.xml.DomFileElement) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) DomFixedChildDescription(com.intellij.util.xml.reflect.DomFixedChildDescription) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Example 3 with AbstractDomChildrenDescription

use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.

the class DomStubBuilderVisitor method visitXmlElement.

void visitXmlElement(XmlElement element, ElementStub parent, int index) {
    DomInvocationHandler handler = myManager.getDomHandler(element);
    if (handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed())
        return;
    AbstractDomChildrenDescription description = handler.getChildDescription();
    String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription) description).getXmlName().getNamespaceKey() : "";
    if (element instanceof XmlTag) {
        XmlTag tag = (XmlTag) element;
        String elementClass = null;
        if (handler.getAnnotation(StubbedOccurrence.class) != null) {
            final Type type = description.getType();
            elementClass = ((Class) type).getName();
        }
        ElementStub stub = new ElementStub(parent, StringRef.fromString(tag.getName()), StringRef.fromNullableString(nsKey), index, description instanceof CustomDomChildrenDescription, elementClass == null ? null : StringRef.fromNullableString(elementClass), tag.getSubTags().length == 0 ? tag.getValue().getTrimmedText() : "");
        for (XmlAttribute attribute : tag.getAttributes()) {
            visitXmlElement(attribute, stub, 0);
        }
        Map<String, Integer> indices = new HashMap<>();
        for (final XmlTag subTag : tag.getSubTags()) {
            String name = subTag.getName();
            Integer i = indices.get(name);
            i = i == null ? 0 : i + 1;
            visitXmlElement(subTag, stub, i);
            indices.put(name, i);
        }
    } else if (element instanceof XmlAttribute) {
        new AttributeStub(parent, StringRef.fromString(((XmlAttribute) element).getLocalName()), StringRef.fromNullableString(nsKey), ((XmlAttribute) element).getValue());
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) Stubbed(com.intellij.util.xml.Stubbed) HashMap(java.util.HashMap) DomInvocationHandler(com.intellij.util.xml.impl.DomInvocationHandler) CustomDomChildrenDescription(com.intellij.util.xml.reflect.CustomDomChildrenDescription) DomChildrenDescription(com.intellij.util.xml.reflect.DomChildrenDescription) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) CustomDomChildrenDescription(com.intellij.util.xml.reflect.CustomDomChildrenDescription) Type(java.lang.reflect.Type) AttributeStub(com.intellij.util.xml.stubs.AttributeStub) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) ElementStub(com.intellij.util.xml.stubs.ElementStub) XmlTag(com.intellij.psi.xml.XmlTag) StubbedOccurrence(com.intellij.util.xml.StubbedOccurrence)

Example 4 with AbstractDomChildrenDescription

use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.

the class DomHighlightingHelperImpl method checkRequired.

@Override
@NotNull
public List<DomElementProblemDescriptor> checkRequired(final DomElement element, final DomElementAnnotationHolder holder) {
    final Required required = element.getAnnotation(Required.class);
    if (required != null) {
        final XmlElement xmlElement = element.getXmlElement();
        if (xmlElement == null) {
            if (required.value()) {
                final String xmlElementName = element.getXmlElementName();
                String namespace = element.getXmlElementNamespace();
                if (element instanceof GenericAttributeValue) {
                    return Collections.singletonList(holder.createProblem(element, IdeBundle.message("attribute.0.should.be.defined", xmlElementName), new DefineAttributeQuickFix(xmlElementName, namespace)));
                }
                return Collections.singletonList(holder.createProblem(element, HighlightSeverity.ERROR, IdeBundle.message("child.tag.0.should.be.defined", xmlElementName), new AddRequiredSubtagFix(xmlElementName, namespace)));
            }
        } else if (element instanceof GenericDomValue) {
            return ContainerUtil.createMaybeSingletonList(checkRequiredGenericValue((GenericDomValue) element, required, holder));
        }
    }
    if (DomUtil.hasXml(element)) {
        final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
        final DomGenericInfo info = element.getGenericInfo();
        for (final AbstractDomChildrenDescription description : info.getChildrenDescriptions()) {
            if (description instanceof DomCollectionChildDescription && description.getValues(element).isEmpty()) {
                final DomCollectionChildDescription childDescription = (DomCollectionChildDescription) description;
                final Required annotation = description.getAnnotation(Required.class);
                if (annotation != null && annotation.value()) {
                    list.add(holder.createProblem(element, childDescription, IdeBundle.message("child.tag.0.should.be.defined", ((DomCollectionChildDescription) description).getXmlElementName())));
                }
            }
        }
        return list;
    }
    return Collections.emptyList();
}
Also used : DomGenericInfo(com.intellij.util.xml.reflect.DomGenericInfo) DomCollectionChildDescription(com.intellij.util.xml.reflect.DomCollectionChildDescription) XmlElement(com.intellij.psi.xml.XmlElement) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with AbstractDomChildrenDescription

use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.

the class DomGenericInfoEx method findChildrenDescription.

@Nullable
public final AbstractDomChildrenDescription findChildrenDescription(DomInvocationHandler handler, final String localName, String namespace, boolean attribute, final String qName) {
    for (final AbstractDomChildrenDescription description : getChildrenDescriptions()) {
        if (description instanceof DomChildDescriptionImpl && description instanceof AttributeChildDescriptionImpl == attribute) {
            final XmlName xmlName = ((DomChildDescriptionImpl) description).getXmlName();
            if (attribute && StringUtil.isEmpty(namespace) && xmlName.getLocalName().equals(localName))
                return description;
            final EvaluatedXmlName evaluatedXmlName = handler.createEvaluatedXmlName(xmlName);
            if (DomImplUtil.isNameSuitable(evaluatedXmlName, localName, qName, namespace, handler.getFile())) {
                return description;
            }
        }
    }
    List<? extends CustomDomChildrenDescription> list = getCustomNameChildrenDescription();
    for (CustomDomChildrenDescription description : list) {
        if (attribute) {
        // todo
        } else if (description.getTagNameDescriptor() != null) {
            return description;
        }
    }
    return null;
}
Also used : EvaluatedXmlName(com.intellij.util.xml.EvaluatedXmlName) EvaluatedXmlName(com.intellij.util.xml.EvaluatedXmlName) XmlName(com.intellij.util.xml.XmlName) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) CustomDomChildrenDescription(com.intellij.util.xml.reflect.CustomDomChildrenDescription) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AbstractDomChildrenDescription (com.intellij.util.xml.reflect.AbstractDomChildrenDescription)5 XmlElement (com.intellij.psi.xml.XmlElement)2 CustomDomChildrenDescription (com.intellij.util.xml.reflect.CustomDomChildrenDescription)2 DomCollectionChildDescription (com.intellij.util.xml.reflect.DomCollectionChildDescription)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 SmartList (com.intellij.util.SmartList)1 DomFileElement (com.intellij.util.xml.DomFileElement)1 EvaluatedXmlName (com.intellij.util.xml.EvaluatedXmlName)1 GenericDomValue (com.intellij.util.xml.GenericDomValue)1 Stubbed (com.intellij.util.xml.Stubbed)1 StubbedOccurrence (com.intellij.util.xml.StubbedOccurrence)1 XmlName (com.intellij.util.xml.XmlName)1 DomElementAnnotationsManager (com.intellij.util.xml.highlighting.DomElementAnnotationsManager)1 DomInvocationHandler (com.intellij.util.xml.impl.DomInvocationHandler)1 DomChildrenDescription (com.intellij.util.xml.reflect.DomChildrenDescription)1 DomFixedChildDescription (com.intellij.util.xml.reflect.DomFixedChildDescription)1 DomGenericInfo (com.intellij.util.xml.reflect.DomGenericInfo)1 AttributeStub (com.intellij.util.xml.stubs.AttributeStub)1 ElementStub (com.intellij.util.xml.stubs.ElementStub)1