private static boolean appearsInInvocationContext(Expression expression) { if (expression.getParentNode().isPresent()) { Node parent = expression.getParentNode().get(); if (parent instanceof ExpressionStmt) { return false; } if (parent instanceof MethodCallExpr) { return true; } throw new UnsupportedOperationException(parent.getClass().getCanonicalName()); } return false; }
private static boolean isScopeOfThisExpression(@Nonnull Expression expression) { return ThisExpr.class.isInstance(expression.getParentNode()); }
private static boolean appearsInInvocationContext(Expression expression) { if (expression.getParentNode().isPresent()) { Node parent = expression.getParentNode().get(); if (parent instanceof ExpressionStmt) { return false; } if (parent instanceof MethodCallExpr) { return true; } throw new UnsupportedOperationException(parent.getClass().getCanonicalName()); } return false; }
private static boolean appearsInInvocationContext(Expression expression) { if (expression.getParentNode().isPresent()) { Node parent = expression.getParentNode().get(); if (parent instanceof ExpressionStmt) { return false; } if (parent instanceof MethodCallExpr) { return true; } throw new UnsupportedOperationException(parent.getClass().getCanonicalName()); } return false; }
private static boolean appearsInAssignmentContext(Expression expression) { if (expression.getParentNode().isPresent()) { Node parent = expression.getParentNode().get(); if (parent instanceof ExpressionStmt) { return false; } if (parent instanceof MethodCallExpr) { return false; } if (parent instanceof ReturnStmt) { return false; } throw new UnsupportedOperationException(parent.getClass().getCanonicalName()); } return false; }
private static boolean appearsInAssignmentContext(Expression expression) { if (expression.getParentNode().isPresent()) { Node parent = expression.getParentNode().get(); if (parent instanceof ExpressionStmt) { return false; } if (parent instanceof MethodCallExpr) { return false; } if (parent instanceof ReturnStmt) { return false; } throw new UnsupportedOperationException(parent.getClass().getCanonicalName()); } return false; }
private static boolean appearsInAssignmentContext(Expression expression) { if (expression.getParentNode().isPresent()) { Node parent = expression.getParentNode().get(); if (parent instanceof ExpressionStmt) { return false; } if (parent instanceof MethodCallExpr) { return false; } if (parent instanceof ReturnStmt) { return false; } throw new UnsupportedOperationException(parent.getClass().getCanonicalName()); } return false; }
private static boolean isScopeOfAMethodCall(@Nonnull Expression expression) { return MethodCallExpr.class.isInstance(expression.getParentNode()) && expression == MethodCallExpr.class.cast(expression.getParentNode()).getScope(); }
private static boolean isTargetOfAnAssignment(@Nonnull Expression expression) { return AssignExpr.class.isInstance(expression.getParentNode()) && expression == AssignExpr.class.cast(expression.getParentNode()).getTarget(); }
/** * 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; }