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


Java BinaryExpression类代码示例

本文整理汇总了Java中org.codehaus.groovy.ast.expr.BinaryExpression的典型用法代码示例。如果您正苦于以下问题:Java BinaryExpression类的具体用法?Java BinaryExpression怎么用?Java BinaryExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BinaryExpression类属于org.codehaus.groovy.ast.expr包,在下文中一共展示了BinaryExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseLine

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
List<T> parseLine(BinaryExpression exp, Class<T> cls) {

        List<T> constantExpressions = new LinkedList<>();

        Expression leftExpression = exp.getLeftExpression();

        if (leftExpression.getClass().equals(cls)) {
            T leftConstantExpression = (T) leftExpression;
            constantExpressions.add(leftConstantExpression);
        } else {
            BinaryExpression leftBinaryExpression = (BinaryExpression) leftExpression;
            List<T> leftConstantExpressions = parseLine(leftBinaryExpression, cls);
            constantExpressions.addAll(leftConstantExpressions);
        }

        T rightExpression = (T) exp.getRightExpression();
        constantExpressions.add(rightExpression);

        return constantExpressions;

    }
 
开发者ID:kiview,项目名称:do-with-macro-method,代码行数:22,代码来源:WithBlockLineParser.java

示例2: getArgsModifiers

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
public static YMap<String, YSet<String>> getArgsModifiers(MethodNode methodNode, YMap<String, YSet<String>> result) {

        for (Parameter parameter : methodNode.getParameters()) if (!isPrimitive(translateType(parameter.getText()))) {

            YList<Boolean> rewritten = al(false);
            CodeVisitorSupport detectRewrittenVisitor = new CodeVisitorSupport() {

                @Override
                public void visitBinaryExpression(BinaryExpression expression) {
                    if (expression.getOperation().getText().equals("=")) {
                        Expression left = expression.getLeftExpression();
                        if (left instanceof VariableExpression) {
                            if (((VariableExpression) left).getName().equals(parameter.getName())) {
                                rewritten.set(0, true);
                            }
                        }
                    }
                    super.visitBinaryExpression(expression);
                }
            };
            detectRewrittenVisitor.visitBlockStatement((BlockStatement) methodNode.getCode());
            if (rewritten.get(0)) System.out.println(parameter.getName() + " rewritten!");
        }
        return result;
    }
 
开发者ID:kravchik,项目名称:senjin,代码行数:26,代码来源:Visitors.java

示例3: createCatchBlockForOuterNewTryCatchStatement

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private CatchStatement createCatchBlockForOuterNewTryCatchStatement(String primaryExcName) {
    // { ... }
    BlockStatement blockStatement = new BlockStatement();
    String tExcName = this.genTExcName();

    // #primaryExc = #t;
    ExpressionStatement primaryExcAssignStatement =
            new ExpressionStatement(
                    new BinaryExpression(
                            new VariableExpression(primaryExcName),
                            org.codehaus.groovy.syntax.Token.newSymbol(Types.ASSIGN, -1, -1),
                            new VariableExpression(tExcName)));
    astBuilder.appendStatementsToBlockStatement(blockStatement, primaryExcAssignStatement);

    // throw #t;
    ThrowStatement throwTExcStatement = new ThrowStatement(new VariableExpression(tExcName));
    astBuilder.appendStatementsToBlockStatement(blockStatement, throwTExcStatement);

    // Throwable #t
    Parameter tExcParameter = new Parameter(ClassHelper.make(Throwable.class), tExcName);

    return new CatchStatement(tExcParameter, blockStatement);
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:TryWithResourcesASTTransformation.java

示例4: visitAssertStatement

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
@Override
public AssertStatement visitAssertStatement(AssertStatementContext ctx) {
    Expression conditionExpression = (Expression) this.visit(ctx.ce);

    if (conditionExpression instanceof BinaryExpression) {
        BinaryExpression binaryExpression = (BinaryExpression) conditionExpression;

        if (binaryExpression.getOperation().getType() == Types.ASSIGN) {
            throw createParsingFailedException("Assignment expression is not allowed in the assert statement", conditionExpression);
        }
    }

    BooleanExpression booleanExpression =
            configureAST(
                    new BooleanExpression(conditionExpression), conditionExpression);

    if (!asBoolean(ctx.me)) {
        return configureAST(
                new AssertStatement(booleanExpression), ctx);
    }

    return configureAST(new AssertStatement(booleanExpression,
                    (Expression) this.visit(ctx.me)),
            ctx);
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:AstBuilder.java

示例5: evaluateCompareTo

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private void evaluateCompareTo(BinaryExpression expression) {
    Expression leftExpression = expression.getLeftExpression();
    AsmClassGenerator acg = controller.getAcg();
    OperandStack operandStack = controller.getOperandStack();
    
    leftExpression.visit(acg);
    operandStack.box();

    // if the right hand side is a boolean expression, we need to autobox
    Expression rightExpression = expression.getRightExpression();
    rightExpression.visit(acg);
    operandStack.box();

    compareToMethod.call(controller.getMethodVisitor());
    operandStack.replace(ClassHelper.Integer_TYPE,2);
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:BinaryExpressionHelper.java

示例6: evaluateLogicalAndExpression

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private void evaluateLogicalAndExpression(BinaryExpression expression) {
    MethodVisitor mv = controller.getMethodVisitor();
    AsmClassGenerator acg = controller.getAcg();
    OperandStack operandStack = controller.getOperandStack();

    expression.getLeftExpression().visit(acg);
    operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
    Label falseCase = operandStack.jump(IFEQ);

    expression.getRightExpression().visit(acg);
    operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
    operandStack.jump(IFEQ,falseCase);

    ConstantExpression.PRIM_TRUE.visit(acg);
    Label trueCase = new Label();
    mv.visitJumpInsn(GOTO, trueCase);

    mv.visitLabel(falseCase);
    ConstantExpression.PRIM_FALSE.visit(acg);

    mv.visitLabel(trueCase);
    operandStack.remove(1); // have to remove 1 because of the GOTO
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:BinaryExpressionHelper.java

示例7: doPrimitiveCompare

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
protected boolean doPrimitiveCompare(ClassNode leftType, ClassNode rightType, BinaryExpression binExp) {
    Expression leftExp = binExp.getLeftExpression();
    Expression rightExp = binExp.getRightExpression();
    int operation = binExp.getOperation().getType();
    
    int operationType = getOperandConversionType(leftType,rightType);
    BinaryExpressionWriter bew = binExpWriter[operationType];

    if (!bew.write(operation, true)) return false;
        
    AsmClassGenerator acg = getController().getAcg();
    OperandStack os = getController().getOperandStack();
    leftExp.visit(acg);
    os.doGroovyCast(bew.getNormalOpResultType());
    rightExp.visit(acg);
    os.doGroovyCast(bew.getNormalOpResultType());
    bew.write(operation, false);
    
    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:BinaryExpressionMultiTypeDispatcher.java

示例8: usesToken

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
/**
 * Checks that a given {@link BinaryExpression} uses a specific
 * token type. The token type is an `int` value. You can use
 * {@link Types} where all token types are declared.
 *
 * @deprecated use {@link asteroid.Criterias}
 * @param tokenType Check {@link Types} for more info
 * @return a {@link Closure} used as criteria
 * @since 0.2.3
 * @see Types
 */
@Deprecated
public static Closure<Boolean> usesToken(final int tokenType) {
    return new Closure<Boolean>(null) {
        public Boolean doCall(final Expression expression) {
            if (!(expression instanceof BinaryExpression)) {
                return false;
            }

            final BinaryExpression binaryExpression = (BinaryExpression) expression;

            return binaryExpression
                .getOperation()
                .getType() == tokenType;
        }
    };
}
 
开发者ID:grooviter,项目名称:asteroid,代码行数:28,代码来源:AbstractExpressionTransformer.java

示例9: evaluateEqual

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
@Override
public void evaluateEqual(final BinaryExpression expression, final boolean defineVariable) {
    if (!defineVariable) {
        Expression leftExpression = expression.getLeftExpression();
        if (leftExpression instanceof PropertyExpression) {
            PropertyExpression pexp = (PropertyExpression) leftExpression;
            if (makeSetProperty(
                    pexp.getObjectExpression(),
                    pexp.getProperty(),
                    expression.getRightExpression(),
                    pexp.isSafe(),
                    pexp.isSpreadSafe(),
                    pexp.isImplicitThis(),
                    pexp instanceof AttributeExpression)) return;
        }
    }
    // GROOVY-5620: Spread safe/Null safe operator on LHS is not supported
    if (expression.getLeftExpression() instanceof PropertyExpression
            && ((PropertyExpression) expression.getLeftExpression()).isSpreadSafe()
            && StaticTypeCheckingSupport.isAssignment(expression.getOperation().getType())) {
        // rewrite it so that it can be statically compiled
        transformSpreadOnLHS(expression);
        return;
    }
    super.evaluateEqual(expression, defineVariable);
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:StaticTypesBinaryExpressionMultiTypeDispatcher.java

示例10: tryOptimizeCharComparison

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private static BinaryExpression tryOptimizeCharComparison(final Expression left, final Expression right, final BinaryExpression bin) {
    int op = bin.getOperation().getType();
    if (isCompareToBoolean(op) || op == COMPARE_EQUAL || op == COMPARE_NOT_EQUAL) {
        Character cLeft = tryCharConstant(left);
        Character cRight = tryCharConstant(right);
        if (cLeft != null || cRight != null) {
            Expression oLeft = cLeft == null ? left : new ConstantExpression(cLeft, true);
            oLeft.setSourcePosition(left);
            Expression oRight = cRight == null ? right : new ConstantExpression(cRight, true);
            oRight.setSourcePosition(right);
            bin.setLeftExpression(oLeft);
            bin.setRightExpression(oRight);
            return bin;
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:BinaryExpressionTransformer.java

示例11: transformDeclarationExpression

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private static Expression transformDeclarationExpression(final BinaryExpression bin) {
    Expression leftExpression = bin.getLeftExpression();
    if (leftExpression instanceof VariableExpression) {
        if (ClassHelper.char_TYPE.equals(((VariableExpression) leftExpression).getOriginType())) {
            Expression rightExpression = bin.getRightExpression();
            if (rightExpression instanceof ConstantExpression && ClassHelper.STRING_TYPE.equals(rightExpression.getType())) {
                String text = (String) ((ConstantExpression) rightExpression).getValue();
                if (text.length() == 1) {
                    // optimize char initialization
                    ConstantExpression ce = new ConstantExpression(
                            text.charAt(0),
                            true
                    );
                    ce.setSourcePosition(rightExpression);
                    bin.setRightExpression(ce);
                    return bin;
                }
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:BinaryExpressionTransformer.java

示例12: convertInOperatorToTernary

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private Expression convertInOperatorToTernary(final BinaryExpression bin, final Expression rightExpression, final Expression leftExpression) {
    MethodCallExpression call = new MethodCallExpression(
            rightExpression,
            "isCase",
            leftExpression
    );
    call.setMethodTarget((MethodNode) bin.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET));
    call.setSourcePosition(bin);
    call.copyNodeMetaData(bin);
    TernaryExpression tExp = new TernaryExpression(
            new BooleanExpression(
                    new BinaryExpression(rightExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null))
            ),
            new BinaryExpression(leftExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null)),
            call
    );
    return staticCompilationTransformer.transform(tExp);
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:BinaryExpressionTransformer.java

示例13: optimizeConstantInitialization

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private static DeclarationExpression optimizeConstantInitialization(
        final BinaryExpression originalDeclaration,
        final Token operation,
        final ConstantExpression constant,
        final Expression leftExpression,
        final ClassNode declarationType) {
    ConstantExpression cexp = new ConstantExpression(
            convertConstant((Number) constant.getValue(), ClassHelper.getWrapper(declarationType)), true);
    cexp.setType(declarationType);
    cexp.setSourcePosition(constant);
    DeclarationExpression result = new DeclarationExpression(
            leftExpression,
            operation,
            cexp
    );
    result.setSourcePosition(originalDeclaration);
    result.copyNodeMetaData(originalDeclaration);
    return result;
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:BinaryExpressionTransformer.java

示例14: transformBinaryExpression

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
private Expression transformBinaryExpression(final BinaryExpression exp) {
    final int op = exp.getOperation().getType();
    int token = TokenUtil.removeAssignment(op);
    if (token == op) {
        // no transform needed
        return super.transform(exp);
    }
    BinaryExpression operation = new BinaryExpression(
            exp.getLeftExpression(),
            Token.newSymbol(token, -1, -1),
            exp.getRightExpression()
    );
    operation.setSourcePosition(exp);
    BinaryExpression result = new BinaryExpression(
            exp.getLeftExpression(),
            Token.newSymbol(EQUAL, -1, -1),
            operation
    );
    result.setSourcePosition(exp);
    return result;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:NAryOperationRewriter.java

示例15: positionStmtsAfterEnumInitStmts

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
public void positionStmtsAfterEnumInitStmts(List<Statement> staticFieldStatements) {
    MethodNode method = getOrAddStaticConstructorNode();
    Statement statement = method.getCode();
    if (statement instanceof BlockStatement) {
        BlockStatement block = (BlockStatement) statement;
        // add given statements for explicitly declared static fields just after enum-special fields
        // are found - the $VALUES binary expression marks the end of such fields.
        List<Statement> blockStatements = block.getStatements();
        ListIterator<Statement> litr = blockStatements.listIterator();
        while (litr.hasNext()) {
            Statement stmt = litr.next();
            if (stmt instanceof ExpressionStatement &&
                    ((ExpressionStatement) stmt).getExpression() instanceof BinaryExpression) {
                BinaryExpression bExp = (BinaryExpression) ((ExpressionStatement) stmt).getExpression();
                if (bExp.getLeftExpression() instanceof FieldExpression) {
                    FieldExpression fExp = (FieldExpression) bExp.getLeftExpression();
                    if (fExp.getFieldName().equals("$VALUES")) {
                        for (Statement tmpStmt : staticFieldStatements) {
                            litr.add(tmpStmt);
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:ClassNode.java


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