Search in sources :

Example 31 with CastExpr

use of com.github.javaparser.ast.expr.CastExpr in project checker-framework by typetools.

the class JointJavacJavaParserVisitor method visitTypeCast.

@Override
public Void visitTypeCast(TypeCastTree javacTree, Node javaParserNode) {
    CastExpr node = castNode(CastExpr.class, javaParserNode, javacTree);
    processTypeCast(javacTree, node);
    javacTree.getType().accept(this, node.getType());
    javacTree.getExpression().accept(this, node.getExpression());
    return null;
}
Also used : CastExpr(com.github.javaparser.ast.expr.CastExpr)

Example 32 with CastExpr

use of com.github.javaparser.ast.expr.CastExpr in project vue-gwt by Axellience.

the class TemplateParser method getTypeFromCast.

/**
 * Get the type of an expression from the cast at the beginning.
 * (int) 12 -> 12 of type int
 * (int) 15 + 5 -> 15 + 5 of type int
 * (float) (12 + 3) -> 12 + 3 of type float
 * ((int) 12) + 3 -> ((int) 12) + 3 of type Any
 * ((JsArray) myArray).getAt(0) -> ((JsArray) myArray).getAt(0) of type Any
 * @param expression The expression to process
 * @return The modified expression (where cast has been removed if necessary)
 */
private Expression getTypeFromCast(Expression expression) {
    if (expression instanceof BinaryExpr) {
        Expression mostLeft = getLeftmostExpression(expression);
        if (mostLeft instanceof CastExpr) {
            CastExpr castExpr = (CastExpr) mostLeft;
            currentExpressionReturnType = stringTypeToTypeName(castExpr.getType().toString());
            BinaryExpr parent = (BinaryExpr) mostLeft.getParentNode().get();
            parent.setLeft(castExpr.getExpression());
        }
    } else if (expression instanceof CastExpr) {
        CastExpr castExpr = (CastExpr) expression;
        currentExpressionReturnType = stringTypeToTypeName(castExpr.getType().toString());
        expression = castExpr.getExpression();
    }
    return expression;
}
Also used : TemplateExpression(com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression) Expression(com.github.javaparser.ast.expr.Expression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) CastExpr(com.github.javaparser.ast.expr.CastExpr)

Aggregations

CastExpr (com.github.javaparser.ast.expr.CastExpr)32 Expression (com.github.javaparser.ast.expr.Expression)21 NameExpr (com.github.javaparser.ast.expr.NameExpr)13 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)11 Test (org.junit.Test)9 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)7 CompilationUnit (com.github.javaparser.ast.CompilationUnit)6 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)6 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)6 Type (com.github.javaparser.ast.type.Type)6 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)6 NodeList (com.github.javaparser.ast.NodeList)5 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)5 ThisExpr (com.github.javaparser.ast.expr.ThisExpr)5 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)4 UnificationTypedExpression (org.drools.modelcompiler.builder.generator.UnificationTypedExpression)4 DrlNameExpr (org.drools.mvel.parser.ast.expr.DrlNameExpr)4 SerializableFunction (org.kie.pmml.api.iinterfaces.SerializableFunction)4 Node (com.github.javaparser.ast.Node)3 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)3