Java 类com.intellij.psi.impl.source.tree.JavaElementType 实例源码

项目:intellij-ce-playground    文件:SimpleJavaBlock.java   
@Override
@NotNull
public ChildAttributes getChildAttributes(final int newChildIndex) {
  if (myNode.getElementType() == JavaElementType.CONDITIONAL_EXPRESSION && mySettings.ALIGN_MULTILINE_TERNARY_OPERATION) {
    final Alignment usedAlignment = getUsedAlignment(newChildIndex);
    if (usedAlignment != null) {
      return new ChildAttributes(null, usedAlignment);
    }
    else {
      return super.getChildAttributes(newChildIndex);
    }
  }
  else if (myNode.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT) {
    return new ChildAttributes(Indent.getNormalIndent(), null);
  }
  else {
    return super.getChildAttributes(newChildIndex);
  }
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseForEachFromColon(PsiBuilder builder, PsiBuilder.Marker statement) {
  builder.advanceLexer();

  final PsiBuilder.Marker expr = myParser.getExpressionParser().parse(builder);
  if (expr == null) {
    error(builder, JavaErrorMessages.message("expected.expression"));
  }

  if (expect(builder, JavaTokenType.RPARENTH)) {
    final PsiBuilder.Marker bodyStatement = parseStatement(builder);
    if (bodyStatement == null) {
      error(builder, JavaErrorMessages.message("expected.statement"));
    }
  }
  else {
    error(builder, JavaErrorMessages.message("expected.rparen"));
  }

  done(statement, JavaElementType.FOREACH_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseDoWhileStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();

  final PsiBuilder.Marker body = parseStatement(builder);
  if (body == null) {
    error(builder, JavaErrorMessages.message("expected.statement"));
    done(statement, JavaElementType.DO_WHILE_STATEMENT);
    return statement;
  }

  if (!expect(builder, JavaTokenType.WHILE_KEYWORD)) {
    error(builder, JavaErrorMessages.message("expected.while"));
    done(statement, JavaElementType.DO_WHILE_STATEMENT);
    return statement;
  }

  if (parseExpressionInParenth(builder)) {
    semicolon(builder);
  }

  done(statement, JavaElementType.DO_WHILE_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseThrowStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();

  final PsiBuilder.Marker expr = myParser.getExpressionParser().parse(builder);
  if (expr == null) {
    error(builder, JavaErrorMessages.message("expected.expression"));
    done(statement, JavaElementType.THROW_STATEMENT);
    return statement;
  }

  semicolon(builder);
  done(statement, JavaElementType.THROW_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseSynchronizedStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();

  if (!parseExpressionInParenth(builder)) {
    done(statement, JavaElementType.SYNCHRONIZED_STATEMENT);
    return statement;
  }

  final PsiBuilder.Marker body = parseCodeBlock(builder, true);
  if (body == null) {
    error(builder, JavaErrorMessages.message("expected.lbrace"));
  }

  done(statement, JavaElementType.SYNCHRONIZED_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@Nullable
private PsiBuilder.Marker parseAssignment(final PsiBuilder builder) {
  final PsiBuilder.Marker left = parseConditional(builder);
  if (left == null) return null;

  final IElementType tokenType = getGtTokenType(builder);
  if (ASSIGNMENT_OPS.contains(tokenType) && tokenType != null) {
    final PsiBuilder.Marker assignment = left.precede();
    advanceGtToken(builder, tokenType);

    final PsiBuilder.Marker right = parse(builder);
    if (right == null) {
      error(builder, JavaErrorMessages.message("expected.expression"));
    }

    assignment.done(JavaElementType.ASSIGNMENT_EXPRESSION);
    return assignment;
  }

  return left;
}
项目:intellij-ce-playground    文件:CodeBlockBlock.java   
/**
 * There is a possible case that 'implements' section is incomplete (e.g. ends with comma). We may want to align lbrace
 * to the comma then.
 *
 * @param alignment     block alignment
 * @param baseNode      base AST node
 * @return              alignment strategy to use for the given node
 */
private static AlignmentStrategy getAlignmentStrategy(Alignment alignment, ASTNode baseNode, @NotNull CommonCodeStyleSettings settings) {
  if (baseNode.getElementType() != JavaElementType.CLASS || !settings.ALIGN_MULTILINE_EXTENDS_LIST) {
    return AlignmentStrategy.wrap(alignment);
  }
  for (ASTNode node = baseNode.getLastChildNode(); node != null; node = FormatterUtil.getPreviousNonWhitespaceSibling(node)) {
    if (node.getElementType() != JavaElementType.IMPLEMENTS_LIST) {
      continue;
    }
    ASTNode lastChildNode = node.getLastChildNode();
    if (lastChildNode != null && lastChildNode.getElementType() == TokenType.ERROR_ELEMENT) {
      Alignment alignmentToUse = alignment;
      if (alignment == null) {
        alignmentToUse = Alignment.createAlignment();
      }
      return AlignmentStrategy.wrap(
        alignmentToUse, false, JavaTokenType.LBRACE, JavaElementType.JAVA_CODE_REFERENCE, node.getElementType()
      );
    }
    break;
  }
  return AlignmentStrategy.wrap(alignment);
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@Nullable
private static PsiBuilder.Marker parseClassObjectAccess(PsiBuilder builder, PsiBuilder.Marker expr, boolean optionalClassKeyword) {
  final PsiBuilder.Marker mark = builder.mark();
  builder.advanceLexer();

  if (builder.getTokenType() == JavaTokenType.CLASS_KEYWORD) {
    mark.drop();
    builder.advanceLexer();
  }
  else {
    if (!optionalClassKeyword) return null;
    mark.rollbackTo();
    builder.error(".class expected");
  }

  expr.done(JavaElementType.CLASS_OBJECT_ACCESS_EXPRESSION);
  return expr;
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@Nullable
private PsiBuilder.Marker parseLambdaExpression(final PsiBuilder builder, final boolean typed, @Nullable final PsiBuilder.Marker typeList) {
  final PsiBuilder.Marker start = typeList != null ? typeList.precede() : builder.mark();

  myParser.getDeclarationParser().parseLambdaParameterList(builder, typed);

  if (!expect(builder, JavaTokenType.ARROW)) {
    start.rollbackTo();
    return null;
  }

  final PsiBuilder.Marker body;
  if (builder.getTokenType() == JavaTokenType.LBRACE) {
    body = myParser.getStatementParser().parseCodeBlock(builder);
  }
  else {
    body = parse(builder);
  }

  if (body == null) {
    builder.error(JavaErrorMessages.message("expected.lbrace"));
  }

  start.done(JavaElementType.LAMBDA_EXPRESSION);
  return start;
}
项目:intellij-ce-playground    文件:ReferenceParser.java   
@Nullable
public PsiBuilder.Marker parseTypeParameter(final PsiBuilder builder) {
  final PsiBuilder.Marker param = builder.mark();

  myParser.getDeclarationParser().parseAnnotations(builder);

  if (isKeywordAny(builder)) {
    dummy(builder);
  }

  final boolean wild = expect(builder, JavaTokenType.QUEST);
  if (!wild && !expect(builder, JavaTokenType.IDENTIFIER)) {
    param.rollbackTo();
    return null;
  }

  parseReferenceList(builder, JavaTokenType.EXTENDS_KEYWORD, JavaElementType.EXTENDS_BOUND_LIST, JavaTokenType.AND);

  if (!wild) {
    param.done(JavaElementType.TYPE_PARAMETER);
  }
  else {
    param.error(JavaErrorMessages.message("wildcard.not.expected"));
  }
  return param;
}
项目:intellij-ce-playground    文件:DeclarationParser.java   
private boolean parseAnnotationParameter(final PsiBuilder builder, final boolean mayBeSimple) {
  PsiBuilder.Marker pair = builder.mark();

  if (mayBeSimple) {
    parseAnnotationValue(builder);
    if (builder.getTokenType() != JavaTokenType.EQ) {
      done(pair, JavaElementType.NAME_VALUE_PAIR);
      return false;
    }

    pair.rollbackTo();
    pair = builder.mark();
  }

  final boolean hasName = expectOrError(builder, JavaTokenType.IDENTIFIER, "expected.identifier");

  expectOrError(builder, JavaTokenType.EQ, "expected.eq");

  parseAnnotationValue(builder);

  done(pair, JavaElementType.NAME_VALUE_PAIR);

  return hasName;
}
项目:intellij-ce-playground    文件:BlockContainingJavaBlock.java   
private static int calcNewState(final ASTNode child, final int state) {
  if (state == BEFORE_FIRST) {
    if (child.getElementType() == JavaTokenType.ELSE_KEYWORD) {
      return AFTER_ELSE;
    }
    if (StdTokenSets.COMMENT_BIT_SET.contains(child.getElementType())) {
      return BEFORE_FIRST;
    }
    if (child.getElementType() == JavaElementType.CATCH_SECTION) {
      return BEFORE_FIRST;
    }
  } else if (state == BEFORE_BLOCK){
    if (child.getElementType() == JavaTokenType.ELSE_KEYWORD) {
      return AFTER_ELSE;
    }
    if (child.getElementType() == JavaElementType.BLOCK_STATEMENT) {
      return BEFORE_FIRST;
    }
    if (child.getElementType() == JavaElementType.CODE_BLOCK) {
      return BEFORE_FIRST;
    }

  }
  return BEFORE_BLOCK;
}
项目:intellij-ce-playground    文件:ImportStaticStatementElement.java   
@Override
public ASTNode findChildByRole(int role) {
  final ASTNode result = super.findChildByRole(role);
  if (result != null) return result;
  switch (role) {
    default:
      return null;

    case ChildRole.IMPORT_REFERENCE:
      final ASTNode importStaticReference = findChildByType(JavaElementType.IMPORT_STATIC_REFERENCE);
      if (importStaticReference != null) {
        return importStaticReference;
      }
      else {
        return findChildByType(JavaElementType.JAVA_CODE_REFERENCE);
      }
  }
}
项目:intellij-ce-playground    文件:LombokPsiConverter.java   
@NonNull
private static Statement toVariableDeclaration(@NonNull PsiDeclarationStatement statement) {
  PsiElement[] declaredElements = statement.getDeclaredElements();
  if (declaredElements.length == 1 && declaredElements[0].getNode().getElementType() == JavaElementType.CLASS) {
    // Class declaration inside method
    TypeDeclaration typeDeclaration = toTypeDeclaration((PsiClass)declaredElements[0]);
    if (typeDeclaration instanceof Statement) {
      return (Statement)typeDeclaration;
    }
    throw new UnsupportedOperationException("Non-statement type declaration: " + statement);
  }

  VariableDeclaration declaration = new VariableDeclaration();
  bind(declaration, statement);
  VariableDefinition definition = toVariableDefinition(statement, declaredElements);
  declaration.astDefinition(definition);

  return declaration;
}
项目:intellij-ce-playground    文件:JavaFileElement.java   
@Override
public int getChildRole(ASTNode child) {
  LOG.assertTrue(child.getTreeParent() == this);
  IElementType i = child.getElementType();
  if (i == JavaElementType.PACKAGE_STATEMENT) {
    return ChildRole.PACKAGE_STATEMENT;
  }
  else if (i == JavaElementType.IMPORT_LIST) {
    return ChildRole.IMPORT_LIST;
  }
  else if (i == JavaElementType.CLASS) {
    return ChildRole.CLASS;
  }
  else {
    return ChildRoleBase.NONE;
  }
}
项目:intellij-ce-playground    文件:PsiBuilderTest.java   
public void testProgramWithSingleKeyword() throws Exception {
  myBuilder = createBuilder("package");

  final PsiBuilder.Marker fileMarker = myBuilder.mark();
  assertEquals("package", myBuilder.getTokenText());
  assertEquals(JavaTokenType.PACKAGE_KEYWORD, myBuilder.getTokenType());
  final PsiBuilder.Marker packageStatementMarker = myBuilder.mark();
  myBuilder.advanceLexer();
  assertTrue(myBuilder.eof());
  packageStatementMarker.done(JavaElementType.PACKAGE_STATEMENT);
  fileMarker.done(JavaStubElementTypes.JAVA_FILE);

  ASTNode fileNode = myBuilder.getTreeBuilt();
  assertNotNull(fileNode);
  assertEquals("package", fileNode.getText());
  assertSame(fileNode.getFirstChildNode(), fileNode.getLastChildNode());
  ASTNode packageNode = fileNode.getFirstChildNode();
  assertNotNull(packageNode);
  assertEquals("package", packageNode.getText());
  assertEquals(JavaElementType.PACKAGE_STATEMENT, packageNode.getElementType());

  ASTNode leaf = packageNode.getFirstChildNode();
  assertNotNull(leaf);
  assertEquals(JavaTokenType.PACKAGE_KEYWORD, leaf.getElementType());
}
项目:intellij-ce-playground    文件:ParameterElement.java   
@Override
public int getChildRole(ASTNode child) {
  LOG.assertTrue(child.getTreeParent() == this);

  IElementType i = child.getElementType();
  if (i == JavaElementType.MODIFIER_LIST) {
    return ChildRole.MODIFIER_LIST;
  }
  else if (i == JavaElementType.TYPE) {
    return getChildRole(child, ChildRole.TYPE);
  }
  else if (i == JavaTokenType.IDENTIFIER) {
    return getChildRole(child, ChildRole.NAME);
  }
  else {
    return ChildRoleBase.NONE;
  }
}
项目:intellij-ce-playground    文件:PsiReferenceListImpl.java   
@Override
public Role getRole() {
  IElementType type = getElementType();
  if (type == JavaElementType.EXTENDS_LIST) {
    return Role.EXTENDS_LIST;
  }
  else if (type == JavaElementType.IMPLEMENTS_LIST) {
    return Role.IMPLEMENTS_LIST;
  }
  else if (type == JavaElementType.THROWS_LIST) {
    return Role.THROWS_LIST;
  }
  else if (type == JavaElementType.EXTENDS_BOUND_LIST) {
    return Role.EXTENDS_BOUNDS_LIST;
  }

  LOG.error("Unknown element type:" + type);
  return null;
}
项目:intellij-ce-playground    文件:ImplementsListElement.java   
@Override
public int getChildRole(ASTNode child) {
  LOG.assertTrue(child.getTreeParent() == this);
  IElementType i = child.getElementType();
  if (i == JavaTokenType.IMPLEMENTS_KEYWORD) {
    return ChildRole.IMPLEMENTS_KEYWORD;
  }
  else if (i == JavaTokenType.COMMA) {
    return ChildRole.COMMA;
  }
  else if (i == JavaElementType.JAVA_CODE_REFERENCE) {
    return ChildRole.REFERENCE_IN_LIST;
  }
  else {
    return ChildRoleBase.NONE;
  }
}
项目:intellij-ce-playground    文件:ImportStatementBaseElement.java   
@Override
public int getChildRole(ASTNode child) {
  LOG.assertTrue(child.getTreeParent() == this);
  IElementType i = child.getElementType();
  if (i == JavaTokenType.IMPORT_KEYWORD) {
    return ChildRole.IMPORT_KEYWORD;
  }
  else if (i == JavaElementType.JAVA_CODE_REFERENCE) {
    return ChildRole.IMPORT_REFERENCE;
  }
  else if (i == JavaTokenType.DOT) {
    return ChildRole.IMPORT_ON_DEMAND_DOT;
  }
  else if (i == JavaTokenType.ASTERISK) {
    return ChildRole.IMPORT_ON_DEMAND_ASTERISK;
  }
  else if (i == JavaTokenType.SEMICOLON) {
    return ChildRole.CLOSING_SEMICOLON;
  }
  else {
    return ChildRoleBase.NONE;
  }
}
项目:intellij-ce-playground    文件:JavaFoldingBuilderBase.java   
@Override
protected boolean isCustomFoldingRoot(ASTNode node) {
  IElementType nodeType = node.getElementType();
  if (nodeType == JavaElementType.CLASS) {
    ASTNode parent = node.getTreeParent();
    return parent == null || parent.getElementType() != JavaElementType.CLASS;
  }
  return nodeType == JavaElementType.CODE_BLOCK;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseIfStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();

  if (!parseExpressionInParenth(builder)) {
    done(statement, JavaElementType.IF_STATEMENT);
    return statement;
  }

  final PsiBuilder.Marker thenStatement = parseStatement(builder);
  if (thenStatement == null) {
    error(builder, JavaErrorMessages.message("expected.statement"));
    done(statement, JavaElementType.IF_STATEMENT);
    return statement;
  }

  if (!expect(builder, JavaTokenType.ELSE_KEYWORD)) {
    done(statement, JavaElementType.IF_STATEMENT);
    return statement;
  }

  final PsiBuilder.Marker elseStatement = parseStatement(builder);
  if (elseStatement == null) {
    error(builder, JavaErrorMessages.message("expected.statement"));
  }

  done(statement, JavaElementType.IF_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:CodeBlockBlock.java   
@Nullable
private ASTNode processCaseAndStatementAfter(final ArrayList<Block> result,
                                             ASTNode child,
                                             final Alignment childAlignment,
                                             final Wrap childWrap, final Indent indent) {
  final ArrayList<Block> localResult = new ArrayList<Block>();
  processChild(localResult, child, AlignmentStrategy.getNullStrategy(), null, Indent.getNoneIndent());
  child = child.getTreeNext();
  Indent childIndent = Indent.getNormalIndent();
  while (child != null) {
    if (child.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT || isRBrace(child)) {
      result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap));
      return child.getTreePrev();
    }

    if (!FormatterUtil.containsWhiteSpacesOnly(child)) {

      if (child.getElementType() == JavaElementType.BLOCK_STATEMENT) {
        childIndent = Indent.getNoneIndent();
      }

      boolean breakOrReturn = isBreakOrReturn(child);
      processChild(localResult, child, AlignmentStrategy.getNullStrategy(), null, childIndent);
      if (breakOrReturn) {
        result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap));
        return child;
      }
    }

    child = child.getTreeNext();
  }
  result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap));
  return null;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private static PsiBuilder.Marker parseBreakStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();
  expect(builder, JavaTokenType.IDENTIFIER);
  semicolon(builder);
  done(statement, JavaElementType.BREAK_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private static PsiBuilder.Marker parseContinueStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();
  expect(builder, JavaTokenType.IDENTIFIER);
  semicolon(builder);
  done(statement, JavaElementType.CONTINUE_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseReturnStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();

  myParser.getExpressionParser().parse(builder);

  semicolon(builder);
  done(statement, JavaElementType.RETURN_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseTryStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  builder.advanceLexer();

  final boolean hasResourceList = builder.getTokenType() == JavaTokenType.LPARENTH;
  if (hasResourceList) {
    myParser.getDeclarationParser().parseResourceList(builder);
  }

  final PsiBuilder.Marker tryBlock = parseCodeBlock(builder, true);
  if (tryBlock == null) {
    error(builder, JavaErrorMessages.message("expected.lbrace"));
    done(statement, JavaElementType.TRY_STATEMENT);
    return statement;
  }

  if (!hasResourceList && !TRY_CLOSERS_SET.contains(builder.getTokenType())) {
    error(builder, JavaErrorMessages.message("expected.catch.or.finally"));
    done(statement, JavaElementType.TRY_STATEMENT);
    return statement;
  }

  while (builder.getTokenType() == JavaTokenType.CATCH_KEYWORD) {
    if (!parseCatchBlock(builder)) break;
  }

  if (expect(builder, JavaTokenType.FINALLY_KEYWORD)) {
    final PsiBuilder.Marker finallyBlock = parseCodeBlock(builder, true);
    if (finallyBlock == null) {
      error(builder, JavaErrorMessages.message("expected.lbrace"));
    }
  }

  done(statement, JavaElementType.TRY_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:StatementParser.java   
@NotNull
private PsiBuilder.Marker parseBlockStatement(final PsiBuilder builder) {
  final PsiBuilder.Marker statement = builder.mark();
  parseCodeBlock(builder, true);
  done(statement, JavaElementType.BLOCK_STATEMENT);
  return statement;
}
项目:intellij-ce-playground    文件:PsiLambdaExpressionImpl.java   
@Override
public int getChildRole(ASTNode child) {
  final IElementType elType = child.getElementType();
  if (elType == JavaTokenType.ARROW) {
    return ChildRole.ARROW;
  } else if (elType == JavaElementType.PARAMETER_LIST) {
    return ChildRole.PARAMETER_LIST;
  } else if (elType == JavaElementType.CODE_BLOCK) {
    return ChildRole.LBRACE;
  } else {
    return ChildRole.EXPRESSION;
  }
}
项目:intellij-ce-playground    文件:BlockContainingJavaBlock.java   
private void buildChildren(final ArrayList<Block> result, final Alignment childAlignment, final Wrap childWrap) {
  ASTNode child = myNode.getFirstChildNode();
  ASTNode prevChild = null;

  int state = BEFORE_FIRST;

  while (child != null) {
    if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0){
      final Indent indent = calcIndent(child,  state);
      myIndentsBefore.add(calcIndentBefore(child,  state));
      state = calcNewState(child, state);

      // The general idea is that it's possible that there are comment lines before method declaration line and that they have
      // different indents. Example:
      //
      //     // This is comment before method
      //               void foo() {}
      //
      // We want to have the comment and method as distinct blocks then in order to correctly process indentation for inner method
      // elements. See IDEA-53778 for example of situation when it is significant.
      if (prevChild != null && myNode.getElementType() == JavaElementType.METHOD
          && ElementType.JAVA_COMMENT_BIT_SET.contains(prevChild.getElementType())
          && !ElementType.JAVA_COMMENT_BIT_SET.contains(child.getElementType()))
      {
        prevChild = child;
        child = composeCodeBlock(result, child, Indent.getNoneIndent(), 0, null);
      }
      else {
        prevChild = child;
        child = processChild(result, child, childAlignment, childWrap, indent);
      }                
      for (int i = myIndentsBefore.size(); i < result.size(); i++) {
        myIndentsBefore.add(Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS));
      }
    }
    if (child != null) {
      child = child.getTreeNext();
    }
  }
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@Nullable
public PsiBuilder.Marker parseConditional(final PsiBuilder builder) {
  final PsiBuilder.Marker condition = parseExpression(builder, ExprType.CONDITIONAL_OR);
  if (condition == null) return null;

  if (builder.getTokenType() != JavaTokenType.QUEST) return condition;
  final PsiBuilder.Marker ternary = condition.precede();
  builder.advanceLexer();

  final PsiBuilder.Marker truePart = parse(builder);
  if (truePart == null) {
    error(builder, JavaErrorMessages.message("expected.expression"));
    ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
    return ternary;
  }

  if (builder.getTokenType() != JavaTokenType.COLON) {
    error(builder, JavaErrorMessages.message("expected.colon"));
    ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
    return ternary;
  }
  builder.advanceLexer();

  final PsiBuilder.Marker falsePart = parseConditional(builder);
  if (falsePart == null) {
    error(builder, JavaErrorMessages.message("expected.expression"));
    ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
    return ternary;
  }

  ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
  return ternary;
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@Nullable
private PsiBuilder.Marker parseBinary(final PsiBuilder builder, final ExprType type, final TokenSet ops) {
  PsiBuilder.Marker result = parseExpression(builder, type);
  if (result == null) return null;
  int operandCount = 1;

  IElementType tokenType = getGtTokenType(builder);
  IElementType currentExprTokenType = tokenType;
  while (true) {
    if (tokenType == null || !ops.contains(tokenType)) break;

    advanceGtToken(builder, tokenType);

    final PsiBuilder.Marker right = parseExpression(builder, type);
    operandCount++;
    tokenType = getGtTokenType(builder);
    if (tokenType == null || !ops.contains(tokenType) || tokenType != currentExprTokenType || right == null) {
      // save
      result = result.precede();
      if (right == null) {
        error(builder, JavaErrorMessages.message("expected.expression"));
      }
      result.done(operandCount > 2 ? JavaElementType.POLYADIC_EXPRESSION : JavaElementType.BINARY_EXPRESSION);
      if (right == null) break;
      currentExprTokenType = tokenType;
      operandCount = 1;
    }
  }

  return result;
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@Nullable
private PsiBuilder.Marker parseRelational(final PsiBuilder builder) {
  PsiBuilder.Marker left = parseExpression(builder, ExprType.SHIFT);
  if (left == null) return null;

  IElementType tokenType;
  while ((tokenType = getGtTokenType(builder)) != null) {
    final IElementType toCreate;
    final ExprType toParse;
    if (RELATIONAL_OPS.contains(tokenType)) {
      toCreate = JavaElementType.BINARY_EXPRESSION;
      toParse = ExprType.SHIFT;
    }
    else if (tokenType == JavaTokenType.INSTANCEOF_KEYWORD) {
      toCreate = JavaElementType.INSTANCE_OF_EXPRESSION;
      toParse = ExprType.TYPE;
    }
    else {
      break;
    }

    final PsiBuilder.Marker expression = left.precede();
    advanceGtToken(builder, tokenType);

    final PsiBuilder.Marker right = parseExpression(builder, toParse);
    if (right == null) {
      error(builder, toParse == ExprType.TYPE ?
                     JavaErrorMessages.message("expected.type") : JavaErrorMessages.message("expected.expression"));
      expression.done(toCreate);
      return expression;
    }

    expression.done(toCreate);
    left = expression;
  }

  return left;
}
项目:intellij-ce-playground    文件:CodeBlockBlock.java   
private SyntheticCodeBlock createCaseSectionBlock(final ArrayList<Block> localResult, final Alignment childAlignment, final Indent indent,
                                                  final Wrap childWrap) {
  final SyntheticCodeBlock result = new SyntheticCodeBlock(localResult, childAlignment, getSettings(), myJavaSettings, indent, childWrap) {
    @Override
    @NotNull
    public ChildAttributes getChildAttributes(final int newChildIndex) {
      IElementType prevElementType = null;
      if (newChildIndex > 0) {
        final Block previousBlock = getSubBlocks().get(newChildIndex - 1);
        if (previousBlock instanceof AbstractBlock) {
          prevElementType = ((AbstractBlock)previousBlock).getNode().getElementType();
        }
      }

      if (prevElementType == JavaElementType.BLOCK_STATEMENT
          || prevElementType == JavaElementType.BREAK_STATEMENT
          || prevElementType == JavaElementType.RETURN_STATEMENT) {
        return new ChildAttributes(Indent.getNoneIndent(), null);
      }
      else {
        return super.getChildAttributes(newChildIndex);
      }
    }

  };
  result.setChildAttributes(new ChildAttributes(Indent.getNormalIndent(), null));
  result.setIsIncomplete(true);
  return result;
}
项目:intellij-ce-playground    文件:ExpressionParser.java   
@NotNull
private PsiBuilder.Marker parseMethodReference(final PsiBuilder builder, final PsiBuilder.Marker start) {
  builder.advanceLexer();

  myParser.getReferenceParser().parseReferenceParameterList(builder, false, false);

  if (!expect(builder, JavaTokenType.IDENTIFIER) && !expect(builder, JavaTokenType.NEW_KEYWORD)) {
    error(builder, JavaErrorMessages.message("expected.identifier"));
  }

  start.done(JavaElementType.METHOD_REF_EXPRESSION);
  return start;
}
项目:intellij-ce-playground    文件:ImportStaticStatementElement.java   
@Override
public int getChildRole(ASTNode child) {
  final int role = super.getChildRole(child);
  if (role != ChildRoleBase.NONE) return role;
  if (child.getElementType() == JavaElementType.IMPORT_STATIC_REFERENCE) {
    return ChildRole.IMPORT_REFERENCE;
  }
  else {
    return ChildRoleBase.NONE;
  }
}
项目:intellij-ce-playground    文件:ReferenceParser.java   
private void completeWildcardType(PsiBuilder builder, boolean wildcard, PsiBuilder.Marker type) {
  if (expect(builder, WILDCARD_KEYWORD_SET)) {
    if (parseTypeInfo(builder, EAT_LAST_DOT) == null) {
      error(builder, JavaErrorMessages.message("expected.type"));
    }
  }

  if (wildcard) {
    type.done(JavaElementType.TYPE);
  }
  else {
    type.error(JavaErrorMessages.message("wildcard.not.expected"));
  }
}
项目:intellij-ce-playground    文件:ReferenceParser.java   
public boolean parseReferenceParameterList(final PsiBuilder builder, final boolean wildcard, final boolean diamonds) {
  final PsiBuilder.Marker list = builder.mark();
  if (!expect(builder, JavaTokenType.LT)) {
    list.done(JavaElementType.REFERENCE_PARAMETER_LIST);
    return false;
  }

  int flags = set(set(EAT_LAST_DOT, WILDCARD, wildcard), DIAMONDS, diamonds);
  boolean isOk = true;
  while (true) {
    if (parseTypeInfo(builder, flags, true) == null) {
      error(builder, JavaErrorMessages.message("expected.identifier"));
    }
    else {
      IElementType tokenType = builder.getTokenType();
      if (WILDCARD_KEYWORD_SET.contains(tokenType)) {
        parseReferenceList(builder, tokenType, null, JavaTokenType.AND);
      }
    }

    if (expect(builder, JavaTokenType.GT)) {
      break;
    }
    else if (!expectOrError(builder, JavaTokenType.COMMA, "expected.gt.or.comma")) {
      isOk = false;
      break;
    }
    flags = set(flags, DIAMONDS, false);
  }

  list.done(JavaElementType.REFERENCE_PARAMETER_LIST);
  return isOk;
}
项目:intellij-ce-playground    文件:ReferenceParser.java   
@NotNull
public PsiBuilder.Marker parseTypeParameters(final PsiBuilder builder) {
  final PsiBuilder.Marker list = builder.mark();
  if (!expect(builder, JavaTokenType.LT)) {
    list.done(JavaElementType.TYPE_PARAMETER_LIST);
    return list;
  }

  while (true) {
    final PsiBuilder.Marker param = parseTypeParameter(builder);
    if (param == null) {
      error(builder, JavaErrorMessages.message("expected.type.parameter"));
    }
    if (!expect(builder, JavaTokenType.COMMA)) {
      break;
    }
  }

  if (!expect(builder, JavaTokenType.GT)) {
    // hack for completion
    if (builder.getTokenType() == JavaTokenType.IDENTIFIER) {
      if (builder.lookAhead(1) == JavaTokenType.GT) {
        final PsiBuilder.Marker errorElement = builder.mark();
        builder.advanceLexer();
        errorElement.error(JavaErrorMessages.message("unexpected.identifier"));
        builder.advanceLexer();
      }
      else {
        error(builder, JavaErrorMessages.message("expected.gt"));
      }
    }
    else {
      error(builder, JavaErrorMessages.message("expected.gt"));
    }
  }

  list.done(JavaElementType.TYPE_PARAMETER_LIST);
  return list;
}
项目:intellij-ce-playground    文件:DeclarationParser.java   
@Nullable
public PsiBuilder.Marker parseEnumConstant(final PsiBuilder builder) {
  final PsiBuilder.Marker constant = builder.mark();

  parseModifierList(builder);

  if (expect(builder, JavaTokenType.IDENTIFIER)) {
    if (builder.getTokenType() == JavaTokenType.LPARENTH) {
      myParser.getExpressionParser().parseArgumentList(builder);
    }
    else {
      emptyElement(builder, JavaElementType.EXPRESSION_LIST);
    }

    if (builder.getTokenType() == JavaTokenType.LBRACE) {
      final PsiBuilder.Marker constantInit = builder.mark();
      parseClassBodyWithBraces(builder, false, false);
      done(constantInit, JavaElementType.ENUM_CONSTANT_INITIALIZER);
    }

    done(constant, JavaElementType.ENUM_CONSTANT);
    return constant;
  }
  else {
    constant.rollbackTo();
    return null;
  }
}