Search in sources :

Example 66 with IElementType

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

the class KtNamedFunction method getReceiverTypeRefByTree.

@Nullable
private KtTypeReference getReceiverTypeRefByTree() {
    PsiElement child = getFirstChild();
    while (child != null) {
        IElementType tt = child.getNode().getElementType();
        if (tt == KtTokens.LPAR || tt == KtTokens.COLON)
            break;
        if (child instanceof KtTypeReference) {
            return (KtTypeReference) child;
        }
        child = child.getNextSibling();
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with IElementType

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

the class KtStubElementType method createStubDependingOnParent.

private static boolean createStubDependingOnParent(ASTNode node) {
    ASTNode parent = node.getTreeParent();
    IElementType parentType = parent.getElementType();
    if (parentType instanceof IStubElementType) {
        return ((IStubElementType) parentType).shouldCreateStub(parent);
    }
    if (parentType instanceof IStubFileElementType) {
        return true;
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) ASTNode(com.intellij.lang.ASTNode) IStubElementType(com.intellij.psi.stubs.IStubElementType)

Example 68 with IElementType

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

the class SemanticWhitespaceAwarePsiBuilderImpl method advanceLexer.

@Override
public void advanceLexer() {
    if (!joinComplexTokens()) {
        super.advanceLexer();
        return;
    }
    IElementType tokenType = getTokenType();
    if (complexTokens.contains(tokenType)) {
        Marker mark = mark();
        super.advanceLexer();
        super.advanceLexer();
        mark.collapse(tokenType);
    } else {
        super.advanceLexer();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType)

Example 69 with IElementType

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

the class SemanticWhitespaceAwarePsiBuilderImpl method newlineBeforeCurrentToken.

@Override
public boolean newlineBeforeCurrentToken() {
    if (!newlinesEnabled.peek())
        return false;
    if (eof())
        return true;
    // TODO: maybe, memoize this somehow?
    for (int i = 1; i <= getCurrentOffset(); i++) {
        IElementType previousToken = rawLookup(-i);
        if (previousToken == KtTokens.BLOCK_COMMENT || previousToken == KtTokens.DOC_COMMENT || previousToken == KtTokens.EOL_COMMENT || previousToken == SHEBANG_COMMENT) {
            continue;
        }
        if (previousToken != TokenType.WHITE_SPACE) {
            break;
        }
        int previousTokenStart = rawTokenTypeStart(-i);
        int previousTokenEnd = rawTokenTypeStart(-i + 1);
        assert previousTokenStart >= 0;
        assert previousTokenEnd < getOriginalText().length();
        for (int j = previousTokenStart; j < previousTokenEnd; j++) {
            if (getOriginalText().charAt(j) == '\n') {
                return true;
            }
        }
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType)

Example 70 with IElementType

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

the class GroovySmartCompletionContributor method inferDiamond.

@Nullable
private static PsiType inferDiamond(PsiElement place) {
    if (!GroovyConfigUtils.getInstance().isVersionAtLeast(place, GroovyConfigUtils.GROOVY1_8)) {
        return null;
    }
    final PsiElement parent = place.getParent().getParent();
    if (!(parent instanceof GrNewExpression))
        return null;
    final PsiElement pparent = parent.getParent();
    if (pparent instanceof GrVariable) {
        return ((GrVariable) pparent).getDeclaredType();
    } else if (pparent instanceof GrAssignmentExpression) {
        GrAssignmentExpression assignment = (GrAssignmentExpression) pparent;
        IElementType optoken = assignment.getOperationTokenType();
        GrExpression lvalue = assignment.getLValue();
        GrExpression rvalue = assignment.getRValue();
        if (parent == rvalue && optoken == GroovyTokenTypes.mASSIGN) {
            return lvalue.getNominalType();
        }
    } else if (pparent instanceof GrApplicationStatement) {
        PsiElement ppparent = pparent.getParent();
        if (ppparent instanceof GrAssignmentExpression) {
            GrAssignmentExpression assignment = (GrAssignmentExpression) ppparent;
            IElementType optoken = assignment.getOperationTokenType();
            GrExpression lvalue = assignment.getLValue();
            GrExpression rvalue = assignment.getRValue();
            if (pparent == rvalue && optoken == GroovyTokenTypes.mASSIGN) {
                return lvalue.getNominalType();
            }
        }
    }
    return null;
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) IElementType(com.intellij.psi.tree.IElementType) Nullable(org.jetbrains.annotations.Nullable)

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