@Override public Expression apply(final AstNode e) { return new CastExpression(castToType, right); } }
public final AstType getType() { return getChildByRole(Roles.TYPE); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof CastExpression) { final CastExpression otherCast = (CastExpression) other; return !otherCast.isNull() && getType().matches(otherCast.getType(), match) && getExpression().matches(otherCast.getExpression(), match); } return false; } }
public CastExpression(final AstType castToType, final Expression expression) { super( expression.getOffset()); setType(castToType); setExpression(expression); }
public boolean isInPolymorphicCall(final CastExpression cast) { // // See http://download.java.net/jdk7/docs/api/java/lang/invoke/MethodHandle.html#sigpoly // final Expression operand = cast.getExpression(); if (operand instanceof InvocationExpression || operand instanceof MemberReferenceExpression && operand.getParent() instanceof InvocationExpression || operand instanceof ObjectCreationExpression) { if (isPolymorphicMethod(operand)) { return true; } } return cast.getRole() == Roles.ARGUMENT && isPolymorphicMethod(skipParenthesesUp(cast.getParent())); }
@Override public Void visitCastExpression(final CastExpression node, final Void data) { super.visitCastExpression(node, data); final Expression operand = node.getExpression(); final ResolveResult targetResult = _resolver.apply(node.getType()); if (targetResult == null || targetResult.getType() == null) { return null; } final ResolveResult valueResult = _resolver.apply(operand); if (valueResult == null || valueResult.getType() == null) { return null; } final ConversionType conversionType = MetadataHelper.getConversionType(targetResult.getType(), valueResult.getType()); if (conversionType == ConversionType.NONE) { addCastForAssignment(node.getType(), node.getExpression()); } if (RedundantCastUtility.isCastRedundant(_resolver, node)) { RedundantCastUtility.removeCast(node); } return null; }
public boolean isTypeCastSemantic(final CastExpression cast) { final Expression operand = cast.getExpression(); final TypeReference castType = getType(cast.getType()); AstNode parent = cast.getParent();
protected void processAlreadyHasTypeCast(final CastExpression cast) { AstNode parent = cast.getParent(); cast.getRole() == Roles.ARGUMENT && !(parent instanceof IndexerExpression) || parent instanceof AssignmentExpression || parent instanceof ReturnStatement || final TypeReference castTo = getType(cast.getType()); final Expression operand = cast.getExpression();
public static void removeCast(final CastExpression castExpression) { if (castExpression == null || castExpression.isNull()) { return; } Expression operand = castExpression.getExpression(); if (operand instanceof ParenthesizedExpression) { operand = ((ParenthesizedExpression) operand).getExpression(); } if (operand == null || operand.isNull()) { return; } AstNode toBeReplaced = castExpression; AstNode parent = castExpression.getParent(); while (parent instanceof ParenthesizedExpression) { toBeReplaced = parent; parent = parent.getParent(); } toBeReplaced.replaceWith(operand); }
super.visitCastExpression(node, data); final AstType castType = node.getType(); final TypeReference typeReference = castType.toTypeReference(); final Expression operand = node.getExpression(); final ResolveResult rr = _resolver.apply(operand); replacement.getTarget().putUserData(Keys.MEMBER_REFERENCE, boxMethod); node.replaceWith(replacement);
@Override public Void visitCastExpression(final CastExpression node, final Void data) { super.visitCastExpression(node, data); final List<CastExpression> redundantCasts = RedundantCastUtility.getRedundantCastsInside( _resolver, skipParenthesesUp(node.getParent()) ); if (redundantCasts.contains(node)) { RedundantCastUtility.removeCast(node); } return null; }
public final void setExpression(final Expression value) { setChildByRole(Roles.EXPRESSION, value); }
protected void processBinaryExpressionOperand( final Expression operand, final TypeReference otherType, final BinaryOperatorType op) { if (operand instanceof CastExpression) { final CastExpression cast = (CastExpression) operand; final Expression toCast = cast.getExpression(); final TypeReference castType = getType(cast); final TypeReference innerType = getType(toCast); if (castType != null && innerType != null && TypeUtilities.isBinaryOperatorApplicable(op, innerType, otherType, false)) { addToResults(cast, false); } } }
private void removeUnboxingForCast( final InvocationExpression e, final MemberReferenceExpression target, final CastExpression parent) { final TypeReference targetType = parent.getType().toTypeReference(); if (targetType == null || !targetType.isPrimitive()) { return; } final Expression boxedValue = target.getTarget(); final ResolveResult boxedValueResult = _resolver.apply(boxedValue); if (boxedValueResult == null || boxedValueResult.getType() == null) { return; } final TypeReference sourceType = boxedValueResult.getType(); final ConversionType conversionType = MetadataHelper.getNumericConversionType(targetType, sourceType); switch (conversionType) { case IMPLICIT: case EXPLICIT: case EXPLICIT_TO_UNBOXED: { boxedValue.remove(); e.replaceWith(boxedValue); return; } default: return; } }
@Override public Void visitCastExpression(final CastExpression node, final Void data) { super.visitCastExpression(node, data); final Expression operand = node.getExpression(); final ResolveResult targetResult = _resolver.apply(node.getType()); if (targetResult == null || targetResult.getType() == null) { return null; } final ResolveResult valueResult = _resolver.apply(operand); if (valueResult == null || valueResult.getType() == null) { return null; } final ConversionType conversionType = MetadataHelper.getConversionType(targetResult.getType(), valueResult.getType()); if (conversionType == ConversionType.NONE) { addCastForAssignment(node.getType(), node.getExpression()); } if (RedundantCastUtility.isCastRedundant(_resolver, node)) { RedundantCastUtility.removeCast(node); } return null; }
public boolean isTypeCastSemantic(final CastExpression cast) { final Expression operand = cast.getExpression(); final TypeReference castType = getType(cast.getType()); AstNode parent = cast.getParent();
protected void processAlreadyHasTypeCast(final CastExpression cast) { AstNode parent = cast.getParent(); cast.getRole() == Roles.ARGUMENT && !(parent instanceof IndexerExpression) || parent instanceof AssignmentExpression || parent instanceof ReturnStatement || final TypeReference castTo = getType(cast.getType()); final Expression operand = cast.getExpression();
public boolean isInPolymorphicCall(final CastExpression cast) { // // See http://download.java.net/jdk7/docs/api/java/lang/invoke/MethodHandle.html#sigpoly // final Expression operand = cast.getExpression(); if (operand instanceof InvocationExpression || operand instanceof MemberReferenceExpression && operand.getParent() instanceof InvocationExpression || operand instanceof ObjectCreationExpression) { if (isPolymorphicMethod(operand)) { return true; } } return cast.getRole() == Roles.ARGUMENT && isPolymorphicMethod(skipParenthesesUp(cast.getParent())); }
public static void removeCast(final CastExpression castExpression) { if (castExpression == null || castExpression.isNull()) { return; } Expression operand = castExpression.getExpression(); if (operand instanceof ParenthesizedExpression) { operand = ((ParenthesizedExpression) operand).getExpression(); } if (operand.isNull()) { return; } AstNode toBeReplaced = castExpression; AstNode parent = castExpression.getParent(); while (parent instanceof ParenthesizedExpression) { toBeReplaced = parent; parent = parent.getParent(); } toBeReplaced.replaceWith(operand); }
public CastExpression(final AstType castToType, final Expression expression) { super( expression.getOffset()); setType(castToType); setExpression(expression); }