use of com.intellij.psi.xml.XmlTagChild in project intellij-community by JetBrains.
the class XmlSurroundDescriptor method getElementsToSurround.
@Override
@NotNull
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
final Pair<XmlTagChild, XmlTagChild> childrenInRange = XmlUtil.findTagChildrenInRange(file, startOffset, endOffset);
if (childrenInRange == null) {
final PsiElement elementAt = file.findElementAt(startOffset);
if (elementAt instanceof XmlToken && ((XmlToken) elementAt).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
return new PsiElement[] { elementAt };
}
return PsiElement.EMPTY_ARRAY;
}
List<PsiElement> result = new ArrayList<>();
PsiElement first = childrenInRange.getFirst();
PsiElement last = childrenInRange.getSecond();
while (true) {
result.add(first);
if (first == last)
break;
first = first.getNextSibling();
}
return PsiUtilCore.toPsiElementArray(result);
}
use of com.intellij.psi.xml.XmlTagChild in project intellij-community by JetBrains.
the class DefaultXmlPsiPolicy method encodeXmlTextContents.
@Override
public ASTNode encodeXmlTextContents(String displayText, PsiElement text) {
final PsiFile containingFile = text.getContainingFile();
CharTable charTable = SharedImplUtil.findCharTableByTree(text.getNode());
final FileElement dummyParent = DummyHolderFactory.createHolder(text.getManager(), null, charTable).getTreeElement();
final XmlTag rootTag = ((XmlFile) PsiFileFactory.getInstance(containingFile.getProject()).createFileFromText("a.xml", "<a>" + displayText + "</a>")).getRootTag();
assert rootTag != null;
final XmlTagChild[] tagChildren = rootTag.getValue().getChildren();
final XmlTagChild child = tagChildren.length > 0 ? tagChildren[0] : null;
LOG.assertTrue(child != null, "Child is null for tag: " + rootTag.getText());
final TreeElement element = (TreeElement) child.getNode();
((TreeElement) tagChildren[tagChildren.length - 1].getNode().getTreeNext()).rawRemoveUpToLast();
dummyParent.rawAddChildren(element);
TreeUtil.clearCaches(dummyParent);
return element.getFirstChildNode();
}
Aggregations