当前位置: 首页>>代码示例>>Java>>正文


Java JCStatement.getKind方法代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCStatement.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java JCStatement.getKind方法的具体用法?Java JCStatement.getKind怎么用?Java JCStatement.getKind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.tree.JCTree.JCStatement的用法示例。


在下文中一共展示了JCStatement.getKind方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: delegatingConstructor

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入方法依赖的package包/类
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");
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:27,代码来源:TreePruner.java

示例2: containsVariable

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入方法依赖的package包/类
private static boolean containsVariable(List<JCStatement> statements) {
    for (JCStatement s : statements) {
        if (s.getKind() == Kind.VARIABLE) {
            return true;
        }
    }

    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:CasualDiff.java

示例3: reparseMethodBody

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:PartialReparserService.java

示例4: extractSingleStatement

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入方法依赖的package包/类
/**
 * @return the only statement in a block containing one statement or the body itself when it is
 *         not a block.
 */
private JCStatement extractSingleStatement(JCStatement body) {
  if (body.getKind() != Kind.BLOCK) {
    return body;
  }
  JCBlock block = (JCBlock) body;
  if (block.getStatements().size() == 1) {
    return block.getStatements().get(0);
  }
  return null;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:15,代码来源:ElementsCountedInLoop.java

示例5: printBreakContinueTree

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入方法依赖的package包/类
/**
 * Rewrites <code>break</code> or <code>continue</code> tree.
 * @param bounds original bounds
 * @param oldTLabel old label
 * @param newTlabel new label
 * @param oldT the tree to be rewritten
 * @return new bounds
 */
private int printBreakContinueTree(int[] bounds, final Name oldTLabel, final Name newTlabel, JCStatement oldT) {
    int localPointer = bounds[0];
    String stmt = oldT.getKind() == Kind.BREAK ? "break" : "continue"; //NOI18N
    // PENDING: inner comments should be handled - inner comment should be printed in between break and its label,
    // or after the break with no label.
    if (nameChanged(oldTLabel, newTlabel)) {
        int labelPos = -1;
        copyTo(localPointer, localPointer = getOldPos(oldT));
        printer.print(stmt);
        localPointer += stmt.length();
        
        int commentStart = -1;
        int commentEnd = -1;
        if (oldTLabel != null && oldTLabel.length() > 0) {
            tokenSequence.move(localPointer);
            while (tokenSequence.moveNext()) {
                Token<JavaTokenId> tukac = tokenSequence.token();
                if (isComment(tukac.id())) {
                    if (commentStart == -1) {
                        commentStart = tokenSequence.offset();
                    }
                    commentEnd = tokenSequence.offset() + tukac.length();
                } else if (tukac.id() != JavaTokenId.WHITESPACE) {
                    break;
                }
            }
            if (commentStart != -1) {
                // replicate whitespace before the comment + all the comments up to the last one:
                localPointer = copyUpTo(localPointer, commentEnd);
            }
            // start of the old label
            labelPos = tokenSequence.offset();
        }
        if (newTlabel != null && newTlabel.length() > 0) {
            if (oldTLabel != null) {
                // replicate the original whitespaces
                localPointer = copyUpTo(localPointer, labelPos);
            } else {
                printer.print(" ");
            }
            printer.print(newTlabel);
        }
        if (oldTLabel != null) {
            localPointer = labelPos + oldTLabel.length();
        }
    }
    copyTo(localPointer, bounds[1]);
    return bounds[1];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:58,代码来源:CasualDiff.java

示例6: getIncrementedIdentifer

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入方法依赖的package包/类
/**
 * @return identifier which is being incremented by constant one. Returns null if no such
 *         identifier is found.
 */
private IdentifierTree getIncrementedIdentifer(JCStatement statement) {
  if (statement == null) {
    return null;
  }
  if (statement.getKind() == Kind.EXPRESSION_STATEMENT) {
    Tree.Kind kind = ((JCExpressionStatement) statement).getExpression().getKind();
    if (kind == Kind.PREFIX_INCREMENT || kind == Kind.POSTFIX_INCREMENT) {
      JCUnary unary = (JCUnary) ((JCExpressionStatement) statement).getExpression();
      if (unary.arg.getKind() == Kind.IDENTIFIER) {
        return (IdentifierTree) unary.arg;
      }
      return null;
    } else if (kind == Kind.PLUS_ASSIGNMENT) {
      JCAssignOp assignOp = (JCAssignOp) ((JCExpressionStatement) statement).getExpression();
      if (assignOp.lhs.getKind() == Kind.IDENTIFIER && (isConstantOne(assignOp.rhs))) {
        return (IdentifierTree) assignOp.lhs;
      }
    } else if (kind == Kind.ASSIGNMENT) {
      JCAssign assign = (JCAssign) ((JCExpressionStatement) statement).getExpression();
      if (assign.lhs.getKind() == Kind.IDENTIFIER && assign.rhs.getKind() == Kind.PLUS) {
        JCBinary binary = (JCBinary) assign.rhs;
        if (binary.lhs.getKind() == Kind.IDENTIFIER) {
          if (((JCIdent) assign.lhs).sym == ((JCIdent) binary.lhs).sym) {
            if (isConstantOne(binary.rhs)) {
              return (IdentifierTree) binary.lhs;
            }
          }
        }
        if (binary.rhs.getKind() == Kind.IDENTIFIER) {
          if (((JCIdent) assign.lhs).sym == ((JCIdent) binary.rhs).sym) {
            if (isConstantOne(binary.lhs)) {
              return (IdentifierTree) binary.rhs;
            }
          }
        }
      }
    }
  }
  return null;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:45,代码来源:ElementsCountedInLoop.java

示例7: describe

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入方法依赖的package包/类
public Description describe(MethodInvocationTree methodInvocationTree, VisitorState state) {
  if (matchState == MatchState.NONE) {
    throw new IllegalStateException("describe() called without a match");
  }

  // If we don't find a good field to use, then just replace with "true"
  Fix fix = new SuggestedFix().replace(methodInvocationTree, "true");

  if (matchState == MatchState.OBJECTS_EQUAL) {
    /**
     * Cases:
     *    1) Objects.equal(foo, foo) ==> Objects.equal(foo, other.foo)
     *    2) Objects.equal(foo, this.foo) ==> Objects.equal(other.foo, this.foo)
     *    3) Objects.equal(this.foo, foo) ==> Objects.equal(this.foo, other.foo)
     *    4) Objects.equal(this.foo, this.foo) ==> Objects.equal(this.foo, other.foo)
     */
    // Assumption: Both arguments are either identifiers or field accesses.
    List<? extends ExpressionTree> args = methodInvocationTree.getArguments();
    for (ExpressionTree arg : args) {
      switch (arg.getKind()) {
        case IDENTIFIER: case MEMBER_SELECT:
          break;
        default:
          throw new IllegalStateException("Expected arg " + arg + " to be a field access or "
              + "identifier");
      }
    }

    // Choose argument to replace.
    ExpressionTree toReplace;
    if (args.get(1).getKind() == Kind.IDENTIFIER) {
      toReplace = args.get(1);
    } else if (args.get(0).getKind() == Kind.IDENTIFIER) {
      toReplace = args.get(0);
    } else {
      // If we don't have a good reason to replace one or the other, replace the second.
      toReplace = args.get(1);
    }
    // Find containing block
    TreePath path = state.getPath();
    while(path.getLeaf().getKind() != Kind.BLOCK) {
      path = path.getParentPath();
    }
    JCBlock block = (JCBlock)path.getLeaf();
    for (JCStatement jcStatement : block.getStatements()) {
      if (jcStatement.getKind() == Kind.VARIABLE) {
        JCVariableDecl declaration = (JCVariableDecl) jcStatement;
        TypeSymbol variableTypeSymbol = declaration.getType().type.tsym;

        if (ASTHelpers.getSymbol(toReplace).isMemberOf(variableTypeSymbol, state.getTypes())) {
          if (toReplace.getKind() == Kind.IDENTIFIER) {
            fix = new SuggestedFix().prefixWith(toReplace,
                declaration.getName().toString() + ".");
          } else {
            fix = new SuggestedFix().replace(((JCFieldAccess) toReplace).getExpression(),
                declaration.getName().toString());
          }
        }
      }
    }
  }

  return describeMatch(methodInvocationTree, fix);
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:65,代码来源:SelfEquals.java


注:本文中的com.sun.tools.javac.tree.JCTree.JCStatement.getKind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。