Search in sources :

Example 21 with IElementType

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

the class XsltBreakpointHandler method getActualLineNumber.

public static int getActualLineNumber(Project project, @Nullable XSourcePosition position) {
    if (position == null) {
        return -1;
    }
    final PsiElement element = findContextElement(project, position);
    if (element == null) {
        return -1;
    }
    if (element instanceof XmlToken) {
        final IElementType tokenType = ((XmlToken) element).getTokenType();
        if (tokenType == XmlTokenType.XML_START_TAG_START || tokenType == XmlTokenType.XML_NAME) {
            final PsiManager psiManager = PsiManager.getInstance(project);
            final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
            final PsiFile psiFile = psiManager.findFile(position.getFile());
            if (psiFile == null) {
                return -1;
            }
            final Document document = documentManager.getDocument(psiFile);
            if (document == null) {
                return -1;
            }
            if (document.getLineNumber(element.getTextRange().getStartOffset()) == position.getLine()) {
                final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
                if (tag != null) {
                    final ASTNode node = tag.getNode();
                    assert node != null;
                    // TODO: re-check if/when Xalan is supported
                    final ASTNode end = XmlChildRole.START_TAG_END_FINDER.findChild(node);
                    if (end != null) {
                        return document.getLineNumber(end.getTextRange().getEndOffset()) + 1;
                    } else {
                        final ASTNode end2 = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(node);
                        if (end2 != null) {
                            return document.getLineNumber(end2.getTextRange().getEndOffset()) + 1;
                        }
                    }
                }
            }
        }
    }
    return -1;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 22 with IElementType

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

the class YAMLParser method getShorthandIndentAddition.

private int getShorthandIndentAddition() {
    final int offset = myBuilder.getCurrentOffset();
    final IElementType nextToken = myBuilder.lookAhead(1);
    if (nextToken != SEQUENCE_MARKER && nextToken != SCALAR_KEY) {
        return 1;
    }
    if (myBuilder.rawLookup(1) == WHITESPACE) {
        return myBuilder.rawTokenTypeStart(2) - offset;
    } else {
        return 1;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType)

Example 23 with IElementType

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

the class YAMLParser method advanceLexer.

private void advanceLexer() {
    if (myBuilder.eof()) {
        return;
    }
    final IElementType type = myBuilder.getTokenType();
    eolSeen = eolSeen || type == EOL;
    if (type == EOL) {
        // Drop and create new eolMarker
        myAfterLastEolMarker = mark();
        myIndent = 0;
    } else if (type == INDENT) {
        myIndent = getCurrentTokenLength();
    } else {
        // Drop Eol Marker if other token seen
        dropEolMarker();
    }
    myBuilder.advanceLexer();
}
Also used : IElementType(com.intellij.psi.tree.IElementType)

Example 24 with IElementType

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

the class YAMLParser method parseSingleStatement.

@Nullable
private IElementType parseSingleStatement(int indent) {
    if (eof()) {
        return null;
    }
    final PsiBuilder.Marker marker = mark();
    if (getTokenType() == YAMLTokenTypes.TAG) {
        advanceLexer();
    }
    final IElementType tokenType = getTokenType();
    final IElementType nodeType;
    if (tokenType == LBRACE) {
        nodeType = parseHash();
    } else if (tokenType == LBRACKET) {
        nodeType = parseArray();
    } else if (tokenType == SEQUENCE_MARKER) {
        nodeType = parseSequenceItem(indent);
    } else if (tokenType == QUESTION) {
        nodeType = parseExplicitKeyValue(indent);
    } else if (tokenType == SCALAR_KEY) {
        nodeType = parseScalarKeyValue(indent);
    } else if (YAMLElementTypes.SCALAR_VALUES.contains(getTokenType())) {
        nodeType = parseScalarValue(indent);
    } else {
        advanceLexer();
        nodeType = null;
    }
    if (nodeType != null) {
        marker.done(nodeType);
    } else {
        marker.drop();
    }
    return nodeType;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 25 with IElementType

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

the class YAMLHashImpl method addNewKey.

@Override
protected void addNewKey(@NotNull YAMLKeyValue key) {
    PsiElement anchor = null;
    for (PsiElement child = getLastChild(); child != null; child = child.getPrevSibling()) {
        final IElementType type = child.getNode().getElementType();
        if (type == YAMLTokenTypes.COMMA || type == YAMLTokenTypes.LBRACE) {
            anchor = child;
        }
    }
    addAfter(key, anchor);
    final YAMLFile dummyFile = YAMLElementGenerator.getInstance(getProject()).createDummyYamlWithText("{,}");
    final PsiElement comma = dummyFile.findElementAt(1);
    assert comma != null && comma.getNode().getElementType() == YAMLTokenTypes.COMMA;
    addAfter(comma, key);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) YAMLFile(org.jetbrains.yaml.psi.YAMLFile) PsiElement(com.intellij.psi.PsiElement)

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