use of com.intellij.psi.impl.source.tree.LeafElement in project intellij-community by JetBrains.
the class XmlUtil method expandTag.
public static void expandTag(@NotNull XmlTag tag) {
XmlTag newTag = XmlElementFactory.getInstance(tag.getProject()).createTagFromText('<' + tag.getName() + "></" + tag.getName() + '>');
ASTNode node = tag.getNode();
if (!(node instanceof CompositeElement))
return;
CompositeElement compositeElement = (CompositeElement) node;
final LeafElement emptyTagEnd = (LeafElement) XmlChildRole.EMPTY_TAG_END_FINDER.findChild(compositeElement);
if (emptyTagEnd == null)
return;
compositeElement.removeChild(emptyTagEnd);
PsiElement[] children = newTag.getChildren();
compositeElement.addChildren(children[2].getNode(), null, null);
}
use of com.intellij.psi.impl.source.tree.LeafElement in project intellij-community by JetBrains.
the class XmlTemplateTreePatcher method split.
@Override
public LeafElement split(LeafElement leaf, int offset, final CharTable table) {
final CharSequence chars = leaf.getChars();
final LeafElement leftPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, 0, offset));
final LeafElement rightPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, offset, chars.length()));
leaf.rawInsertAfterMe(leftPart);
leftPart.rawInsertAfterMe(rightPart);
leaf.rawRemove();
return leftPart;
}
use of com.intellij.psi.impl.source.tree.LeafElement in project oxy-template-support-plugin by mutant-industries.
the class OxyTemplateInnerJsElementType method convertReferencesToVariables.
private void convertReferencesToVariables(final FileElement root) {
for (TextRange range : variables.get().pop()) {
LeafElement elementAt = root.findLeafElementAt(range.getStartOffset());
CompositeElement parent;
if (elementAt == null || elementAt.getElementType() != JSTokenTypes.IDENTIFIER || elementAt.getTextLength() != range.getLength() || (parent = elementAt.getTreeParent()).getElementType() != JSElementTypes.REFERENCE_EXPRESSION || (parent = parent.getTreeParent()).getElementType() != JSElementTypes.EXPRESSION_STATEMENT) {
continue;
}
ASTNode replacement = JSChangeUtil.createJSTreeFromText(root.getManager().getProject(), "var " + elementAt.getText());
replacement.removeRange(replacement.getFirstChildNode(), replacement.getLastChildNode());
parent.getTreeParent().replaceChild(parent, replacement);
}
}
use of com.intellij.psi.impl.source.tree.LeafElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPsiImplUtil method updateText.
@NotNull
public static GoStringLiteralImpl updateText(@NotNull GoStringLiteral o, @NotNull String text) {
if (text.length() > 2) {
if (o.getString() != null) {
StringBuilder outChars = new StringBuilder();
GoStringLiteralEscaper.escapeString(text.substring(1, text.length() - 1), outChars);
outChars.insert(0, '"');
outChars.append('"');
text = outChars.toString();
}
}
ASTNode valueNode = o.getNode().getFirstChildNode();
assert valueNode instanceof LeafElement;
((LeafElement) valueNode).replaceWithText(text);
return (GoStringLiteralImpl) o;
}
use of com.intellij.psi.impl.source.tree.LeafElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoExpressionUtil method isOperatorEquals.
private static boolean isOperatorEquals(@Nullable PsiElement l, @Nullable PsiElement r) {
if (l == null || r == null)
return false;
ASTNode lNode = l.getNode();
ASTNode rNode = r.getNode();
return lNode instanceof LeafElement && lNode.getElementType().equals(rNode.getElementType());
}
Aggregations