Java 类com.sun.tools.javac.tree.JCTree.JCExpressionStatement 实例源码

项目:lombok-ianchiu    文件:PrettyPrinter.java   
private boolean suppress(JCTree tree) {
    if (tree instanceof JCBlock) {
        JCBlock block = (JCBlock) tree;
        return (Position.NOPOS == block.pos) && block.stats.isEmpty();
    }

    if (tree instanceof JCExpressionStatement) {
        JCExpression expr = ((JCExpressionStatement)tree).expr;
        if (expr instanceof JCMethodInvocation) {
            JCMethodInvocation inv = (JCMethodInvocation) expr;
            if (!inv.typeargs.isEmpty() || !inv.args.isEmpty()) return false;
            if (!(inv.meth instanceof JCIdent)) return false;
            return ((JCIdent) inv.meth).name.toString().equals("super");
        }
    }

    return false;
}
项目:lombok-ianchiu    文件:JavacHandlerUtil.java   
public static boolean isConstructorCall(final JCStatement statement) {
    if (!(statement instanceof JCExpressionStatement)) return false;
    JCExpression expr = ((JCExpressionStatement) statement).expr;
    if (!(expr instanceof JCMethodInvocation)) return false;
    JCExpression invocation = ((JCMethodInvocation) expr).meth;
    String name;
    if (invocation instanceof JCFieldAccess) {
        name = ((JCFieldAccess) invocation).name.toString();
    } else if (invocation instanceof JCIdent) {
        name = ((JCIdent) invocation).name.toString();
    } else {
        name = "";
    }

    return "super".equals(name) || "this".equals(name);
}
项目:EasyMPermission    文件:JavacHandlerUtil.java   
public static boolean isConstructorCall(final JCStatement statement) {
    if (!(statement instanceof JCExpressionStatement)) return false;
    JCExpression expr = ((JCExpressionStatement) statement).expr;
    if (!(expr instanceof JCMethodInvocation)) return false;
    JCExpression invocation = ((JCMethodInvocation) expr).meth;
    String name;
    if (invocation instanceof JCFieldAccess) {
        name = ((JCFieldAccess) invocation).name.toString();
    } else if (invocation instanceof JCIdent) {
        name = ((JCIdent) invocation).name.toString();
    } else {
        name = "";
    }

    return "super".equals(name) || "this".equals(name);
}
项目:jmlok    文件:Examinator.java   
/**
 * Verify if all variables were initialized on the constructor.
 * @param block The lines of the constructor.
 * @return true if all variables were initialized on the constructor.
 */
private boolean isAllVariableInitialized(JCBlock block) {
    for (com.sun.tools.javac.util.List<JCStatement> traversing = block.stats; !traversing.isEmpty(); traversing = traversing.tail){
        if(traversing.head instanceof JCExpressionStatement){
            if(((JCExpressionStatement) traversing.head).expr instanceof JCAssign 
            && !((JCAssign) ((JCExpressionStatement) traversing.head).expr).rhs.toString().equals("null")){
                String toTest = ((JCAssign) ((JCExpressionStatement) traversing.head).expr).lhs.toString();     
                int i = 0; boolean isNecessaryToRemove = false;
                for(i = 0; i < this.variables.size(); i++){
                    if(toTest.equals(this.variables.get(i)) || toTest.equals("this." + this.variables.get(i))){
                        isNecessaryToRemove = true;
                        break;
                    }
                }
                if(isNecessaryToRemove)
                    this.variables.remove(i);
            }
        }
    }
    return this.variables.isEmpty();
}
项目:error-prone    文件:ULambda.java   
JCTree inlineBody(Inliner inliner) throws CouldNotResolveImportException {
  if (getBody() instanceof UPlaceholderExpression) {
    UPlaceholderExpression body = (UPlaceholderExpression) getBody();
    Optional<List<JCStatement>> blockBinding =
        inliner.getOptionalBinding(body.placeholder().blockKey());
    if (blockBinding.isPresent()) {
      // this lambda is of the form args -> blockPlaceholder();
      List<JCStatement> blockInlined =
          UPlaceholderExpression.copier(body.arguments(), inliner)
              .copy(blockBinding.get(), inliner);
      if (blockInlined.size() == 1) {
        if (blockInlined.get(0) instanceof JCReturn) {
          return ((JCReturn) blockInlined.get(0)).getExpression();
        } else if (blockInlined.get(0) instanceof JCExpressionStatement) {
          return ((JCExpressionStatement) blockInlined.get(0)).getExpression();
        }
      }
      return inliner.maker().Block(0, blockInlined);
    }
  }
  return getBody().inline(inliner);
}
项目:bazel    文件:TreePruner.java   
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");
}
项目:incubator-netbeans    文件:CasualDiff.java   
protected int diffExec(JCExpressionStatement oldT, JCExpressionStatement newT, int[] bounds) {
    int localPointer = bounds[0];
    // expr
    int[] exprBounds = getBounds(oldT.expr);
    copyTo(localPointer, exprBounds[0]);
    localPointer = diffTree(oldT.expr, newT.expr, exprBounds);

    copyTo(localPointer, bounds[1]);

    return bounds[1];
}
项目:java-code-templates    文件:AstSubstitutionProcessor.java   
@Override
public void visitExec(final JCExpressionStatement node) {
    if (substitutionInventory.referencesSubstitutableField(node)) {
        // Visit once per descriptor replacement.
        replacements.forEach(field -> {
            substitutionStack.push(field);
            super.visitExec(node);
            substitutionStack.pop();
            print("\n");
        });
    } else {
        super.visitExec(node);
    }
}
项目:lombok-ianchiu    文件:HandleEqualsAndHashCode.java   
public JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) {
    /* result = result * PRIME + expr; */
    JavacTreeMaker maker = typeNode.getTreeMaker();
    Name resultName = typeNode.toName(RESULT_NAME);
    JCExpression mult = maker.Binary(CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
    JCExpression add = maker.Binary(CTC_PLUS, mult, expr);
    return maker.Exec(maker.Assign(maker.Ident(resultName), add));
}
项目:lombok-ianchiu    文件:HandleCleanup.java   
public void doAssignmentCheck0(JavacNode node, JCTree statement, Name name) {
    if (statement instanceof JCAssign) doAssignmentCheck0(node, ((JCAssign)statement).rhs, name);
    if (statement instanceof JCExpressionStatement) doAssignmentCheck0(node,
            ((JCExpressionStatement)statement).expr, name);
    if (statement instanceof JCVariableDecl) doAssignmentCheck0(node, ((JCVariableDecl)statement).init, name);
    if (statement instanceof JCTypeCast) doAssignmentCheck0(node, ((JCTypeCast)statement).expr, name);
    if (statement instanceof JCIdent) {
        if (((JCIdent)statement).name.contentEquals(name)) {
            JavacNode problemNode = node.getNodeFor(statement);
            if (problemNode != null) problemNode.addWarning(
            "You're assigning an auto-cleanup variable to something else. This is a bad idea.");
        }
    }
}
项目:javaparser2jctree    文件:PrintAstVisitor.java   
public void visitExec(JCExpressionStatement that) {
    try {
        print("JCExpressionStatement:");
    } catch (Exception e) {
    }
    super.visitExec(that);
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
private boolean isSuppressed(JCTree tree) {
    if (isEmptyStat(tree)) {
        return true;
    }
    if (tree instanceof JCExpressionStatement) {
        return isNoArgsSuperCall(((JCExpressionStatement)tree).expr);
    }
    return false;
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitExec(JCExpressionStatement tree) {
    if (isNoArgsSuperCall(tree.expr)) return;
    try {
        printExpr(tree.expr);
        if (prec == TreeInfo.notExpression) print(";");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:EasyMPermission    文件:HandleEqualsAndHashCode.java   
public JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) {
    /* result = result * PRIME + (expr); */
    JavacTreeMaker maker = typeNode.getTreeMaker();
    Name resultName = typeNode.toName(RESULT_NAME);
    JCExpression mult = maker.Binary(CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
    JCExpression add = maker.Binary(CTC_PLUS, mult, expr);
    return maker.Exec(maker.Assign(maker.Ident(resultName), add));
}
项目:EasyMPermission    文件:HandleCleanup.java   
public void doAssignmentCheck0(JavacNode node, JCTree statement, Name name) {
    if (statement instanceof JCAssign) doAssignmentCheck0(node, ((JCAssign)statement).rhs, name);
    if (statement instanceof JCExpressionStatement) doAssignmentCheck0(node,
            ((JCExpressionStatement)statement).expr, name);
    if (statement instanceof JCVariableDecl) doAssignmentCheck0(node, ((JCVariableDecl)statement).init, name);
    if (statement instanceof JCTypeCast) doAssignmentCheck0(node, ((JCTypeCast)statement).expr, name);
    if (statement instanceof JCIdent) {
        if (((JCIdent)statement).name.contentEquals(name)) {
            JavacNode problemNode = node.getNodeFor(statement);
            if (problemNode != null) problemNode.addWarning(
            "You're assigning an auto-cleanup variable to something else. This is a bad idea.");
        }
    }
}
项目:callsuper-annotation    文件:CallSuperProcessor.java   
private boolean doesCallSuper (List list, String methodName) {
    for (Object object : list) {
        if (object instanceof JCTree.JCExpressionStatement) {
            JCTree.JCExpressionStatement expr = (JCExpressionStatement) object;
            String exprString = expr.toString();
            if (exprString.startsWith("super." + methodName) && exprString.endsWith(");")) return true;
        }
    }

    return false;
}
项目:refactor-faster    文件:UForLoop.java   
@Override
public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().ForLoop(
      inliner.inlineList(getInitializer()),
      (getCondition() == null) ? null : getCondition().inline(inliner), 
      com.sun.tools.javac.util.List.convert(
          JCExpressionStatement.class, inliner.inlineList(getUpdate())), 
      getStatement().inline(inliner));
}
项目:android-retrolambda-lombok    文件:JcTreeBuilder.java   
@Override
public boolean visitAlternateConstructorInvocation(AlternateConstructorInvocation node) {
    int thisStart, thisEnd;

    Position jcThisPos = getConversionPositionInfo(node, "this");
    thisStart = jcThisPos == null ? (!node.astConstructorTypeArguments().isEmpty() ? posOfStructure(node, "<", true) : posOfStructure(node, "this", true)) : jcThisPos.getStart();
    thisEnd = jcThisPos == null ? posOfStructure(node, "this", false) : jcThisPos.getEnd();

    JCMethodInvocation invoke = treeMaker.Apply(
            toList(JCExpression.class, node.astConstructorTypeArguments()), 
            setPos(thisStart, thisEnd,
                    treeMaker.Ident(table._this)),
            toList(JCExpression.class, node.astArguments()));
    int start, end;
    if (hasSourceStructures()) {
        start = posOfStructure(node, "(", true);
        end = posOfStructure(node, ")", false);
    } else {
        start = node.getPosition().getStart();
        end = node.getPosition().getEnd();
    }

    JCExpressionStatement exec = treeMaker.Exec(setPos(start, end, invoke));
    Position jcExecPos = getConversionPositionInfo(node, "exec");
    if (jcExecPos != null) {
        setPos(jcExecPos.getStart(), jcExecPos.getEnd(), exec);
    } else {
        setPos(node, exec);
    }

    return set(node, exec);
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
@Override public void visitExec(JCExpressionStatement node) {
    Node expr = toTree(node.getExpression());
    if (expr instanceof SuperConstructorInvocation || expr instanceof AlternateConstructorInvocation) {
        setConversionPositionInfo(expr, "exec", getPosition(node));
        set(node, expr);
        return;
    }
    ExpressionStatement exec = new ExpressionStatement();
    exec.rawExpression(expr);
    set(node, exec);
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
@Override public void visitForLoop(JCForLoop node) {
    For f = new For();
    f.rawCondition(toTree(node.getCondition()));
    f.rawStatement(toTree(node.getStatement()));
    for (JCExpressionStatement upd : node.getUpdate()) {
        Node updateNode = toTree(upd.getExpression());
        setConversionPositionInfo(updateNode, "exec", getPosition(upd));
        f.rawUpdates().addToEnd(updateNode);
    }
    List<JCStatement> initializers = node.getInitializer();
    // Multiple vardefs in a row need to trigger the JCVD version AND be washed through fillList to be turned into 1 VD.
    if (!initializers.isEmpty() && initializers.get(0) instanceof JCVariableDecl) {
        Block tmp = new Block();
        fillList(initializers, tmp.rawContents(), FlagKey.VARDEF_IS_DEFINITION);
        Node varDecl = tmp.rawContents().first();
        if (varDecl != null) varDecl.unparent();
        f.rawVariableDeclaration(varDecl);
    } else {
        for (JCStatement init : initializers) {
            if (init instanceof JCExpressionStatement) {
                Node initNode = toTree(((JCExpressionStatement) init).getExpression());
                setConversionPositionInfo(initNode, "exec", getPosition(init));
                f.rawExpressionInits().addToEnd(initNode);
            } else {
                f.rawExpressionInits().addToEnd(toTree(init));
            }
        }
    }
    set(node, f);
}
项目:jmlok    文件:Examinator.java   
/**
 * Verify if some variable from class or parameter from the method are receiving a value
 * in an attribution.
 * @param params The parameters from the method.
 * @param block The code lines from the method.
 * @return true If the method attribute value to some field.
 */
private boolean isSomeVarOtAtrGettingAttribution(com.sun.tools.javac.util.List<JCVariableDecl> params, JCBlock block) {
    for (com.sun.tools.javac.util.List<JCStatement> traversing = block.stats; !traversing.isEmpty(); traversing = traversing.tail){

        if(traversing.head instanceof JCExpressionStatement){
            if(verifyAttribution(params, ((JCExpressionStatement) traversing.head).expr))
                return true;
            else if(((JCExpressionStatement) traversing.head).expr instanceof JCMethodInvocation)
                return true;
        }
    }
    return false;
}
项目:error-prone    文件:PlaceholderUnificationVisitor.java   
@Override
public Choice<State<JCForLoop>> visitForLoop(final ForLoopTree node, State<?> state) {
  return chooseSubtrees(
      state,
      s -> unifyStatements(node.getInitializer(), s),
      s -> unifyExpression(node.getCondition(), s),
      s -> unifyStatements(node.getUpdate(), s),
      s -> unifyStatement(node.getStatement(), s),
      (inits, cond, update, stmt) ->
          maker().ForLoop(inits, cond, List.convert(JCExpressionStatement.class, update), stmt));
}
项目:error-prone    文件:UForLoop.java   
@Override
public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner
      .maker()
      .ForLoop(
          UBlock.inlineStatementList(getInitializer(), inliner),
          (getCondition() == null) ? null : getCondition().inline(inliner),
          com.sun.tools.javac.util.List.convert(
              JCExpressionStatement.class, inliner.<JCStatement>inlineList(getUpdate())),
          getStatement().inline(inliner));
}
项目:s4j    文件:JavacParser.java   
/** MoreStatementExpressions = { COMMA StatementExpression }
 */
<T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos,
                                                                JCExpression first,
                                                                T stats) {
    // This Exec is a "StatementExpression"; it subsumes no terminating token
    stats.append(toP(F.at(pos).Exec(checkExprStat(first))));
    while (S.token() == COMMA) {
        S.nextToken();
        pos = S.pos();
        JCExpression t = parseExpression();
        // This Exec is a "StatementExpression"; it subsumes no terminating token
        stats.append(toP(F.at(pos).Exec(checkExprStat(t))));
    }
    return stats;
}
项目:s4j    文件:Pretty.java   
public void visitExec(JCExpressionStatement tree) {
    try {
        printExpr(tree.expr);
        if (prec == TreeInfo.notExpression) print(";");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:s4j    文件:Attr.java   
public void visitExec(JCExpressionStatement tree) {
    //a fresh environment is required for 292 inference to work properly ---
    //see Infer.instantiatePolymorphicSignatureInstance()
    Env<AttrContext> localEnv = env.dup(tree);

    // de.so.ma
    // check for JCSqlQuery 
    SqlQueryNodeTransformer transformer = SqlQueryNodeTransformer.getInstance(); 
    tree.expr = transformer.transformPotentialSqlQuery(
            tree.expr, localEnv, null, this, enter, memberEnter);

    attribExpr(tree.expr, localEnv);
    result = null;
}
项目:s4j    文件:Attr.java   
/** Check that given application node appears as first statement
 *  in a constructor call.
 *  @param tree   The application node
 *  @param env    The environment current at the application.
 */
boolean checkFirstConstructorStat(JCMethodInvocation tree, Env<AttrContext> env) {
    JCMethodDecl enclMethod = env.enclMethod;
    if (enclMethod != null && enclMethod.name == names.init) {
        JCBlock body = enclMethod.body;
        if (body.stats.head.getTag() == JCTree.EXEC &&
            ((JCExpressionStatement) body.stats.head).expr == tree)
            return true;
    }
    log.error(tree.pos(),"call.must.be.first.stmt.in.ctor",
              TreeInfo.name(tree.meth));
    return false;
}
项目:Refaster    文件:UForLoop.java   
@Override
public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().ForLoop(
      inliner.inlineList(getInitializer()),
      (getCondition() == null) ? null : getCondition().inline(inliner), 
      com.sun.tools.javac.util.List.convert(
          JCExpressionStatement.class, inliner.inlineList(getUpdate())), 
      getStatement().inline(inliner));
}
项目:lombok    文件:PrettyCommentsPrinter.java   
public void visitExec(JCExpressionStatement tree) {
    if (isNoArgsSuperCall(tree.expr)) return;
    try {
        printExpr(tree.expr);
        if (prec == TreeInfo.notExpression) print(";");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok    文件:HandleSneakyThrows.java   
private boolean isConstructorCall(final JCStatement supect) {
    if (!(supect instanceof JCExpressionStatement)) return false;
    final JCExpression supectExpression = ((JCExpressionStatement) supect).expr;
    if (!(supectExpression instanceof JCMethodInvocation)) return false;
    final String methodName = ((JCMethodInvocation) supectExpression).meth.toString();
    return "super".equals(methodName) || "this".equals(methodName);
}
项目:lombok    文件:HandleEqualsAndHashCode.java   
private JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) {
    /* result = result * PRIME + (expr); */
    TreeMaker maker = typeNode.getTreeMaker();
    Name resultName = typeNode.toName(RESULT_NAME);
    JCExpression mult = maker.Binary(CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
    JCExpression add = maker.Binary(CTC_PLUS, mult, expr);
    return maker.Exec(maker.Assign(maker.Ident(resultName), add));
}
项目:lombok    文件:HandleCleanup.java   
private void doAssignmentCheck0(JavacNode node, JCTree statement, Name name) {
    if (statement instanceof JCAssign) doAssignmentCheck0(node, ((JCAssign)statement).rhs, name);
    if (statement instanceof JCExpressionStatement) doAssignmentCheck0(node,
            ((JCExpressionStatement)statement).expr, name);
    if (statement instanceof JCVariableDecl) doAssignmentCheck0(node, ((JCVariableDecl)statement).init, name);
    if (statement instanceof JCTypeCast) doAssignmentCheck0(node, ((JCTypeCast)statement).expr, name);
    if (statement instanceof JCIdent) {
        if (((JCIdent)statement).name.contentEquals(name)) {
            JavacNode problemNode = node.getNodeFor(statement);
            if (problemNode != null) problemNode.addWarning(
            "You're assigning an auto-cleanup variable to something else. This is a bad idea.");
        }
    }
}
项目:yield4j    文件:JavacCodeGenerator.java   
@Override
public void visit(ForWrapper w) {
    result = builder.getTreeMaker().ForLoop(
            generate(w.getInitStatements(), JCStatement.class),
            generate(w.getCondition()),
            generate(w.getUpdateStatements(),
                    JCExpressionStatement.class),
            generate(w.getStatement()));
}
项目:lombok-ianchiu    文件:JavacTreeMaker.java   
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) {
    return invoke(ForLoop, init, cond, step, body);
}
项目:lombok-ianchiu    文件:JavacTreeMaker.java   
public JCExpressionStatement Exec(JCExpression expr) {
    return invoke(Exec, expr);
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
@Override public void visitExec(JCExpressionStatement tree) {
    align();
    print(tree.expr);
    println(";", tree);
}
项目:javaparser2jctree    文件:AJCExpressionStatement.java   
public AJCExpressionStatement(JCExpressionStatement ltree) {
    super(ltree.expr);
}
项目:javaparser2jctree    文件:AJCExpressionStatement.java   
public AJCExpressionStatement(JCExpressionStatement ltree, String lcomment) {
    this(ltree);
    setComment(lcomment);
}
项目:EasyMPermission    文件:JavacTreeMaker.java   
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) {
    return invoke(ForLoop, init, cond, step, body);
}
项目:EasyMPermission    文件:JavacTreeMaker.java   
public JCExpressionStatement Exec(JCExpression expr) {
    return invoke(Exec, expr);
}