Search in sources :

Example 1 with GeneratedMarkerVisitor

use of com.intellij.psi.impl.GeneratedMarkerVisitor 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;
}
Also used : GeneratedMarkerVisitor(com.intellij.psi.impl.GeneratedMarkerVisitor) FileElement(com.intellij.psi.impl.source.tree.FileElement) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 2 with GeneratedMarkerVisitor

use of com.intellij.psi.impl.GeneratedMarkerVisitor in project intellij-community by JetBrains.

the class EncodeEachSymbolPolicy method encodeXmlTextContents.

@Override
public ASTNode encodeXmlTextContents(String displayText, PsiElement text) {
    if (!toCode(displayText))
        return super.encodeXmlTextContents(displayText, text);
    final FileElement dummyParent = DummyHolderFactory.createHolder(text.getManager(), null, SharedImplUtil.findCharTableByTree(text.getNode())).getTreeElement();
    int sectionStartOffset = 0;
    int offset = 0;
    while (offset < displayText.length()) {
        if (toCode(displayText.charAt(offset))) {
            final String plainSection = displayText.substring(sectionStartOffset, offset);
            if (!plainSection.isEmpty()) {
                dummyParent.rawAddChildren((TreeElement) super.encodeXmlTextContents(plainSection, text));
            }
            dummyParent.rawAddChildren(createCharEntity(displayText.charAt(offset), dummyParent.getCharTable()));
            sectionStartOffset = offset + 1;
        }
        offset++;
    }
    final String plainSection = displayText.substring(sectionStartOffset, offset);
    if (!plainSection.isEmpty()) {
        dummyParent.rawAddChildren((TreeElement) super.encodeXmlTextContents(plainSection, text));
    }
    dummyParent.acceptTree(new GeneratedMarkerVisitor());
    return dummyParent.getFirstChildNode();
}
Also used : GeneratedMarkerVisitor(com.intellij.psi.impl.GeneratedMarkerVisitor) FileElement(com.intellij.psi.impl.source.tree.FileElement)

Example 3 with GeneratedMarkerVisitor

use of com.intellij.psi.impl.GeneratedMarkerVisitor in project intellij-community by JetBrains.

the class JavaSharedImplUtil method normalizeBrackets.

public static void normalizeBrackets(@NotNull PsiVariable variable) {
    CompositeElement variableElement = (CompositeElement) variable.getNode();
    PsiTypeElement typeElement = variable.getTypeElement();
    PsiIdentifier nameElement = variable.getNameIdentifier();
    LOG.assertTrue(typeElement != null && nameElement != null);
    ASTNode type = typeElement.getNode();
    ASTNode name = nameElement.getNode();
    ASTNode firstBracket = null;
    ASTNode lastBracket = null;
    int arrayCount = 0;
    ASTNode element = name;
    while (element != null) {
        element = PsiImplUtil.skipWhitespaceAndComments(element.getTreeNext());
        if (element == null || element.getElementType() != JavaTokenType.LBRACKET)
            break;
        if (firstBracket == null)
            firstBracket = element;
        lastBracket = element;
        arrayCount++;
        element = PsiImplUtil.skipWhitespaceAndComments(element.getTreeNext());
        if (element == null || element.getElementType() != JavaTokenType.RBRACKET)
            break;
        lastBracket = element;
    }
    if (firstBracket != null) {
        element = firstBracket;
        while (true) {
            ASTNode next = element.getTreeNext();
            variableElement.removeChild(element);
            if (element == lastBracket)
                break;
            element = next;
        }
        CompositeElement newType = (CompositeElement) type.clone();
        for (int i = 0; i < arrayCount; i++) {
            CompositeElement newType1 = ASTFactory.composite(JavaElementType.TYPE);
            newType1.rawAddChildren(newType);
            newType1.rawAddChildren(ASTFactory.leaf(JavaTokenType.LBRACKET, "["));
            newType1.rawAddChildren(ASTFactory.leaf(JavaTokenType.RBRACKET, "]"));
            newType = newType1;
            newType.acceptTree(new GeneratedMarkerVisitor());
        }
        newType.putUserData(CharTable.CHAR_TABLE_KEY, SharedImplUtil.findCharTableByTree(type));
        variableElement.replaceChild(type, newType);
    }
}
Also used : GeneratedMarkerVisitor(com.intellij.psi.impl.GeneratedMarkerVisitor) ASTNode(com.intellij.lang.ASTNode)

Aggregations

GeneratedMarkerVisitor (com.intellij.psi.impl.GeneratedMarkerVisitor)3 FileElement (com.intellij.psi.impl.source.tree.FileElement)2 ASTNode (com.intellij.lang.ASTNode)1 CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)1