Search in sources :

Example 96 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class RestBlock method buildSubBlock.

private RestBlock buildSubBlock(ASTNode child) {
    IElementType parentType = myNode.getElementType();
    IElementType childType = child.getElementType();
    IElementType grandparentType = myNode.getTreeParent() == null ? null : myNode.getTreeParent().getElementType();
    Wrap wrap = null;
    Indent childIndent = Indent.getNoneIndent();
    Alignment childAlignment = null;
    if (grandparentType == RestElementTypes.FIELD_LIST && parentType == RestElementTypes.LINE_TEXT && childType == RestTokenTypes.LINE) {
        childIndent = Indent.getNormalIndent();
    }
    return new RestBlock(this, child, childAlignment, childIndent, wrap);
}
Also used : IElementType(com.intellij.psi.tree.IElementType)

Example 97 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class RestBlock method buildSubBlocks.

private List<RestBlock> buildSubBlocks() {
    List<RestBlock> blocks = new ArrayList<>();
    for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) {
        IElementType childType = child.getElementType();
        if (child.getTextRange().getLength() == 0)
            continue;
        if (childType == RestTokenTypes.WHITESPACE) {
            continue;
        }
        blocks.add(buildSubBlock(child));
    }
    return Collections.unmodifiableList(blocks);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ArrayList(java.util.ArrayList) ASTNode(com.intellij.lang.ASTNode)

Example 98 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class RestParser method parseMarkup.

private static void parseMarkup(PsiBuilder builder) {
    PsiBuilder.Marker marker = builder.mark();
    IElementType type = builder.getTokenType();
    if (type == RestTokenTypes.SUBSTITUTION) {
        builder.advanceLexer();
        marker.done(RestElementTypes.REFERENCE_TARGET);
        builder.advanceLexer();
        marker = builder.mark();
        type = builder.getTokenType();
    }
    if (type == RestTokenTypes.DIRECTIVE) {
        gotoNextWhiteSpaces(builder);
        if (builder.getTokenType() != RestTokenTypes.WHITESPACE) {
            builder.advanceLexer();
            marker.done(RestElementTypes.DIRECTIVE_BLOCK);
            return;
        }
        skipBlankLines(builder);
        if (builder.getTokenType() != RestTokenTypes.WHITESPACE || "\n".equals(builder.getTokenText())) {
            marker.done(RestElementTypes.DIRECTIVE_BLOCK);
            return;
        }
        String white = builder.getTokenText();
        parseDirective(builder, white, marker);
    } else if (type == RestTokenTypes.FOOTNOTE || type == RestTokenTypes.CITATION || type == RestTokenTypes.HYPERLINK || type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
        builder.advanceLexer();
        marker.done(RestElementTypes.REFERENCE_TARGET);
    } else {
        builder.advanceLexer();
        marker.drop();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 99 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class RestParser method parse.

@NotNull
public ASTNode parse(IElementType root, PsiBuilder builder) {
    final PsiBuilder.Marker rootMarker = builder.mark();
    while (!builder.eof()) {
        IElementType type = builder.getTokenType();
        if (type == RestTokenTypes.EXPLISIT_MARKUP_START) {
            builder.advanceLexer();
            parseMarkup(builder);
        } else if (type == RestTokenTypes.REFERENCE_NAME || type == RestTokenTypes.SUBSTITUTION) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestTokenTypes.REFERENCE_NAME);
        } else if (type == RestTokenTypes.TITLE) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestTokenTypes.TITLE);
        } else if (type == RestTokenTypes.FIELD) {
            parseFieldList(builder);
        } else if (type == RestTokenTypes.INLINE_LINE) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestElementTypes.INLINE_BLOCK);
        } else if (type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestElementTypes.REFERENCE_TARGET);
        } else if (type == RestTokenTypes.LINE) {
            parseLineText(builder, type);
        } else
            builder.advanceLexer();
    }
    rootMarker.done(root);
    return builder.getTreeBuilt();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class XmlAttributeImpl method getDisplayValue.

@Override
public String getDisplayValue() {
    String displayText = myDisplayText;
    if (displayText != null)
        return displayText;
    XmlAttributeValue value = getValueElement();
    if (value == null)
        return null;
    PsiElement firstChild = value.getFirstChild();
    if (firstChild == null)
        return null;
    ASTNode child = firstChild.getNode();
    TextRange valueTextRange = new TextRange(0, value.getTextLength());
    if (child != null && child.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER) {
        valueTextRange = new TextRange(child.getTextLength(), valueTextRange.getEndOffset());
        child = child.getTreeNext();
    }
    final TIntArrayList gapsStarts = new TIntArrayList();
    final TIntArrayList gapsShifts = new TIntArrayList();
    StringBuilder buffer = new StringBuilder(getTextLength());
    while (child != null) {
        final int start = buffer.length();
        IElementType elementType = child.getElementType();
        if (elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
            valueTextRange = new TextRange(valueTextRange.getStartOffset(), child.getTextRange().getStartOffset() - value.getTextRange().getStartOffset());
            break;
        }
        if (elementType == XmlTokenType.XML_CHAR_ENTITY_REF) {
            buffer.append(XmlUtil.getCharFromEntityRef(child.getText()));
        } else if (elementType == XmlElementType.XML_ENTITY_REF) {
            buffer.append(XmlUtil.getEntityValue((XmlEntityRef) child));
        } else {
            appendChildToDisplayValue(buffer, child);
        }
        int end = buffer.length();
        int originalLength = child.getTextLength();
        if (end - start != originalLength) {
            gapsStarts.add(start);
            gapsShifts.add(originalLength - (end - start));
        }
        child = child.getTreeNext();
    }
    int[] gapDisplayStarts = ArrayUtil.newIntArray(gapsShifts.size());
    int[] gapPhysicalStarts = ArrayUtil.newIntArray(gapsShifts.size());
    int currentGapsSum = 0;
    for (int i = 0; i < gapDisplayStarts.length; i++) {
        currentGapsSum += gapsShifts.get(i);
        gapDisplayStarts[i] = gapsStarts.get(i);
        gapPhysicalStarts[i] = gapDisplayStarts[i] + currentGapsSum;
    }
    myGapDisplayStarts = gapDisplayStarts;
    myGapPhysicalStarts = gapPhysicalStarts;
    myValueTextRange = valueTextRange;
    return myDisplayText = buffer.toString();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) TIntArrayList(gnu.trove.TIntArrayList)

Aggregations

IElementType (com.intellij.psi.tree.IElementType)843 ASTNode (com.intellij.lang.ASTNode)127 PsiBuilder (com.intellij.lang.PsiBuilder)121 Nullable (org.jetbrains.annotations.Nullable)100 NotNull (org.jetbrains.annotations.NotNull)78 PsiElement (com.intellij.psi.PsiElement)77 TextRange (com.intellij.openapi.util.TextRange)43 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)26 ArrayList (java.util.ArrayList)22 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)22 Lexer (com.intellij.lexer.Lexer)17 GrBinaryExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)15 NonNls (org.jetbrains.annotations.NonNls)14 Document (com.intellij.openapi.editor.Document)13 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)13 LighterASTNode (com.intellij.lang.LighterASTNode)12 BracePair (com.intellij.lang.BracePair)10 Project (com.intellij.openapi.project.Project)9 PsiFile (com.intellij.psi.PsiFile)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9