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;
}
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;
}
Aggregations