@NotNull protected List<TypeReference> getTypes(final AstNodeCollection<? extends AstNode> nodes) { if (nodes == null || nodes.isEmpty()) { return Collections.emptyList(); } final List<TypeReference> types = new ArrayList<>(); for (final AstNode node : nodes) { final TypeReference nodeType = getType(node); if (nodeType == null) { return Collections.emptyList(); } types.add(nodeType); } return types; }
@NotNull protected List<TypeReference> getTypes(final AstNodeCollection<? extends AstNode> nodes) { if (nodes == null || nodes.isEmpty()) { return Collections.emptyList(); } final List<TypeReference> types = new ArrayList<>(); for (final AstNode node : nodes) { final TypeReference nodeType = getType(node); if (nodeType == null) { return Collections.emptyList(); } types.add(nodeType); } return types; }
@NotNull protected List<TypeReference> getTypes(final AstNodeCollection<? extends AstNode> nodes) { if (nodes == null || nodes.isEmpty()) { return Collections.emptyList(); } final List<TypeReference> types = new ArrayList<>(); for (final AstNode node : nodes) { final TypeReference nodeType = getType(node); if (nodeType == null) { return Collections.emptyList(); } types.add(nodeType); } return types; }
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); } } }
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); } } }
@Override public Void visitBinaryOperatorExpression(final BinaryOperatorExpression node, final Void data) { final TypeReference leftType = getType(node.getLeft()); final TypeReference rightType = getType(node.getRight()); processBinaryExpressionOperand(node.getLeft(), rightType, node.getOperator()); processBinaryExpressionOperand(node.getRight(), leftType, node.getOperator()); return super.visitBinaryOperatorExpression(node, data); }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final TypeReference leftType = getType(node.getReturnType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitFieldDeclaration(node, data); }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final TypeReference leftType = getType(node.getReturnType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitFieldDeclaration(node, data); }
@Override public Void visitVariableDeclaration(final VariableDeclarationStatement node, final Void data) { final TypeReference leftType = getType(node.getType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitVariableDeclaration(node, data); }
@Override public Void visitVariableDeclaration(final VariableDeclarationStatement node, final Void data) { final TypeReference leftType = getType(node.getType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitVariableDeclaration(node, data); }
@Override public Void visitBinaryOperatorExpression(final BinaryOperatorExpression node, final Void data) { final TypeReference leftType = getType(node.getLeft()); final TypeReference rightType = getType(node.getRight()); processBinaryExpressionOperand(node.getLeft(), rightType, node.getOperator()); processBinaryExpressionOperand(node.getRight(), leftType, node.getOperator()); return super.visitBinaryOperatorExpression(node, data); }
@Override public Void visitReturnStatement(final ReturnStatement node, final Void data) { final MethodDeclaration methodDeclaration = firstOrDefault(node.getAncestors(MethodDeclaration.class)); if (methodDeclaration != null && !methodDeclaration.isNull()) { final TypeReference returnType = getType(methodDeclaration.getReturnType()); final Expression returnValue = node.getExpression(); if (returnType != null && returnValue != null && !returnValue.isNull()) { processPossibleTypeCast(returnValue, returnType); } } return super.visitReturnStatement(node, data); }
@Override public Void visitVariableDeclaration(final VariableDeclarationStatement node, final Void data) { final TypeReference leftType = getType(node.getType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitVariableDeclaration(node, data); }
@Override public Void visitReturnStatement(final ReturnStatement node, final Void data) { final MethodDeclaration methodDeclaration = firstOrDefault(node.getAncestors(MethodDeclaration.class)); if (methodDeclaration != null && !methodDeclaration.isNull()) { final TypeReference returnType = getType(methodDeclaration.getReturnType()); final Expression returnValue = node.getExpression(); if (returnType != null && !returnValue.isNull()) { processPossibleTypeCast(returnValue, returnType); } } return super.visitReturnStatement(node, data); }
@Override public Void visitReturnStatement(final ReturnStatement node, final Void data) { final MethodDeclaration methodDeclaration = firstOrDefault(node.getAncestors(MethodDeclaration.class)); if (methodDeclaration != null && !methodDeclaration.isNull()) { final TypeReference returnType = getType(methodDeclaration.getReturnType()); final Expression returnValue = node.getExpression(); if (returnType != null && returnValue != null && !returnValue.isNull()) { processPossibleTypeCast(returnValue, returnType); } } return super.visitReturnStatement(node, data); }
@Override public Void visitAssignmentExpression(final AssignmentExpression node, final Void data) { processPossibleTypeCast(node.getRight(), getType(node.getLeft())); return super.visitAssignmentExpression(node, data); }
@Override public Void visitAssignmentExpression(final AssignmentExpression node, final Void data) { processPossibleTypeCast(node.getRight(), getType(node.getLeft())); return super.visitAssignmentExpression(node, data); }
@Override public Void visitBinaryOperatorExpression(final BinaryOperatorExpression node, final Void data) { final BinaryOperatorType operator = node.getOperator(); final TypeReference resultType = operator.isRelational() ? BuiltinTypes.Boolean : getType(node); processBinaryExpressionOperand(node.getRight(), node.getLeft(), operator, resultType); processBinaryExpressionOperand(node.getLeft(), node.getRight(), operator, resultType); return super.visitBinaryOperatorExpression(node, data); }
@Override public Void visitAssignmentExpression(final AssignmentExpression node, final Void data) { processPossibleTypeCast(node.getRight(), getType(node.getLeft())); return super.visitAssignmentExpression(node, data); }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final TypeReference leftType = getType(node.getReturnType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitFieldDeclaration(node, data); }