@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; } }
@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; } }
@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; } }
@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; }
@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; }
@Override public Void visitCastExpression(final CastExpression node, final Void data) { final Expression child = node.getExpression(); parenthesizeIfRequired(child, UNARY); if (child instanceof UnaryOperatorExpression) { final UnaryOperatorExpression childUnary = (UnaryOperatorExpression) child; if (childUnary.getOperator() != UnaryOperatorType.BITWISE_NOT && childUnary.getOperator() != UnaryOperatorType.NOT) { if (canTypeBeMisinterpretedAsExpression(node.getType())) { parenthesize(child); } } } if (child instanceof PrimitiveExpression) { final PrimitiveExpression primitive = (PrimitiveExpression) child; final Object primitiveValue = primitive.getValue(); if (primitiveValue instanceof Number) { final Number number = (Number) primitiveValue; if (primitiveValue instanceof Float || primitiveValue instanceof Double) { if (number.doubleValue() < 0d) { parenthesize(child); } } else if (number.longValue() < 0L) { parenthesize(child); } } } return super.visitCastExpression(node, data); }
@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; }
@Override public Void visitCastExpression(final CastExpression node, final Void data) { final Expression child = node.getExpression(); parenthesizeIfRequired(child, UNARY); if (child instanceof UnaryOperatorExpression) { final UnaryOperatorExpression childUnary = (UnaryOperatorExpression) child; if (childUnary.getOperator() != UnaryOperatorType.BITWISE_NOT && childUnary.getOperator() != UnaryOperatorType.NOT) { if (canTypeBeMisinterpretedAsExpression(node.getType())) { parenthesize(child); } } } if (child instanceof PrimitiveExpression) { final PrimitiveExpression primitive = (PrimitiveExpression) child; final Object primitiveValue = primitive.getValue(); if (primitiveValue instanceof Number) { final Number number = (Number) primitiveValue; if (primitiveValue instanceof Float || primitiveValue instanceof Double) { if (number.doubleValue() < 0d) { parenthesize(child); } } else if (number.longValue() < 0L) { parenthesize(child); } } } return super.visitCastExpression(node, data); }
@Override public Void visitCastExpression(final CastExpression node, final Void data) { final Expression child = node.getExpression(); parenthesizeIfRequired(child, UNARY); if (child instanceof UnaryOperatorExpression) { final UnaryOperatorExpression childUnary = (UnaryOperatorExpression) child; if (childUnary.getOperator() != UnaryOperatorType.BITWISE_NOT && childUnary.getOperator() != UnaryOperatorType.NOT) { if (canTypeBeMisinterpretedAsExpression(node.getType())) { parenthesize(child); } } } if (child instanceof PrimitiveExpression) { final PrimitiveExpression primitive = (PrimitiveExpression) child; final Object primitiveValue = primitive.getValue(); if (primitiveValue instanceof Number) { final Number number = (Number) primitiveValue; if (primitiveValue instanceof Float || primitiveValue instanceof Double) { if (number.doubleValue() < 0d) { parenthesize(child); } } else if (number.longValue() < 0L) { parenthesize(child); } } } return super.visitCastExpression(node, data); }
@Override public Void visitCastExpression(final CastExpression node, final Void ignored) { startNode(node); leftParenthesis(); space(policy.SpacesWithinCastParentheses); node.getType().acceptVisitor(this, ignored); space(policy.SpacesWithinCastParentheses); rightParenthesis(); space(policy.SpaceAfterTypecast); node.getExpression().acceptVisitor(this, ignored); endNode(node); return null; }
@Override public Void visitCastExpression(final CastExpression node, final Void ignored) { startNode(node); leftParenthesis(); space(policy.SpacesWithinCastParentheses); node.getType().acceptVisitor(this, ignored); space(policy.SpacesWithinCastParentheses); rightParenthesis(); space(policy.SpaceAfterTypecast); node.getExpression().acceptVisitor(this, ignored); endNode(node); return null; }
@Override public Void visitCastExpression(final CastExpression node, final Void ignored) { startNode(node); leftParenthesis(); space(policy.SpacesWithinCastParentheses); node.getType().acceptVisitor(this, ignored); space(policy.SpacesWithinCastParentheses); rightParenthesis(); space(policy.SpaceAfterTypecast); node.getExpression().acceptVisitor(this, ignored); endNode(node); return null; }
@Override public ResolveResult visitCastExpression(final CastExpression node, final Void data) { final ResolveResult childResult = node.getExpression().acceptVisitor(this, data); final ResolveResult typeResult = resolveType(node.getType()); if (typeResult == null) { return childResult; } final TypeReference resolvedType = typeResult.getType(); if (resolvedType != null) { if (resolvedType.isPrimitive() && childResult != null && childResult.isCompileTimeConstant()) { return new PrimitiveResolveResult( resolvedType, JavaPrimitiveCast.cast(resolvedType.getSimpleType(), childResult.getConstantValue()) ); } return new ResolveResult(resolvedType); } return typeResult; }
@Override public ResolveResult visitCastExpression(final CastExpression node, final Void data) { final ResolveResult childResult = node.getExpression().acceptVisitor(this, data); final ResolveResult typeResult = resolveType(node.getType()); if (typeResult == null) { return childResult; } final TypeReference resolvedType = typeResult.getType(); if (resolvedType != null) { if (resolvedType.isPrimitive() && childResult != null && childResult.isCompileTimeConstant()) { return new PrimitiveResolveResult( resolvedType, JavaPrimitiveCast.cast(resolvedType.getSimpleType(), childResult.getConstantValue()) ); } return new ResolveResult(resolvedType); } return typeResult; }
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 ResolveResult visitCastExpression(final CastExpression node, final Void data) { final ResolveResult childResult = node.getExpression().acceptVisitor(this, data); final ResolveResult typeResult = resolveType(node.getType()); if (typeResult == null) { return childResult; } final TypeReference resolvedType = typeResult.getType(); if (resolvedType != null) { if (resolvedType.isPrimitive() && childResult != null && childResult.isCompileTimeConstant()) { return new PrimitiveResolveResult( resolvedType, JavaPrimitiveCast.cast(resolvedType.getSimpleType(), childResult.getConstantValue()) ); } return new ResolveResult(resolvedType); } return typeResult; }
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; } }
super.visitCastExpression(node, data); final AstType castType = node.getType(); final TypeReference typeReference = castType.toTypeReference();
protected void processPossibleTypeCast(final Expression rightExpression, @Nullable final TypeReference leftType) { if (leftType == null) { return; } final Expression r = removeParentheses(rightExpression); if (r instanceof CastExpression) { final AstType castAstType = ((CastExpression) r).getType(); final TypeReference castType = castAstType != null ? castAstType.toTypeReference() : null; final Expression castOperand = ((CastExpression) r).getExpression(); if (castOperand != null && !castOperand.isNull() && castType != null) { final TypeReference operandType = getType(castOperand); if (operandType != null) { if (MetadataHelper.isAssignableFrom(leftType, operandType, false)) { addToResults((CastExpression) r, false); } else { final TypeReference unboxedCastType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(castType); final TypeReference unboxedLeftType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(leftType); if (castOperand instanceof PrimitiveExpression && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedCastType, ((PrimitiveExpression) castOperand).getValue()) && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedLeftType, ((PrimitiveExpression) castOperand).getValue())) { addToResults((CastExpression) r, true); } } } } } }
protected void processPossibleTypeCast(final Expression rightExpression, @Nullable final TypeReference leftType) { if (leftType == null) { return; } final Expression r = removeParentheses(rightExpression); if (r instanceof CastExpression) { final AstType castAstType = ((CastExpression) r).getType(); final TypeReference castType = castAstType != null ? castAstType.toTypeReference() : null; final Expression castOperand = ((CastExpression) r).getExpression(); if (castOperand != null && !castOperand.isNull() && castType != null) { final TypeReference operandType = getType(castOperand); if (operandType != null) { if (MetadataHelper.isAssignableFrom(leftType, operandType, false)) { addToResults((CastExpression) r, false); } else { final TypeReference unboxedCastType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(castType); final TypeReference unboxedLeftType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(leftType); if (castOperand instanceof PrimitiveExpression && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedCastType, ((PrimitiveExpression) castOperand).getValue()) && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedLeftType, ((PrimitiveExpression) castOperand).getValue())) { addToResults((CastExpression) r, true); } } } } } }