private boolean anyIsString(final List<Expression> expressions) { final JavaResolver resolver = new JavaResolver(context); for (int i = 0; i < expressions.size(); i++) { final ResolveResult result = resolver.apply(expressions.get(i)); if (result != null && result.getType() != null && CommonTypeReferences.String.isEquivalentTo(result.getType())) { return true; } } return false; } }
private boolean anyIsString(final List<Expression> expressions) { final JavaResolver resolver = new JavaResolver(context); for (int i = 0; i < expressions.size(); i++) { final ResolveResult result = resolver.apply(expressions.get(i)); if (result != null && result.getType() != null && CommonTypeReferences.String.isEquivalentTo(result.getType())) { return true; } } return false; } }
private boolean anyIsString(final List<Expression> expressions) { final JavaResolver resolver = new JavaResolver(context); for (int i = 0; i < expressions.size(); i++) { final ResolveResult result = resolver.apply(expressions.get(i)); if (result != null && result.getType() != null && CommonTypeReferences.String.isEquivalentTo(result.getType())) { return true; } } return false; } }
@Override public Void visitConditionalExpression(final ConditionalExpression node, final Void data) { super.visitConditionalExpression(node, data); final Expression condition = node.getCondition(); final ResolveResult conditionResult = _resolver.apply(condition); if (conditionResult != null && TypeUtilities.isArithmetic(conditionResult.getType())) { convertNumericToBoolean(condition, conditionResult.getType()); } return null; }
@Override public Void visitIfElseStatement(final IfElseStatement node, final Void data) { super.visitIfElseStatement(node, data); final Expression condition = node.getCondition(); final ResolveResult conditionResult = _resolver.apply(condition); if (conditionResult != null && TypeUtilities.isArithmetic(conditionResult.getType())) { convertNumericToBoolean(condition, conditionResult.getType()); } return null; }
@Override public Void visitConditionalExpression(final ConditionalExpression node, final Void data) { super.visitConditionalExpression(node, data); final Expression condition = node.getCondition(); final ResolveResult conditionResult = _resolver.apply(condition); if (conditionResult != null && TypeUtilities.isArithmetic(conditionResult.getType())) { convertNumericToBoolean(condition, conditionResult.getType()); } return null; }
@Override public Void visitIfElseStatement(final IfElseStatement node, final Void data) { super.visitIfElseStatement(node, data); final Expression condition = node.getCondition(); final ResolveResult conditionResult = _resolver.apply(condition); if (conditionResult != null && TypeUtilities.isArithmetic(conditionResult.getType())) { convertNumericToBoolean(condition, conditionResult.getType()); } return null; }
@Override public Void visitIfElseStatement(final IfElseStatement node, final Void data) { super.visitIfElseStatement(node, data); final Expression condition = node.getCondition(); final ResolveResult conditionResult = _resolver.apply(condition); if (conditionResult != null && TypeUtilities.isArithmetic(conditionResult.getType())) { convertNumericToBoolean(condition, conditionResult.getType()); } return null; }
@Override public Void visitConditionalExpression(final ConditionalExpression node, final Void data) { super.visitConditionalExpression(node, data); final Expression condition = node.getCondition(); final ResolveResult conditionResult = _resolver.apply(condition); if (conditionResult != null && TypeUtilities.isArithmetic(conditionResult.getType())) { convertNumericToBoolean(condition, conditionResult.getType()); } return null; }
private void removeUnboxingForCondition( final InvocationExpression e, final MemberReferenceExpression target, final ConditionalExpression parent) { final boolean leftSide = parent.getTrueExpression().isAncestorOf(e); final Expression otherSide = leftSide ? parent.getFalseExpression() : parent.getTrueExpression(); final ResolveResult otherResult = _resolver.apply(otherSide); if (otherResult == null || otherResult.getType() == null || !otherResult.getType().isPrimitive()) { return; } performUnboxingRemoval(e, target); }
private void removeUnboxingForCondition( final InvocationExpression e, final MemberReferenceExpression target, final ConditionalExpression parent) { final boolean leftSide = parent.getTrueExpression().isAncestorOf(e); final Expression otherSide = leftSide ? parent.getFalseExpression() : parent.getTrueExpression(); final ResolveResult otherResult = _resolver.apply(otherSide); if (otherResult == null || otherResult.getType() == null || !otherResult.getType().isPrimitive()) { return; } performUnboxingRemoval(e, target); }
@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) { 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; }
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; } }
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; } }
final ResolveResult rr = _resolver.apply(operand);
@Override public Void visitUnaryOperatorExpression(final UnaryOperatorExpression node, final Void data) { super.visitUnaryOperatorExpression(node, data); switch (node.getOperator()) { case NOT: { final Expression operand = node.getExpression(); final ResolveResult result = _resolver.apply(operand); if (result != null && result.getType() != null && !TypeUtilities.isBoolean(result.getType()) && MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()).getSimpleType().isNumeric()) { final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()); operand.replaceWith( new Function<AstNode, AstNode>() { @Override public AstNode apply(final AstNode input) { return new BinaryOperatorExpression( operand, BinaryOperatorType.INEQUALITY, new PrimitiveExpression(Expression.MYSTERY_OFFSET, JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0)) ); } } ); } break; } } return null; }
@Override @SuppressWarnings("ConstantConditions") public Void visitSuperReferenceExpression(final SuperReferenceExpression node, final Void data) { super.visitSuperReferenceExpression(node, data); if (node.getParent() instanceof InvocationExpression) { final InvocationExpression parent = (InvocationExpression) node.getParent(); if (!parent.getArguments().isEmpty()) { final Expression firstArgument = parent.getArguments().firstOrNullObject(); final ResolveResult resolvedArgument = _resolver.apply(firstArgument); if (resolvedArgument != null) { final TypeReference superType = node.getUserData(Keys.TYPE_REFERENCE); final TypeReference argumentType = resolvedArgument.getType(); if (superType != null && argumentType != null) { final TypeDefinition resolvedSuperType = superType.resolve(); if (resolvedSuperType != null && resolvedSuperType.isInnerClass() && !resolvedSuperType.isStatic() && isEnclosedBy(context.getCurrentType(), argumentType)) { firstArgument.remove(); if (!(firstArgument instanceof ThisReferenceExpression)) { node.setTarget(firstArgument); } } } } } } return null; }
@Override @SuppressWarnings("ConstantConditions") public Void visitSuperReferenceExpression(final SuperReferenceExpression node, final Void data) { super.visitSuperReferenceExpression(node, data); if (node.getParent() instanceof InvocationExpression) { final InvocationExpression parent = (InvocationExpression) node.getParent(); if (!parent.getArguments().isEmpty()) { final Expression firstArgument = parent.getArguments().firstOrNullObject(); final ResolveResult resolvedArgument = _resolver.apply(firstArgument); if (resolvedArgument != null) { final TypeReference superType = node.getUserData(Keys.TYPE_REFERENCE); final TypeReference argumentType = resolvedArgument.getType(); if (superType != null && argumentType != null) { final TypeDefinition resolvedSuperType = superType.resolve(); if (resolvedSuperType != null && resolvedSuperType.isInnerClass() && !resolvedSuperType.isStatic() && isEnclosedBy(context.getCurrentType(), argumentType)) { firstArgument.remove(); if (!(firstArgument instanceof ThisReferenceExpression)) { node.setTarget(firstArgument); } } } } } } return null; }