Java 类com.intellij.lang.WhitespacesBinders 实例源码

项目:intellij-ce-playground    文件:StatementParser.java   
@Nullable
public PsiBuilder.Marker parseCodeBlockDeep(final PsiBuilder builder, final boolean parseUntilEof) {
  if (builder.getTokenType() != JavaTokenType.LBRACE) return null;

  final PsiBuilder.Marker codeBlock = builder.mark();
  builder.advanceLexer();

  parseStatements(builder, parseUntilEof ? BraceMode.TILL_LAST : BraceMode.TILL_FIRST);

  final boolean greedyBlock = !expectOrError(builder, JavaTokenType.RBRACE, "expected.rbrace");
  builder.getTokenType(); // eat spaces

  done(codeBlock, JavaElementType.CODE_BLOCK);
  if (greedyBlock) {
    codeBlock.setCustomEdgeTokenBinders(null, WhitespacesBinders.GREEDY_RIGHT_BINDER);
  }
  return codeBlock;
}
项目:consulo-java    文件:StatementParser.java   
@Nullable
public PsiBuilder.Marker parseCodeBlockDeep(final PsiBuilder builder, final boolean parseUntilEof)
{
    if(builder.getTokenType() != JavaTokenType.LBRACE)
    {
        return null;
    }

    final PsiBuilder.Marker codeBlock = builder.mark();
    builder.advanceLexer();

    parseStatements(builder, parseUntilEof ? BraceMode.TILL_LAST : BraceMode.TILL_FIRST);

    final boolean greedyBlock = !expectOrError(builder, JavaTokenType.RBRACE, "expected.rbrace");
    builder.getTokenType(); // eat spaces

    done(codeBlock, JavaElementType.CODE_BLOCK);
    if(greedyBlock)
    {
        codeBlock.setCustomEdgeTokenBinders(null, WhitespacesBinders.GREEDY_RIGHT_BINDER);
    }
    return codeBlock;
}
项目:intellij-ce-playground    文件:FunctionParsing.java   
public void parseDecoratedDeclaration() {
  assertCurrentToken(PyTokenTypes.AT); // ??? need this?
  final PsiBuilder.Marker decoratorStartMarker = myBuilder.mark();
  final PsiBuilder.Marker decoListMarker = myBuilder.mark();
  boolean decorated = false;
  while (myBuilder.getTokenType() == PyTokenTypes.AT) {
    PsiBuilder.Marker decoratorMarker = myBuilder.mark();
    myBuilder.advanceLexer();
    getStatementParser().parseDottedName();
    if (myBuilder.getTokenType() == PyTokenTypes.LPAR) {
      getExpressionParser().parseArgumentList();
    }
    else { // empty arglist node, so we always have it
      PsiBuilder.Marker argListMarker = myBuilder.mark();
      argListMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, null);
      argListMarker.done(PyElementTypes.ARGUMENT_LIST);
    }
    if (atToken(PyTokenTypes.STATEMENT_BREAK)) {
      decoratorMarker.done(PyElementTypes.DECORATOR_CALL);
      nextToken();
    }
    else {
      myBuilder.error(message("PARSE.expected.statement.break"));
      decoratorMarker.done(PyElementTypes.DECORATOR_CALL);
    }
    decorated = true;
  }
  if (decorated) decoListMarker.done(PyElementTypes.DECORATOR_LIST);
  //else decoListMarker.rollbackTo();
  parseDeclarationAfterDecorator(decoratorStartMarker);
}
项目:consulo-csharp    文件:SharedParsingHelpers.java   
public static void reportIdentifier(PsiBuilder builder, int flags)
{
    PsiBuilder.Marker mark = builder.mark();
    builder.error("Expected identifier");
    mark.done(BitUtil.isSet(flags, STUB_SUPPORT) ? CSharpStubElements.IDENTIFIER : CSharpElements.IDENTIFIER);
    mark.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, null);
}
项目:intellij-ce-playground    文件:StatementParser.java   
@Nullable
public PsiBuilder.Marker parseCodeBlock(final PsiBuilder builder, final boolean isStatement) {
  if (builder.getTokenType() != JavaTokenType.LBRACE) return null;
  else if (isStatement && isParseStatementCodeBlocksDeep(builder)) return parseCodeBlockDeep(builder, false);

  final PsiBuilder.Marker codeBlock = builder.mark();
  builder.advanceLexer();

  boolean greedyBlock = false;
  int braceCount = 1;
  while (true) {
    final IElementType tokenType = builder.getTokenType();
    if (tokenType == null) {
      greedyBlock = true;
      break;
    }
    if (tokenType == JavaTokenType.LBRACE) {
      braceCount++;
    }
    else if (tokenType == JavaTokenType.RBRACE) {
      braceCount--;
    }
    builder.advanceLexer();

    if (braceCount == 0) {
      break;
    }
    else if (braceCount == 1 && (tokenType == JavaTokenType.SEMICOLON || tokenType == JavaTokenType.RBRACE)) {
      final PsiBuilder.Marker position = builder.mark();
      final List<IElementType> list = new SmartList<IElementType>();
      while (true) {
        final IElementType type = builder.getTokenType();
        if (ElementType.PRIMITIVE_TYPE_BIT_SET.contains(type) || ElementType.MODIFIER_BIT_SET.contains(type) ||
            (type == JavaTokenType.IDENTIFIER && list.size() > 0) || type == JavaTokenType.LT || type == JavaTokenType.GT ||
            type == JavaTokenType.GTGT || type == JavaTokenType.GTGTGT || type == JavaTokenType.COMMA ||
            type == JavaTokenType.DOT || type == JavaTokenType.EXTENDS_KEYWORD || type == JavaTokenType.IMPLEMENTS_KEYWORD) {
          list.add(type);
          builder.advanceLexer();
        }
        else {
          break;
        }
      }
      if (builder.getTokenType() == JavaTokenType.LPARENTH && list.size() >= 2) {
        final IElementType last = list.get(list.size() - 1);
        final IElementType prevLast = list.get(list.size() - 2);
        if (last == JavaTokenType.IDENTIFIER &&
            (prevLast == JavaTokenType.IDENTIFIER || ElementType.PRIMITIVE_TYPE_BIT_SET.contains(prevLast))) {
          position.rollbackTo();
          greedyBlock = true;
          break;
        }
      }
      position.drop();
    }
  }

  codeBlock.collapse(JavaElementType.CODE_BLOCK);
  if (greedyBlock) {
    codeBlock.setCustomEdgeTokenBinders(null, WhitespacesBinders.GREEDY_RIGHT_BINDER);
  }
  return codeBlock;
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@NotNull
public PsiBuilder.Marker parseArgumentList(final PsiBuilder builder) {
  final PsiBuilder.Marker list = builder.mark();
  builder.advanceLexer();

  boolean first = true;
  while (true) {
    final IElementType tokenType = builder.getTokenType();
    if (first && (ARGS_LIST_END.contains(tokenType) || builder.eof())) break;
    if (!first && !ARGS_LIST_CONTINUE.contains(tokenType)) break;

    boolean hasError = false;
    if (!first) {
      if (builder.getTokenType() == JavaTokenType.COMMA) {
        builder.advanceLexer();
      }
      else {
        hasError = true;
        error(builder, JavaErrorMessages.message("expected.comma.or.rparen"));
        emptyExpression(builder);
      }
    }
    first = false;

    final PsiBuilder.Marker arg = parse(builder);
    if (arg == null) {
      if (!hasError) {
        error(builder, JavaErrorMessages.message("expected.expression"));
        emptyExpression(builder);
      }
      if (!ARGS_LIST_CONTINUE.contains(builder.getTokenType())) break;
      if (builder.getTokenType() != JavaTokenType.COMMA && !builder.eof()) {
        builder.advanceLexer();
      }
    }
  }

  final boolean closed = expectOrError(builder, JavaTokenType.RPARENTH, "expected.rparen");

  list.done(JavaElementType.EXPRESSION_LIST);
  if (!closed) {
    list.setCustomEdgeTokenBinders(null, WhitespacesBinders.GREEDY_RIGHT_BINDER);
  }
  return list;
}
项目:consulo-java    文件:StatementParser.java   
@Nullable
public PsiBuilder.Marker parseCodeBlock(final PsiBuilder builder, final boolean isStatement)
{
    if(builder.getTokenType() != JavaTokenType.LBRACE)
    {
        return null;
    }
    else if(isStatement && isParseStatementCodeBlocksDeep(builder))
    {
        return parseCodeBlockDeep(builder, false);
    }

    final PsiBuilder.Marker codeBlock = builder.mark();
    builder.advanceLexer();

    boolean greedyBlock = false;
    int braceCount = 1;
    while(true)
    {
        final IElementType tokenType = builder.getTokenType();
        if(tokenType == null)
        {
            greedyBlock = true;
            break;
        }
        if(tokenType == JavaTokenType.LBRACE)
        {
            braceCount++;
        }
        else if(tokenType == JavaTokenType.RBRACE)
        {
            braceCount--;
        }
        builder.advanceLexer();

        if(braceCount == 0)
        {
            break;
        }
        else if(braceCount == 1 && (tokenType == JavaTokenType.SEMICOLON || tokenType == JavaTokenType.RBRACE))
        {
            final PsiBuilder.Marker position = builder.mark();
            final List<IElementType> list = new SmartList<>();
            while(true)
            {
                final IElementType type = builder.getTokenType();
                if(ElementType.PRIMITIVE_TYPE_BIT_SET.contains(type) || ElementType.MODIFIER_BIT_SET.contains(type) || (type == JavaTokenType.IDENTIFIER && list.size() > 0) || type ==
                        JavaTokenType.LT || type == JavaTokenType.GT || type == JavaTokenType.GTGT || type == JavaTokenType.GTGTGT || type == JavaTokenType.COMMA || type == JavaTokenType.DOT ||
                        type == JavaTokenType.EXTENDS_KEYWORD || type == JavaTokenType.IMPLEMENTS_KEYWORD)
                {
                    list.add(type);
                    builder.advanceLexer();
                }
                else
                {
                    break;
                }
            }
            if(builder.getTokenType() == JavaTokenType.LPARENTH && list.size() >= 2)
            {
                final IElementType last = list.get(list.size() - 1);
                final IElementType prevLast = list.get(list.size() - 2);
                if(last == JavaTokenType.IDENTIFIER && (prevLast == JavaTokenType.IDENTIFIER || ElementType.PRIMITIVE_TYPE_BIT_SET.contains(prevLast)))
                {
                    position.rollbackTo();
                    greedyBlock = true;
                    break;
                }
            }
            position.drop();
        }
    }

    codeBlock.collapse(JavaElementType.CODE_BLOCK);
    if(greedyBlock)
    {
        codeBlock.setCustomEdgeTokenBinders(null, WhitespacesBinders.GREEDY_RIGHT_BINDER);
    }
    return codeBlock;
}
项目:consulo-java    文件:ExpressionParser.java   
@NotNull
public PsiBuilder.Marker parseArgumentList(final PsiBuilder builder)
{
    final PsiBuilder.Marker list = builder.mark();
    builder.advanceLexer();

    boolean first = true;
    while(true)
    {
        final IElementType tokenType = builder.getTokenType();
        if(first && (ARGS_LIST_END.contains(tokenType) || builder.eof()))
        {
            break;
        }
        if(!first && !ARGS_LIST_CONTINUE.contains(tokenType))
        {
            break;
        }

        boolean hasError = false;
        if(!first)
        {
            if(builder.getTokenType() == JavaTokenType.COMMA)
            {
                builder.advanceLexer();
            }
            else
            {
                hasError = true;
                error(builder, JavaErrorMessages.message("expected.comma.or.rparen"));
                emptyExpression(builder);
            }
        }
        first = false;

        final PsiBuilder.Marker arg = parse(builder);
        if(arg == null)
        {
            if(!hasError)
            {
                error(builder, JavaErrorMessages.message("expected.expression"));
                emptyExpression(builder);
            }
            if(!ARGS_LIST_CONTINUE.contains(builder.getTokenType()))
            {
                break;
            }
            if(builder.getTokenType() != JavaTokenType.COMMA && !builder.eof())
            {
                builder.advanceLexer();
            }
        }
    }

    final boolean closed = expectOrError(builder, JavaTokenType.RPARENTH, "expected.rparen");

    list.done(JavaElementType.EXPRESSION_LIST);
    if(!closed)
    {
        list.setCustomEdgeTokenBinders(null, WhitespacesBinders.GREEDY_RIGHT_BINDER);
    }
    return list;
}