Java Code Examples for com.sun.tools.javac.tree.JCTree.JCStatement#getKind()

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCStatement#getKind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreePruner.java    From bazel with Apache License 2.0 6 votes vote down vote up
private static boolean delegatingConstructor(List<JCStatement> stats) {
  if (stats.isEmpty()) {
    return false;
  }
  JCStatement stat = stats.get(0);
  if (stat.getKind() != Kind.EXPRESSION_STATEMENT) {
    return false;
  }
  JCExpression expr = ((JCExpressionStatement) stat).getExpression();
  if (expr.getKind() != Kind.METHOD_INVOCATION) {
    return false;
  }
  JCExpression method = ((JCMethodInvocation) expr).getMethodSelect();
  Name name;
  switch (method.getKind()) {
    case IDENTIFIER:
      name = ((JCIdent) method).getName();
      break;
    case MEMBER_SELECT:
      name = ((JCFieldAccess) method).getIdentifier();
      break;
    default:
      return false;
  }
  return name.contentEquals("this") || name.contentEquals("super");
}
 
Example 2
Source File: PartialReparserService.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JCBlock reparseMethodBody(CompilationUnitTree topLevel, MethodTree methodToReparse, String newBodyText, int annonIndex,
        final Map<? super JCTree,? super LazyDocCommentTable.Entry> docComments) {
    CharBuffer buf = CharBuffer.wrap((newBodyText+"\u0000").toCharArray(), 0, newBodyText.length());
    JavacParser parser = newParser(context, buf, ((JCBlock)methodToReparse.getBody()).pos, ((JCCompilationUnit)topLevel).endPositions);
    final JCStatement statement = parser.parseStatement();
    NBParserFactory.assignAnonymousClassIndices(Names.instance(context), statement, Names.instance(context).empty, annonIndex);
    if (statement.getKind() == Tree.Kind.BLOCK) {
        if (docComments != null) {
            docComments.putAll(((LazyDocCommentTable) parser.getDocComments()).table);
        }
        return (JCBlock) statement;
    }
    return null;
}
 
Example 3
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private Expression convertInitializer(JCStatement statement) {
  switch (statement.getKind()) {
    case EXPRESSION_STATEMENT:
      return convertExpression(((JCExpressionStatement) statement).expr);
    default:
      throw new AssertionError();
  }
}
 
Example 4
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private Statement convertStatement(JCStatement jcStatement) {
  switch (jcStatement.getKind()) {
    case ASSERT:
      return convertAssert((JCAssert) jcStatement);
    case BLOCK:
      return convertBlock((JCBlock) jcStatement);
    case BREAK:
      return convertBreak((JCBreak) jcStatement);
    case CLASS:
      convertClassDeclaration((JCClassDecl) jcStatement);
      return null;
    case CONTINUE:
      return convertContinue((JCContinue) jcStatement);
    case DO_WHILE_LOOP:
      return convertDoWhileLoop((JCDoWhileLoop) jcStatement);
    case EMPTY_STATEMENT:
      return new EmptyStatement(getSourcePosition(jcStatement));
    case ENHANCED_FOR_LOOP:
      return convertEnhancedForLoop((JCEnhancedForLoop) jcStatement);
    case EXPRESSION_STATEMENT:
      return convertExpressionStatement((JCExpressionStatement) jcStatement);
    case FOR_LOOP:
      return convertForLoop((JCForLoop) jcStatement);
    case IF:
      return convertIf((JCIf) jcStatement);
    case LABELED_STATEMENT:
      return convertLabeledStatement((JCLabeledStatement) jcStatement);
    case RETURN:
      return convertReturn((JCReturn) jcStatement);
    case SWITCH:
      return convertSwitch((JCSwitch) jcStatement);
    case THROW:
      return convertThrow((JCThrow) jcStatement);
    case TRY:
      return convertTry((JCTry) jcStatement);
    case VARIABLE:
      return convertVariableDeclaration((JCVariableDecl) jcStatement);
    case WHILE_LOOP:
      return convertWhileLoop((JCWhileLoop) jcStatement);
    case SYNCHRONIZED:
      return convertSynchronized((JCSynchronized) jcStatement);
    default:
      throw new AssertionError("Unknown statement node type: " + jcStatement.getKind());
  }
}