use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class CDATAOnAnyEncodedPolicy method encodeXmlTextContents.
@Override
public ASTNode encodeXmlTextContents(String displayText, PsiElement text) {
final ASTNode firstChild = text.getNode().getFirstChildNode();
boolean textAlreadyHasCDATA = firstChild != null && firstChild.getElementType() == XmlElementType.XML_CDATA;
if ((textAlreadyHasCDATA || XmlUtil.toCode(displayText)) && !displayText.isEmpty()) {
final FileElement dummyParent = createCDATAElement(text.getManager(), SharedImplUtil.findCharTableByTree(text.getNode()), displayText);
return dummyParent.getFirstChildNode();
} else {
return super.encodeXmlTextContents(displayText, text);
}
}
use of com.intellij.psi.impl.source.tree.FileElement 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();
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class XmlTokenManipulator method handleContentChange.
@Override
public XmlToken handleContentChange(@NotNull XmlToken xmlToken, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
String oldText = xmlToken.getText();
String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
IElementType tokenType = xmlToken.getTokenType();
FileElement holder = DummyHolderFactory.createHolder(xmlToken.getManager(), null).getTreeElement();
LeafElement leaf = ASTFactory.leaf(tokenType, holder.getCharTable().intern(newText));
holder.rawAddChildren(leaf);
return (XmlToken) xmlToken.replace(leaf.getPsi());
}
Aggregations