Search in sources :

Example 31 with IElementType

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

the class FormSourceCodeGenerator method lexemsEqual.

private static boolean lexemsEqual(final PsiClass classToBind, final PsiClass newClass) {
    Lexer oldTextLexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST);
    Lexer newTextLexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST);
    String oldBuffer = classToBind.getText();
    String newBuffer = newClass.getText();
    oldTextLexer.start(oldBuffer);
    newTextLexer.start(newBuffer);
    while (true) {
        IElementType oldLexem = oldTextLexer.getTokenType();
        IElementType newLexem = newTextLexer.getTokenType();
        if (oldLexem == null || newLexem == null) {
            // must terminate at the same time
            return oldLexem == null && newLexem == null;
        }
        if (oldLexem != newLexem) {
            return false;
        }
        if (oldLexem != TokenType.WHITE_SPACE && oldLexem != JavaDocElementType.DOC_COMMENT) {
            int oldStart = oldTextLexer.getTokenStart();
            int newStart = newTextLexer.getTokenStart();
            int oldLength = oldTextLexer.getTokenEnd() - oldTextLexer.getTokenStart();
            int newLength = newTextLexer.getTokenEnd() - newTextLexer.getTokenStart();
            if (oldLength != newLength) {
                return false;
            }
            for (int i = 0; i < oldLength; i++) {
                if (oldBuffer.charAt(oldStart + i) != newBuffer.charAt(newStart + i)) {
                    return false;
                }
            }
        }
        oldTextLexer.advance();
        newTextLexer.advance();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Lexer(com.intellij.lexer.Lexer)

Example 32 with IElementType

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

the class CommandLineParserUtil method bound_argument.

static void bound_argument(@NotNull final PsiBuilder b, final int i) {
    final IElementType tokenType = b.getTokenType();
    final IElementType leftElement = b.rawLookup(-1);
    final IElementType rightElement = b.rawLookup(1);
    if (leftElement == null || TokenType.WHITE_SPACE.equals(leftElement)) {
        return;
    }
    /**
     * At '=' position: if no whitespace to left and right, we move to argument.
     * And we report error if whitespace to the left.
     */
    if (tokenType == CommandLineElementTypes.EQ) {
        if (leftElement.equals(CommandLineElementTypes.LONG_OPTION_NAME_TOKEN)) {
            if (rightElement == null || TokenType.WHITE_SPACE.equals(rightElement)) {
                b.error("Space between argument is its value is unexpected");
            }
            b.advanceLexer();
        }
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType)

Example 33 with IElementType

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

the class RestLexerTest method doTest.

private static void doTest(String text, String... expected) throws IOException {
    _RestFlexLexer lexer = createLexer(text);
    for (String expectedTokenText : expected) {
        IElementType type = lexer.advance();
        if (type == null) {
            fail("Not enough tokens");
        }
        String tokenText = "[" + lexer.yytext() + ", " + type + "]";
        assertEquals(expectedTokenText, tokenText);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) com.jetbrains.rest.lexer._RestFlexLexer(com.jetbrains.rest.lexer._RestFlexLexer)

Example 34 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 35 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)

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