@Override public Object visit(ASTAllocationExpression node, Object data) { if (!inPrimaryExpressionContext || !(node.jjtGetChild(0) instanceof ASTClassOrInterfaceType)) { return super.visit(node, data); } if (!PRIMITIVE_WRAPPERS.contains(node.jjtGetChild(0).getImage())) { return super.visit(node, data); } usingPrimitiveWrapperAllocation = true; return super.visit(node, data); }
/** * Returns true if this expression defines a body, * which is compiled to an anonymous class. If this * method returns false, then {@link #getQualifiedName()} * returns {@code null}. */ public boolean isAnonymousClass() { if (jjtGetNumChildren() > 1) { // check the last child return jjtGetChild(jjtGetNumChildren() - 1) instanceof ASTClassOrInterfaceBody; } return false; }
@Override public Object visit(ASTAllocationExpression node, Object data) { if (!(node.jjtGetChild(0) instanceof ASTClassOrInterfaceType)) { return data; if (!TypeHelper.isA((ASTClassOrInterfaceType) node.jjtGetChild(0), String.class)) { return data;
@Override public Object visit(final ASTAllocationExpression node, final Object data) { if (node.jjtGetChild(0) instanceof ASTClassOrInterfaceType) { // Ignore primitives final ASTClassOrInterfaceType type = (ASTClassOrInterfaceType) node.jjtGetChild(0); final List<ASTConstructorDeclaration> constructors = privateConstructors.get(type.getImage());
@Override public Object visit(ASTAllocationExpression node, Object data) { super.visit(node, data); final ASTArrayDimsAndInits dims = node.getFirstChildOfType(ASTArrayDimsAndInits.class); if (dims != null) { final JavaTypeDefinition elementType = ((TypeNode) node.jjtGetChild(0)).getTypeDefinition(); if (elementType != null) { node.setTypeDefinition(elementType.withDimensions(dims.getArrayDepth())); } } else { rollupTypeUnary(node); } return data; }
@Override public Object visit(ASTAllocationExpression node, Object data) { Node type = node.jjtGetChild(0); if (!(type instanceof ASTClassOrInterfaceType)) { return super.visit(node, data); } boolean jdk15 = ((RuleContext) data).getLanguageVersion() .compareTo(LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.5")) >= 0; if ((TypeHelper.isA((ASTClassOrInterfaceType) type, BigInteger.class) || jdk15 && TypeHelper.isA((ASTClassOrInterfaceType) type, BigDecimal.class)) && !node.hasDescendantOfType(ASTArrayDimsAndInits.class)) { ASTArguments args = node.getFirstChildOfType(ASTArguments.class); if (args.getArgumentCount() == 1) { ASTLiteral literal = node.getFirstDescendantOfType(ASTLiteral.class); if (literal == null || literal.jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent() != args) { return super.visit(node, data); } String img = literal.getImage(); if (literal.isStringLiteral()) { img = img.substring(1, img.length() - 1); } if ("0".equals(img) || "1".equals(img) || jdk15 && "10".equals(img)) { addViolation(data, node); return data; } } } return super.visit(node, data); }
@Override public Object visit(ASTAllocationExpression node, Object data) { if (!inPrimaryExpressionContext || !(node.jjtGetChild(0) instanceof ASTClassOrInterfaceType)) { return super.visit(node, data); } if (!PRIMITIVE_WRAPPERS.contains(node.jjtGetChild(0).getImage())) { return super.visit(node, data); } usingPrimitiveWrapperAllocation = true; return super.visit(node, data); }
@Override public Object visit(ASTAllocationExpression node, Object data) { super.visit(node, data); boolean notRollupTypeUnary = node.jjtGetNumChildren() >= NumberConstants.INTEGER_SIZE_OR_LENGTH_2 && node.jjtGetChild(1) instanceof ASTArrayDimsAndInits || node.jjtGetNumChildren() >= NumberConstants.INTEGER_SIZE_OR_LENGTH_3 && node.jjtGetChild(NumberConstants.INDEX_2) instanceof ASTArrayDimsAndInits; if (!notRollupTypeUnary) { rollupTypeUnary(node); } return data; }
/** * Returns true if this expression defines a body, * which is compiled to an anonymous class. If this * method returns false, then {@link #getQualifiedName()} * returns {@code null}. */ public boolean isAnonymousClass() { if (jjtGetNumChildren() > 1) { // check the last child return jjtGetChild(jjtGetNumChildren() - 1) instanceof ASTClassOrInterfaceBody; } return false; }
@Override public Object visit(ASTAllocationExpression node, Object data) { if (!(node.jjtGetChild(0) instanceof ASTClassOrInterfaceType)) { return data; if (!TypeHelper.isA((ASTClassOrInterfaceType) node.jjtGetChild(0), String.class)) { return data;
@Override public Object visit(final ASTAllocationExpression node, final Object data) { if (node.jjtGetChild(0) instanceof ASTClassOrInterfaceType) { // Ignore primitives final ASTClassOrInterfaceType type = (ASTClassOrInterfaceType) node.jjtGetChild(0); final List<ASTConstructorDeclaration> constructors = privateConstructors.get(type.getImage());
@Override public Object visit(ASTAllocationExpression node, Object data) { super.visit(node, data); final ASTArrayDimsAndInits dims = node.getFirstChildOfType(ASTArrayDimsAndInits.class); if (dims != null) { final JavaTypeDefinition elementType = ((TypeNode) node.jjtGetChild(0)).getTypeDefinition(); if (elementType != null) { node.setTypeDefinition(elementType.withDimensions(dims.getArrayDepth())); } } else { rollupTypeUnary(node); } return data; }
@Override public Object visit(ASTAllocationExpression node, Object data) { Node type = node.jjtGetChild(0); if (!(type instanceof ASTClassOrInterfaceType)) { return super.visit(node, data); } boolean jdk15 = ((RuleContext) data).getLanguageVersion() .compareTo(LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.5")) >= 0; if ((TypeHelper.isA((ASTClassOrInterfaceType) type, BigInteger.class) || jdk15 && TypeHelper.isA((ASTClassOrInterfaceType) type, BigDecimal.class)) && !node.hasDescendantOfType(ASTArrayDimsAndInits.class)) { ASTArguments args = node.getFirstChildOfType(ASTArguments.class); if (args.getArgumentCount() == 1) { ASTLiteral literal = node.getFirstDescendantOfType(ASTLiteral.class); if (literal == null || literal.jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent() != args) { return super.visit(node, data); } String img = literal.getImage(); if (literal.isStringLiteral()) { img = img.substring(1, img.length() - 1); } if ("0".equals(img) || "1".equals(img) || jdk15 && "10".equals(img)) { addViolation(data, node); return data; } } } return super.visit(node, data); }