Search in sources :

Example 21 with XmlTag

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

the class DomInvocationHandler method getFixedChild.

@NotNull
final IndexedElementInvocationHandler getFixedChild(final Pair<FixedChildDescriptionImpl, Integer> info) {
    final FixedChildDescriptionImpl description = info.first;
    XmlName xmlName = description.getXmlName();
    final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(xmlName);
    if (myStub != null && description.isStubbed()) {
        List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey());
        DomStub stub = stubs.isEmpty() ? null : stubs.get(0);
        DomParentStrategy strategy = stub == null ? new StubParentStrategy.Empty(myStub) : new StubParentStrategy(stub);
        return new IndexedElementInvocationHandler(evaluatedXmlName, description, 0, strategy, myManager, (ElementStub) stub);
    }
    final XmlTag tag = getXmlTag();
    final int index = info.second;
    if (tag != null) {
        if (!tag.isValid()) {
            throw new PsiInvalidElementAccessException(tag);
        }
        final XmlTag[] subTags = tag.getSubTags();
        for (int i = 0, subTagsLength = subTags.length; i < subTagsLength; i++) {
            XmlTag xmlTag = subTags[i];
            if (!xmlTag.isValid()) {
                throw new PsiInvalidElementAccessException(xmlTag, "invalid children of valid tag: " + tag.getText() + "; subtag=" + xmlTag + "; index=" + i);
            }
        }
        final List<XmlTag> tags = DomImplUtil.findSubTags(subTags, evaluatedXmlName, getFile());
        if (tags.size() > index) {
            final XmlTag child = tags.get(index);
            final IndexedElementInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child);
            if (semElement == null) {
                final IndexedElementInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child);
                throw new AssertionError("No DOM at XML. Parent=" + tag + "; child=" + child + "; index=" + index + "; second attempt=" + take2);
            }
            return semElement;
        }
    }
    return new IndexedElementInvocationHandler(evaluatedXmlName, description, index, new VirtualDomParentStrategy(this), myManager, null);
}
Also used : PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) DomStub(com.intellij.util.xml.stubs.DomStub) StubParentStrategy(com.intellij.util.xml.stubs.StubParentStrategy) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with XmlTag

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

the class GenericDomValueReference method createTextRange.

protected TextRange createTextRange() {
    if (myGenericValue instanceof GenericAttributeValue) {
        final GenericAttributeValue genericAttributeValue = (GenericAttributeValue) myGenericValue;
        final XmlAttributeValue attributeValue = genericAttributeValue.getXmlAttributeValue();
        if (attributeValue == null) {
            return TextRange.from(0, genericAttributeValue.getXmlAttribute().getTextLength());
        }
        final int length = attributeValue.getTextLength();
        return length < 2 ? TextRange.from(0, length) : new TextRange(1, length - 1);
    }
    final XmlTag tag = myGenericValue.getXmlTag();
    assert tag != null;
    return XmlTagUtil.getTrimmedValueRange(tag);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) ResolvingHint(com.intellij.psi.ResolvingHint) XmlTag(com.intellij.psi.xml.XmlTag)

Example 23 with XmlTag

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

the class GetCompositeCollectionInvocation method invoke.

@Override
public Object invoke(final DomInvocationHandler<?, ?> handler, final Object[] args) throws Throwable {
    Map<XmlTag, DomElement> map = new THashMap<>();
    for (final CollectionChildDescriptionImpl qname : myQnames) {
        for (DomElement element : handler.getCollectionChildren(qname)) {
            map.put(element.getXmlTag(), element);
        }
    }
    final XmlTag tag = handler.getXmlTag();
    if (tag == null)
        return Collections.emptyList();
    final List<DomElement> list = new ArrayList<>();
    for (final XmlTag subTag : tag.getSubTags()) {
        ContainerUtil.addIfNotNull(list, map.get(subTag));
    }
    return list;
}
Also used : DomElement(com.intellij.util.xml.DomElement) THashMap(gnu.trove.THashMap) XmlTag(com.intellij.psi.xml.XmlTag)

Example 24 with XmlTag

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

the class DomElementAnnotationsManagerImpl method _getOrCreateProblemsHolder.

private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) {
    DomElementsProblemsHolderImpl holder;
    final DomElement rootElement = element.getRootElement();
    final XmlTag rootTag = rootElement.getXmlTag();
    if (rootTag == null)
        return new DomElementsProblemsHolderImpl(element);
    holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY);
    if (isHolderOutdated(element.getFile()) || holder == null) {
        holder = new DomElementsProblemsHolderImpl(element);
        rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder);
        final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(() -> new CachedValueProvider.Result<>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, this, ProjectRootManager.getInstance(myProject)), false);
        cachedValue.getValue();
        element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue);
    }
    return holder;
}
Also used : DomElement(com.intellij.util.xml.DomElement) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) XmlTag(com.intellij.psi.xml.XmlTag)

Example 25 with XmlTag

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

the class DomElementProblemDescriptorImpl method getPsiElement.

@Nullable
private PsiElement getPsiElement() {
    if (myDomElement instanceof DomFileElement) {
        return ((DomFileElement) myDomElement).getFile();
    }
    if (myDomElement instanceof GenericAttributeValue) {
        final GenericAttributeValue attributeValue = (GenericAttributeValue) myDomElement;
        final XmlAttributeValue value = attributeValue.getXmlAttributeValue();
        return value != null && StringUtil.isNotEmpty(value.getText()) ? value : attributeValue.getXmlElement();
    }
    final XmlTag tag = myDomElement.getXmlTag();
    if (myDomElement instanceof GenericValue && tag != null) {
        final XmlText[] textElements = tag.getValue().getTextElements();
        if (textElements.length > 0) {
            return textElements[0];
        }
    }
    return tag;
}
Also used : XmlText(com.intellij.psi.xml.XmlText) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

XmlTag (com.intellij.psi.xml.XmlTag)673 XmlFile (com.intellij.psi.xml.XmlFile)151 PsiElement (com.intellij.psi.PsiElement)130 XmlAttribute (com.intellij.psi.xml.XmlAttribute)121 Nullable (org.jetbrains.annotations.Nullable)99 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)89 NotNull (org.jetbrains.annotations.NotNull)89 PsiFile (com.intellij.psi.PsiFile)71 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)50 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)50 Project (com.intellij.openapi.project.Project)48 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)47 ArrayList (java.util.ArrayList)43 XmlDocument (com.intellij.psi.xml.XmlDocument)39 DomElement (com.intellij.util.xml.DomElement)35 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 TextRange (com.intellij.openapi.util.TextRange)32 Result (com.intellij.openapi.application.Result)24 Document (com.intellij.openapi.editor.Document)24