org.codehaus.groovy.ast.expr.BinaryExpression Java Examples

The following examples show how to use org.codehaus.groovy.ast.expr.BinaryExpression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected void evaluateBinaryExpressionWithAssignment(final String method, final BinaryExpression expression) {
    Expression leftExpression = expression.getLeftExpression();
    if (leftExpression instanceof BinaryExpression) {
        BinaryExpression bexp = (BinaryExpression) leftExpression;
        if (bexp.getOperation().getType() == LEFT_SQUARE_BRACKET) {
            evaluateArrayAssignmentWithOperator(method, expression, bexp);
            return;
        }
    }

    evaluateBinaryExpression(method, expression);

    // br to leave a copy of rvalue on the stack; see also isPopRequired()
    controller.getOperandStack().dup();
    controller.getCompileStack().pushLHS(true);
    leftExpression.visit(controller.getAcg());
    controller.getCompileStack().popLHS();
}
 
Example #2
Source File: VariableFinderVisitor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void visitBinaryExpression(BinaryExpression expression) {
    // if we are in the same block we check position, if it occurs after
    // current position we ignore it
    if (blocks.isEmpty()
            && expression.getLineNumber() >= 0 && expression.getColumnNumber() >= 0
            && path.getLineNumber() >= 0 && path.getColumnNumber() >= 0
            && (expression.getLineNumber() > path.getLineNumber()
            || (expression.getLineNumber() == path.getLineNumber() && expression.getColumnNumber() >= path.getColumnNumber()))) {
        return;
    }

    Expression leftExpression = expression.getLeftExpression();
    if (leftExpression instanceof VariableExpression) {
        if (expression.getOperation().isA(Types.EQUAL)) {
            VariableExpression variableExpression = (VariableExpression) leftExpression;
            if (variableExpression.getAccessedVariable() != null) {
                String name = variableExpression.getAccessedVariable().getName();
                if (!variables.containsKey(name)) {
                    variables.put(name, variableExpression.getAccessedVariable());
                }
            }
        }
    }
    super.visitBinaryExpression(expression);
}
 
Example #3
Source File: TypeInferenceVisitor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void visitBinaryExpression(BinaryExpression expression) {
    if (!leafReached) {
        // have a look at assignment and try to get type from its right side
        Expression leftExpression = expression.getLeftExpression();
        if (leftExpression instanceof VariableExpression) {
            if (expression.getOperation().isA(Types.EQUAL) && sameVariableName(leaf, leftExpression)) {
                Expression rightExpression = expression.getRightExpression();
                if (rightExpression instanceof ConstantExpression
                        && !rightExpression.getText().equals("null")) { // NOI18N
                    guessedType = ((ConstantExpression) rightExpression).getType();
                } else if (rightExpression instanceof ConstructorCallExpression) {
                    guessedType = ClassHelper.make(((ConstructorCallExpression) rightExpression).getType().getName());
                } else if (rightExpression instanceof MethodCallExpression) {
                    guessedType = MethodInference.findCallerType(rightExpression, path, doc, cursorOffset);
                } else if (rightExpression instanceof StaticMethodCallExpression) {
                    guessedType = MethodInference.findCallerType(rightExpression, path, doc, cursorOffset);
                }
            }
        }
    }
    super.visitBinaryExpression(expression);
}
 
Example #4
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void evaluateLogicalOrExpression(final BinaryExpression expression) {
    AsmClassGenerator acg = controller.getAcg();
    MethodVisitor mv = controller.getMethodVisitor();
    OperandStack operandStack = controller.getOperandStack();

    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);
    Label end = new Label();
    operandStack.jump(GOTO, end);

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

    mv.visitLabel(end);
}
 
Example #5
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void execMethodAndStoreForSubscriptOperator(final int op, String method, final Expression expression, final VariableSlotLoader usesSubscript, final Expression orig) {
    writePostOrPrefixMethod(op, method, expression, orig);

    // we need special code for arrays to store the result (like for a[1]++)
    if (usesSubscript != null) {
        BinaryExpression be = (BinaryExpression) expression;
        CompileStack compileStack = controller.getCompileStack();
        OperandStack operandStack = controller.getOperandStack();
        ClassNode methodResultType = operandStack.getTopOperand();
        int resultIdx = compileStack.defineTemporaryVariable("postfix_" + method, methodResultType, true);
        BytecodeExpression methodResultLoader = new VariableSlotLoader(methodResultType, resultIdx, operandStack);

        // execute the assignment, this will leave the right side (here the method call result) on the stack
        assignToArray(be, be.getLeftExpression(), usesSubscript, methodResultLoader, be.isSafe());

        compileStack.removeVar(resultIdx);

    } else if (expression instanceof VariableExpression || expression instanceof PropertyExpression || expression instanceof FieldExpression) {
        // here we handle a++ and a.b++
        controller.getOperandStack().dup();
        controller.getCompileStack().pushLHS(true);
        expression.visit(controller.getAcg());
        controller.getCompileStack().popLHS();
    }
    // other cases don't need storing, so nothing to be done for them
}
 
Example #6
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void evaluateLogicalAndExpression(final BinaryExpression expression) {
    AsmClassGenerator acg = controller.getAcg();
    MethodVisitor mv = controller.getMethodVisitor();
    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
}
 
Example #7
Source File: TryWithResourcesASTTransformation.java    From groovy with Apache License 2.0 6 votes vote down vote up
private CatchStatement createCatchBlockForOuterNewTryCatchStatement(String primaryExcName) {
    // { ... }
    BlockStatement blockStatement = new BlockStatement();
    String tExcName = this.genTExcName();

    // #primaryExc = #t;
    ExpressionStatement primaryExcAssignStatement =
            new ExpressionStatement(
                    new BinaryExpression(
                            new VariableExpression(primaryExcName),
                            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);
}
 
Example #8
Source File: BinaryExpressionMultiTypeDispatcher.java    From groovy with Apache License 2.0 6 votes vote down vote up
private boolean doAssignmentToLocalVariable(final String method, final BinaryExpression binExp) {
    Expression left = binExp.getLeftExpression();
    if (left instanceof VariableExpression) {
        VariableExpression ve = (VariableExpression) left;
        Variable v = ve.getAccessedVariable();
        if (v instanceof DynamicVariable) return false;
        if (v instanceof PropertyExpression) return false;
        /* field and declaration we don't return false */
    } else {
        return false;
    }

    evaluateBinaryExpression(method, binExp);
    controller.getOperandStack().dup();
    controller.getCompileStack().pushLHS(true);
    binExp.getLeftExpression().visit(controller.getAcg());
    controller.getCompileStack().popLHS();

    return true;
}
 
Example #9
Source File: SqlWhereVisitor.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void visitBinaryExpression(BinaryExpression expression) {
    Expression left = expression.getLeftExpression();
    Expression right = expression.getRightExpression();
    boolean leaf = (right instanceof ConstantExpression || left instanceof ConstantExpression);

    if (!leaf) buffer.append("(");
    left.visit(this);
    buffer.append(" ");

    Token token = expression.getOperation();
    buffer.append(tokenAsSql(token));

    buffer.append(" ");
    right.visit(this);
    if (!leaf) buffer.append(")");
}
 
Example #10
Source File: StaticImportVisitor.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected Expression transformBinaryExpression(BinaryExpression be) {
    int type = be.getOperation().getType();
    boolean oldInLeftExpression;
    Expression right = transform(be.getRightExpression());
    be.setRightExpression(right);
    Expression left;
    if (type == Types.EQUAL && be.getLeftExpression() instanceof VariableExpression) {
        oldInLeftExpression = inLeftExpression;
        inLeftExpression = true;
        left = transform(be.getLeftExpression());
        inLeftExpression = oldInLeftExpression;
        if (left instanceof StaticMethodCallExpression) {
            StaticMethodCallExpression smce = (StaticMethodCallExpression) left;
            StaticMethodCallExpression result = new StaticMethodCallExpression(smce.getOwnerType(), smce.getMethod(), right);
            setSourcePosition(result, be);
            return result;
        }
    } else {
        left = transform(be.getLeftExpression());
    }
    be.setLeftExpression(left);
    return be;
}
 
Example #11
Source File: ContractInputProposalsCodeVisitorSupport.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitBinaryExpression(final BinaryExpression expression) {
    proposals = completionComputer.computeCompletionProposals(context, monitor);
    final BinaryExpression binaryExpression = (BinaryExpression) contentAssistContext.getPerceivedCompletionNode();
    final Expression leftExpression = binaryExpression.getLeftExpression();
    String multipleInputName = null;
    if (leftExpression instanceof PropertyExpression) {
        final PropertyExpression propertyExpr = (PropertyExpression) leftExpression;
        final Expression objectExpression = propertyExpr.getProperty();
        multipleInputName = objectExpression.getText();
    } else if (leftExpression instanceof VariableExpression) {
        multipleInputName = ((VariableExpression) leftExpression).getName();
    }
    if (multipleInputName != null) {
        final ContractInput multipleInput = getInputWithName(multipleInputName, inputs);
        final ContractInput copy = EcoreUtil.copy(multipleInput);
        copy.setMultiple(false);
        final String fullyQualifiedType = ExpressionHelper.getContractInputReturnType(copy);
        if (fullyQualifiedType != null && prefix.isEmpty()) {
            proposals = getMethodProposals(contentAssistContext, context, inputs, prefix, multipleInputName, fullyQualifiedType);
        }
    }
}
 
Example #12
Source File: FinalVariableAnalyzer.java    From groovy with Apache License 2.0 6 votes vote down vote up
@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
    inAssignmentRHS = assignment;
    rightExpression.visit(this);
    inAssignmentRHS = false;
    leftExpression.visit(this);
    if (assignment) {
        recordAssignments(expression, isDeclaration, leftExpression, rightExpression);
    }
}
 
Example #13
Source File: InstanceOfVerifier.java    From groovy with Apache License 2.0 6 votes vote down vote up
@Override
public void visitBinaryExpression(BinaryExpression expression) {
    if (expression.getOperation().isA(Types.INSTANCEOF_OPERATOR) &&
            expression.getRightExpression() instanceof ClassExpression) {
        ClassNode referenceType = expression.getRightExpression().getType();

        if (ClassHelper.isPrimitiveType(referenceType)) {
            addTypeError(expression.getRightExpression(), "primitive type " + referenceType.getName());
        } else {
            while (referenceType.isArray()) {
                referenceType = referenceType.getComponentType();
            }

            if (referenceType.isGenericsPlaceHolder()) {
                addTypeError(expression.getRightExpression(), "type parameter " + referenceType.getUnresolvedName() +
                    ". Use its erasure " + referenceType.getNameWithoutPackage() + " instead since further generic type information will be erased at runtime");
            } else if (referenceType.getGenericsTypes() != null) {
                // TODO: Cannot perform instanceof check against parameterized type Class<Type>. Use the form Class<?> instead since further eneric type information will be erased at runtime
            }
        }
    }
    super.visitBinaryExpression(expression);
}
 
Example #14
Source File: InnerClassVisitorHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
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])
                    )
            )
    );
}
 
Example #15
Source File: NAryOperationRewriter.java    From groovy with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #16
Source File: OptimizingStatementWriter.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Optimizes "Z = X/Y" with Z being int or long style.
 *
 * @returns null if the optimization cannot be applied, otherwise it will return the new target type
 */
private ClassNode optimizeDivWithIntOrLongTarget(final Expression rhs, final ClassNode assignmentTartgetType) {
    if (!(rhs instanceof BinaryExpression)) return null;
    BinaryExpression binExp = (BinaryExpression) rhs;
    int op = binExp.getOperation().getType();
    if (op != Types.DIVIDE && op != Types.DIVIDE_EQUAL) return null;

    ClassNode originalResultType = typeChooser.resolveType(binExp, node);
    if (!originalResultType.equals(BigDecimal_TYPE)
            || !(isLongCategory(assignmentTartgetType) || isFloatingCategory(assignmentTartgetType))) {
        return null;
    }

    ClassNode leftType = typeChooser.resolveType(binExp.getLeftExpression(), node);
    if (!isLongCategory(leftType)) return null;
    ClassNode rightType = typeChooser.resolveType(binExp.getRightExpression(), node);
    if (!isLongCategory(rightType)) return null;

    ClassNode target;
    if (isIntCategory(leftType) && isIntCategory(rightType)) {
        target = int_TYPE;
    } else if (isLongCategory(leftType) && isLongCategory(rightType)) {
        target = long_TYPE;
    } else if (isDoubleCategory(leftType) && isDoubleCategory(rightType)) {
        target = double_TYPE;
    } else {
        return null;
    }
    addMeta(rhs).type = target;
    opt.chainInvolvedType(target);
    return target;
}
 
Example #17
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
public void evaluateElvisEqual(final BinaryExpression expression) {
    Token operation = expression.getOperation();
    BinaryExpression elvisAssignmentExpression = binX(
            expression.getLeftExpression(),
            Token.newSymbol(ASSIGN, operation.getStartLine(), operation.getStartColumn()),
            new ElvisOperatorExpression(expression.getLeftExpression(), expression.getRightExpression())
    );
    this.evaluateEqual(elvisAssignmentExpression, false);
}
 
Example #18
Source File: FinalVariableAnalyzer.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void recordAssignments(BinaryExpression expression, boolean isDeclaration, Expression leftExpression, Expression rightExpression) {
    if (leftExpression instanceof Variable) {
        boolean uninitialized = isDeclaration && rightExpression instanceof EmptyExpression;
        recordAssignment((Variable) leftExpression, isDeclaration, uninitialized, false, expression);
    } else if (leftExpression instanceof TupleExpression) {
        TupleExpression te = (TupleExpression) leftExpression;
        for (Expression next : te.getExpressions()) {
            if (next instanceof Variable) {
                recordAssignment((Variable) next, isDeclaration, false, false, next);
            }
        }
    }
}
 
Example #19
Source File: EqualsAndHashCodeASTTransformation.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static BinaryExpression bothSelfRecursivePropertyX(PropertyNode pNode, Expression other) {
    String getterName = getGetterName(pNode);
    Expression selfGetter = callThisX(getterName);
    Expression otherGetter = callX(other, getterName);
    return andX(
            sameX(selfGetter, varX("this")),
            sameX(otherGetter, other)
    );
}
 
Example #20
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected void evaluateCompareExpression(final MethodCaller compareMethod, final BinaryExpression expression) {
    ClassNode classNode = controller.getClassNode();
    Expression leftExp = expression.getLeftExpression();
    Expression rightExp = expression.getRightExpression();
    ClassNode leftType = controller.getTypeChooser().resolveType(leftExp, classNode);
    ClassNode rightType = controller.getTypeChooser().resolveType(rightExp, classNode);

    boolean done = false;
    if (ClassHelper.isPrimitiveType(leftType) && ClassHelper.isPrimitiveType(rightType)) {
        BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(controller);
        done = helper.doPrimitiveCompare(leftType, rightType, expression);
    }
    if (!done) {
        AsmClassGenerator acg = controller.getAcg();
        OperandStack operandStack = controller.getOperandStack();

        leftExp.visit(acg);
        operandStack.box();
        rightExp.visit(acg);
        operandStack.box();

        compareMethod.call(controller.getMethodVisitor());
        ClassNode resType = ClassHelper.boolean_TYPE;
        if (compareMethod == findRegexMethod) {
            resType = ClassHelper.OBJECT_TYPE;
        }
        operandStack.replace(resType, 2);
    }
}
 
Example #21
Source File: EqualsAndHashCodeASTTransformation.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static BinaryExpression differentSelfRecursivePropertyX(PropertyNode pNode, Expression other) {
    String getterName = getGetterName(pNode);
    Expression selfGetter = callThisX(getterName);
    Expression otherGetter = callX(other, getterName);
    return orX(
            andX(sameX(selfGetter, varX("this")), notX(sameX(otherGetter, other))),
            andX(notX(sameX(selfGetter, varX("this"))), sameX(otherGetter, other))
    );
}
 
Example #22
Source File: TraitReceiverTransformer.java    From groovy with Apache License 2.0 5 votes vote down vote up
private BinaryExpression createAssignmentToField(final Expression rightExpression,
                                                 final Token operation, final String fieldName) {
    return new BinaryExpression(
            new PropertyExpression(
                    new VariableExpression(weaved),
                    fieldName
            ),
            operation,
            transform(rightExpression));
}
 
Example #23
Source File: TraitReceiverTransformer.java    From groovy with Apache License 2.0 5 votes vote down vote up
private TernaryExpression createStaticReceiver(final Expression receiver) {
    return new TernaryExpression(
            new BooleanExpression(new BinaryExpression(
                    receiver,
                    Token.newSymbol(Types.KEYWORD_INSTANCEOF, -1, -1),
                    new ClassExpression(ClassHelper.CLASS_Type)
            )),
            receiver,
            new MethodCallExpression(createFieldHelperReceiver(), "getClass", ArgumentListExpression.EMPTY_ARGUMENTS)
    );
}
 
Example #24
Source File: TraitComposer.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static Statement createSuperFallback(MethodNode forwarderMethod, ClassNode returnType) {
    ArgumentListExpression args = new ArgumentListExpression();
    Parameter[] forwarderMethodParameters = forwarderMethod.getParameters();
    for (final Parameter forwarderMethodParameter : forwarderMethodParameters) {
        args.addExpression(new VariableExpression(forwarderMethodParameter));
    }
    BinaryExpression instanceOfExpr = new BinaryExpression(new VariableExpression("this"), Token.newSymbol(Types.KEYWORD_INSTANCEOF, -1, -1), new ClassExpression(Traits.GENERATED_PROXY_CLASSNODE));
    MethodCallExpression superCall = new MethodCallExpression(
            new VariableExpression("super"),
            forwarderMethod.getName(),
            args
    );
    superCall.setImplicitThis(false);
    CastExpression proxyReceiver = new CastExpression(Traits.GENERATED_PROXY_CLASSNODE, new VariableExpression("this"));
    MethodCallExpression getProxy = new MethodCallExpression(proxyReceiver, "getProxyTarget", ArgumentListExpression.EMPTY_ARGUMENTS);
    getProxy.setImplicitThis(true);
    StaticMethodCallExpression proxyCall = new StaticMethodCallExpression(
            ClassHelper.make(InvokerHelper.class),
            "invokeMethod",
            new ArgumentListExpression(getProxy, new ConstantExpression(forwarderMethod.getName()), new ArrayExpression(ClassHelper.OBJECT_TYPE, args.getExpressions()))
    );
    IfStatement stmt = new IfStatement(
            new BooleanExpression(instanceOfExpr),
            new ExpressionStatement(new CastExpression(returnType,proxyCall)),
            new ExpressionStatement(superCall)
    );
    return stmt;
}
 
Example #25
Source File: ASTNodeVisitor.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
public void visitBinaryExpression(BinaryExpression node) {
	pushASTNode(node);
	try {
		super.visitBinaryExpression(node);
	} finally {
		popASTNode();
	}
}
 
Example #26
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void evaluateCompareTo(final BinaryExpression expression) {
    AsmClassGenerator acg = controller.getAcg();
    MethodVisitor mv = controller.getMethodVisitor();
    OperandStack operandStack = controller.getOperandStack();

    expression.getLeftExpression().visit(acg);
    operandStack.box();

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

    compareToMethod.call(mv);
    operandStack.replace(ClassHelper.Integer_TYPE, 2);
}
 
Example #27
Source File: NAryOperationRewriter.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public Expression transform(final Expression exp) {
    if (exp instanceof BinaryExpression) {
        return transformBinaryExpression((BinaryExpression) exp);
    }
    if (exp instanceof PrefixExpression) {
        return transformPrefixExpression((PrefixExpression) exp);
    }
    if (exp instanceof PostfixExpression) {
        return transformPostfixExpression((PostfixExpression) exp);
    }
    return super.transform(exp);
}
 
Example #28
Source File: SuperCallTraitTransformer.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public Expression transform(final Expression exp) {
    if (exp instanceof MethodCallExpression) {
        return transformMethodCallExpression((MethodCallExpression)exp);
    }
    if (exp instanceof BinaryExpression) {
        return transformBinaryExpression((BinaryExpression) exp);
    }
    return super.transform(exp);
}
 
Example #29
Source File: StaticCompilationVisitor.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
protected MethodNode findMethodOrFail(final Expression expr, final ClassNode receiver, final String name, final ClassNode... args) {
    MethodNode methodNode = super.findMethodOrFail(expr, receiver, name, args);
    if (expr instanceof BinaryExpression && methodNode != null) {
        expr.putNodeMetaData(BINARY_EXP_TARGET, new Object[]{methodNode, name});
    }
    return methodNode;
}
 
Example #30
Source File: BinaryExpressionHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void evaluateInstanceof(final BinaryExpression expression) {
    expression.getLeftExpression().visit(controller.getAcg());
    controller.getOperandStack().box();
    Expression rightExp = expression.getRightExpression();
    if (!(rightExp instanceof ClassExpression)) {
        throw new RuntimeException("RHS of the instanceof keyword must be a class name, not: " + rightExp);
    }
    String classInternalName = BytecodeHelper.getClassInternalName(rightExp.getType());
    controller.getMethodVisitor().visitTypeInsn(INSTANCEOF, classInternalName);
    controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
}