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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations