• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BinaryExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: evaluateLogicalOrExpression

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

    Label end = new Label();

    expression.getLeftExpression().visit(acg);
    operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
    Label trueCase = operandStack.jump(IFNE);
    
    expression.getRightExpression().visit(acg);
    operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
    Label falseCase = operandStack.jump(IFEQ);
    
    mv.visitLabel(trueCase);
    ConstantExpression.PRIM_TRUE.visit(acg);
    operandStack.jump(GOTO, end);

    mv.visitLabel(falseCase);
    ConstantExpression.PRIM_FALSE.visit(acg);
    
    mv.visitLabel(end);
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:BinaryExpressionHelper.java


示例17: setPropertySetterDispatcher

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
protected static void setPropertySetterDispatcher(BlockStatement block, Expression thiz, Parameter[] parameters) {
    List<ConstantExpression> gStringStrings = new ArrayList<ConstantExpression>();
    gStringStrings.add(new ConstantExpression(""));
    gStringStrings.add(new ConstantExpression(""));
    List<Expression> gStringValues = new ArrayList<Expression>();
    gStringValues.add(new VariableExpression(parameters[0]));
    block.addStatement(
            new ExpressionStatement(
                    new BinaryExpression(
                            new PropertyExpression(
                                    thiz,
                                    new GStringExpression("$name", gStringStrings, gStringValues)
                            ),
                            Token.newSymbol(Types.ASSIGN, -1, -1),
                            new VariableExpression(parameters[1])
                    )
            )
    );
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:InnerClassVisitorHelper.java


示例18: visitBinaryExpression

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
@Override
public void visitBinaryExpression(final BinaryExpression expression) {
    boolean assignment = StaticTypeCheckingSupport.isAssignment(expression.getOperation().getType());
    boolean isDeclaration = expression instanceof DeclarationExpression;
    Expression leftExpression = expression.getLeftExpression();
    Expression rightExpression = expression.getRightExpression();
    if (isDeclaration) {
        recordFinalVars(leftExpression);
    }
    // visit RHS first for expressions like a = b = 0
    inAssignment = assignment;
    rightExpression.visit(this);
    inAssignment = false;
    leftExpression.visit(this);
    if (assignment) {
        recordAssignments(expression, isDeclaration, leftExpression, rightExpression);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:FinalVariableAnalyzer.java


示例19: byExprBinaryUsingToken

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.
 *
 * @param tokenType Check {@link Types} for more info
 * @return a {@link Closure} used as criteria
 * @since 0.2.4
 * @see Types
 */
public static <A extends Expression> Closure<Boolean> byExprBinaryUsingToken(final int tokenType) {
    return new Closure<Boolean>(null) {
        public Boolean doCall(final A expression) {
            if (!(expression instanceof BinaryExpression)) {
                return false;
            }

            final BinaryExpression binaryExpression = (BinaryExpression) expression;

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


示例20: visitExpressionStatement

import org.codehaus.groovy.ast.expr.BinaryExpression; //导入依赖的package包/类
@Override
public void visitExpressionStatement(ExpressionStatement es) {
    Expression exp = es.getExpression();
    if (exp instanceof BinaryExpression) {
        exp.visit(this);
    }
    super.visitExpressionStatement(es);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:9,代码来源:VolatileFieldASTTransformation.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectLookupContainer类代码示例发布时间:2022-05-23
下一篇:
Java SQLExceptionConverter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap