Java 类com.intellij.psi.tree.IErrorCounterReparseableElementType 实例源码

项目:consulo-java    文件:JavaElementType.java   
@Override
public int getErrorsCount(final CharSequence seq, Language fileLanguage, final Project project)
{
    final Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST);

    lexer.start(seq);
    if(lexer.getTokenType() != JavaTokenType.LBRACE)
    {
        return IErrorCounterReparseableElementType.FATAL_ERROR;
    }
    lexer.advance();
    int balance = 1;
    while(true)
    {
        IElementType type = lexer.getTokenType();
        if(type == null)
        {
            break;
        }
        if(balance == 0)
        {
            return IErrorCounterReparseableElementType.FATAL_ERROR;
        }
        if(type == JavaTokenType.LBRACE)
        {
            balance++;
        }
        else if(type == JavaTokenType.RBRACE)
        {
            balance--;
        }
        lexer.advance();
    }
    return balance;
}