當前位置: 首頁>>代碼示例>>Java>>正文


Java BinaryExpr類代碼示例

本文整理匯總了Java中org.walkmod.javalang.ast.expr.BinaryExpr的典型用法代碼示例。如果您正苦於以下問題:Java BinaryExpr類的具體用法?Java BinaryExpr怎麽用?Java BinaryExpr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BinaryExpr類屬於org.walkmod.javalang.ast.expr包,在下文中一共展示了BinaryExpr類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRemovesAndUpdatesOnStmts

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
@Test
public void testRemovesAndUpdatesOnStmts() throws Exception {
   String code = "public class Foo{\n\tpublic void foo() {\n\t\tif(a){\n\t\t\tif(b){\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t}\n}";
   DefaultJavaParser parser = new DefaultJavaParser();
   CompilationUnit cu = parser.parse(code, false);
   CompilationUnit cu2 = parser.parse(code, false);
   MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0);
   List<Statement> stmts = md.getBody().getStmts();

   IfStmt ifStmt = (IfStmt) stmts.get(0);
   BlockStmt thenBlock = (BlockStmt) ifStmt.getThenStmt();
   IfStmt thenStmt = (IfStmt) thenBlock.getStmts().get(0);

   Expression condition = thenStmt.getCondition().clone();
   BinaryExpr be = new BinaryExpr(ifStmt.getCondition().clone(), condition, BinaryExpr.Operator.and);
   ifStmt.setCondition(be);
   ifStmt.setThenStmt(thenStmt.getThenStmt().clone());
   thenStmt.remove();

   List<Action> actions = getActions(cu2, cu);
   assertCode(actions, code, "public class Foo{\n\tpublic void foo() {\n\t\tif(a && b){\n\t\t\ti++;\n\t\t}\n\t}\n}");
}
 
開發者ID:walkmod,項目名稱:walkmod-javalang-plugin,代碼行數:23,代碼來源:ChangeLogVisitorTest.java

示例2: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public Boolean visit(BinaryExpr n1, Node arg) {
    BinaryExpr n2 = (BinaryExpr) arg;
    if (n1.getOperator() != n2.getOperator()) {
        return Boolean.FALSE;
    }
    if (!nodeEquals(n1.getLeft(), n2.getLeft())) {
        return Boolean.FALSE;
    }
    if (!nodeEquals(n1.getRight(), n2.getRight())) {
        return Boolean.FALSE;
    }
    return Boolean.TRUE;
}
 
開發者ID:rpau,項目名稱:javalang,代碼行數:14,代碼來源:EqualsVisitor.java

示例3: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
@Override
public Node visit(BinaryExpr _n, Object _arg) {
    Expression left = cloneNodes(_n.getLeft(), _arg);
    Expression right = cloneNodes(_n.getRight(), _arg);
    BinaryExpr r = new BinaryExpr(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), left,
            right, _n.getOperator());
    return r;
}
 
開發者ID:rpau,項目名稱:javalang,代碼行數:9,代碼來源:CloneVisitor.java

示例4: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public void visit(BinaryExpr n, VisitorContext arg) {
    if (preVisitor != null) {
        preVisitor.visit(n, arg);
    }
    super.visit(n, arg);
    if (postVisitor != null) {
        postVisitor.visit(n, arg);
    }
}
 
開發者ID:rpau,項目名稱:javalang,代碼行數:10,代碼來源:CompositeVisitor.java

示例5: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public void visit(BinaryExpr n, VisitorContext ctx) {
    Object o = ctx.get(NODE_TO_COMPARE_KEY);
    if (o != null && o instanceof BinaryExpr) {
        BinaryExpr aux = (BinaryExpr) o;
        boolean backup = isUpdated();
        setIsUpdated(false);
        boolean equals = n.getOperator().name().equals(aux.getOperator().name());

        inferASTChanges(n.getRight(), aux.getRight());
        inferASTChanges(n.getLeft(), aux.getLeft());
        if (!equals) {
            applyUpdate(n, (Node) o);
        }
        if (!isUpdated()) {
            if (equals) {
                increaseUnmodifiedNodes(BinaryExpr.class);
            } else {
                increaseUpdatedNodes(BinaryExpr.class);
            }
        } else {
            applyUpdate(n, (Node) o);
            increaseUpdatedNodes(BinaryExpr.class);
        }
        setIsUpdated(backup || isUpdated());
    } else if (o != null) {
        setIsUpdated(true);
        applyUpdate(n, (Node) o);
    }
}
 
開發者ID:walkmod,項目名稱:walkmod-javalang-plugin,代碼行數:30,代碼來源:ChangeLogVisitor.java

示例6: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
@Override
public void visit(BinaryExpr n, A arg) {

    n.getLeft().accept(this, arg);
    SymbolType leftType = (SymbolType) n.getLeft().getSymbolData();

    n.getRight().accept(this, arg);
    SymbolType rightType = (SymbolType) n.getRight().getSymbolData();

    SymbolType resultType = leftType;

    Class<?> leftClazz = null;
    if (leftType != null) {
        leftClazz = leftType.getClazz();
    }
    Class<?> rightClazz = null;
    if (rightType != null) {
        rightClazz = rightType.getClazz();
    }

    if (Types.isCompatible(leftClazz, rightClazz)) {
        resultType = rightType;
    }

    Operator op = n.getOperator();
    if (op.equals(Operator.plus)) {

        if (leftType.getName().equals("java.lang.String")) {
            resultType = leftType;
        } else if (rightType.getName().equals("java.lang.String")) {
            resultType = rightType;
        }
    }

    if (op.equals(Operator.equals) || op.equals(Operator.notEquals) || op.equals(Operator.greater)
            || op.equals(Operator.greaterEquals) || op.equals(Operator.less) || op.equals(Operator.lessEquals)) {
        resultType = new SymbolType(boolean.class);
    }

    n.setSymbolData(resultType);

}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:43,代碼來源:TypeVisitorAdapter.java

示例7: BinaryExprAssert

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public BinaryExprAssert(BinaryExpr actual) {
    super(actual, BinaryExprAssert.class);
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:4,代碼來源:BinaryExprAssert.java

示例8: hasOperator

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public BinaryExprAssert hasOperator(BinaryExpr.Operator op) {
    Assertions.assertThat(actual.getOperator()).as(navigationDescription("operator")).isEqualByComparingTo(op);
    return this;
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:5,代碼來源:BinaryExprAssert.java

示例9: assertThat

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public static BinaryExprAssert assertThat(BinaryExpr actual) {
    return new BinaryExprAssert(actual);
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:4,代碼來源:AstAssertions.java

示例10: asBinaryExpr

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public BinaryExprAssert asBinaryExpr() {
    return AstAssertions.assertThat(asInstanceOf(BinaryExpr.class))
            .as(navigationDescription("(BinaryExpr)"));
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:5,代碼來源:AbstractExpressionAssert.java

示例11: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public R visit(BinaryExpr n, A arg) {
    n.getLeft().accept(this, arg);
    n.getRight().accept(this, arg);
    return null;
}
 
開發者ID:rpau,項目名稱:javalang,代碼行數:6,代碼來源:GenericVisitorAdapter.java

示例12: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public void visit(BinaryExpr n, Object arg) {
    prepareComments(n);
    n.getLeft().accept(this, arg);
    printer.print(" ");

    Node lastNode = n.getLeft();
    List<Node> comments = printInnerComments(n.getLeft(), n.getRight(), arg);
    if (comments != null && !comments.isEmpty()) {
        Node comment = comments.get(comments.size() - 1);
        if (!comment.isNewNode()) {
            lastNode = comment;
        }
    }
    if (!lastNode.isNewNode() && !n.getRight().isNewNode()) {
        addEntersBetween(lastNode, n.getRight());
    }
    switch (n.getOperator()) {
        case or:
            printer.print("||");
            break;
        case and:
            printer.print("&&");
            break;
        case binOr:
            printer.print("|");
            break;
        case binAnd:
            printer.print("&");
            break;
        case xor:
            printer.print("^");
            break;
        case equals:
            printer.print("==");
            break;
        case notEquals:
            printer.print("!=");
            break;
        case less:
            printer.print("<");
            break;
        case greater:
            printer.print(">");
            break;
        case lessEquals:
            printer.print("<=");
            break;
        case greaterEquals:
            printer.print(">=");
            break;
        case lShift:
            printer.print("<<");
            break;
        case rSignedShift:
            printer.print(">>");
            break;
        case rUnsignedShift:
            printer.print(">>>");
            break;
        case plus:
            printer.print("+");
            break;
        case minus:
            printer.print("-");
            break;
        case times:
            printer.print("*");
            break;
        case divide:
            printer.print("/");
            break;
        case remainder:
            printer.print("%");
            break;
    }
    printer.print(" ");
    n.getRight().accept(this, arg);
}
 
開發者ID:rpau,項目名稱:javalang,代碼行數:79,代碼來源:DumpVisitor.java

示例13: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public void visit(BinaryExpr n, A arg) {
    n.getLeft().accept(this, arg);
    n.getRight().accept(this, arg);
}
 
開發者ID:rpau,項目名稱:javalang,代碼行數:5,代碼來源:VoidVisitorAdapter.java

示例14: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public Node visit(BinaryExpr n, A arg) {
    n.setLeft((Expression) n.getLeft().accept(this, arg));
    n.setRight((Expression) n.getRight().accept(this, arg));
    return n;
}
 
開發者ID:rpau,項目名稱:javalang,代碼行數:6,代碼來源:ModifierVisitorAdapter.java

示例15: visit

import org.walkmod.javalang.ast.expr.BinaryExpr; //導入依賴的package包/類
public R visit(BinaryExpr n, A arg); 
開發者ID:rpau,項目名稱:javalang,代碼行數:2,代碼來源:GenericVisitor.java


注:本文中的org.walkmod.javalang.ast.expr.BinaryExpr類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。