use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class CDATAOnAnyEncodedPolicy method createCDATAElement.
@SuppressWarnings({ "HardCodedStringLiteral" })
public static FileElement createCDATAElement(final PsiManager manager, final CharTable charTableByTree, final String displayText) {
final FileElement dummyParent = DummyHolderFactory.createHolder(manager, null, charTableByTree).getTreeElement();
final CompositeElement cdata = ASTFactory.composite(XmlElementType.XML_CDATA);
dummyParent.rawAddChildren(cdata);
cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_START, "<![CDATA["));
cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_DATA_CHARACTERS, dummyParent.getCharTable().intern(displayText)));
cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_END, "]]>"));
dummyParent.acceptTree(new GeneratedMarkerVisitor());
return dummyParent;
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class GroovySpacingProcessor method _init.
private void _init(@Nullable final ASTNode child) {
if (child == null)
return;
ASTNode treePrev = child.getTreePrev();
while (treePrev != null && isWhiteSpace(treePrev)) {
treePrev = treePrev.getTreePrev();
}
if (treePrev == null) {
_init(child.getTreeParent());
} else {
myChild2 = child;
myType2 = myChild2.getElementType();
myChild1 = treePrev;
myType1 = myChild1.getElementType();
final CompositeElement parent = (CompositeElement) treePrev.getTreeParent();
myParent = SourceTreeToPsiMap.treeElementToPsi(parent);
}
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class HtmlFileImpl method getDocument.
@Override
public XmlDocument getDocument() {
CompositeElement treeElement = calcTreeElement();
ASTNode node = treeElement.findChildByType(XmlElementType.HTML_DOCUMENT);
return node != null ? (XmlDocument) node.getPsi() : null;
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class XmlProcessingInstructionManipulator method handleContentChange.
@Override
public XmlProcessingInstruction handleContentChange(@NotNull XmlProcessingInstruction element, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
CheckUtil.checkWritable(element);
final CompositeElement attrNode = (CompositeElement) element.getNode();
final ASTNode valueNode = attrNode.findLeafElementAt(range.getStartOffset());
LOG.assertTrue(valueNode != null, "Leaf not found in " + attrNode + " at offset " + range.getStartOffset() + " in element " + element);
final PsiElement elementToReplace = valueNode.getPsi();
String text;
try {
text = elementToReplace.getText();
final int offsetInParent = elementToReplace.getStartOffsetInParent();
String textBeforeRange = text.substring(0, range.getStartOffset() - offsetInParent);
String textAfterRange = text.substring(range.getEndOffset() - offsetInParent, text.length());
newContent = element.getText().startsWith("'") || element.getText().endsWith("'") ? newContent.replace("'", "'") : newContent.replace("\"", """);
text = textBeforeRange + newContent + textAfterRange;
} catch (StringIndexOutOfBoundsException e) {
LOG.error("Range: " + range + " in text: '" + element.getText() + "'", e);
throw e;
}
final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(attrNode);
final LeafElement newValueElement = Factory.createSingleLeafElement(XmlTokenType.XML_TAG_CHARACTERS, text, charTableByTree, element.getManager());
attrNode.replaceChildInternal(valueNode, newValueElement);
return element;
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class ASTDelegatePsiElement method getChildren.
@Override
@NotNull
public PsiElement[] getChildren() {
PsiElement psiChild = getFirstChild();
if (psiChild == null)
return PsiElement.EMPTY_ARRAY;
List<PsiElement> result = new ArrayList<>();
while (psiChild != null) {
if (psiChild.getNode() instanceof CompositeElement) {
result.add(psiChild);
}
psiChild = psiChild.getNextSibling();
}
return PsiUtilCore.toPsiElementArray(result);
}
Aggregations