Search in sources :

Example 31 with FileElement

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);
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) FileElement(com.intellij.psi.impl.source.tree.FileElement)

Example 32 with FileElement

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();
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) PsiFile(com.intellij.psi.PsiFile) CharTable(com.intellij.util.CharTable) XmlTagChild(com.intellij.psi.xml.XmlTagChild) XmlTag(com.intellij.psi.xml.XmlTag) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 33 with FileElement

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());
}
Also used : IElementType(com.intellij.psi.tree.IElementType) FileElement(com.intellij.psi.impl.source.tree.FileElement) LeafElement(com.intellij.psi.impl.source.tree.LeafElement) XmlToken(com.intellij.psi.xml.XmlToken)

Aggregations

FileElement (com.intellij.psi.impl.source.tree.FileElement)33 NotNull (org.jetbrains.annotations.NotNull)10 ASTNode (com.intellij.lang.ASTNode)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)6 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)5 FileManager (com.intellij.psi.impl.file.impl.FileManager)5 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)4 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)3 Nullable (org.jetbrains.annotations.Nullable)3 Lexer (com.intellij.lexer.Lexer)2 Disposable (com.intellij.openapi.Disposable)2 Document (com.intellij.openapi.editor.Document)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PomModel (com.intellij.pom.PomModel)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 GeneratedMarkerVisitor (com.intellij.psi.impl.GeneratedMarkerVisitor)2 DummyHolder (com.intellij.psi.impl.source.DummyHolder)2 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)2