private boolean isMainMethod(ASTAnyTypeBodyDeclaration bodyDeclaration) { if (DeclarationKind.METHOD != bodyDeclaration.getKind()) { return false; } ASTMethodDeclaration decl = (ASTMethodDeclaration) bodyDeclaration.getDeclarationNode(); return decl.isStatic() && "main".equals(decl.getMethodName()) && decl.getResultType().isVoid() && decl.getFormalParameters().getParameterCount() == 1 && String[].class.equals(decl.getFormalParameters().iterator().next().getType()); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { if (currentLookup.peek() == null) { return super.visit(node, data); } for (ASTAnnotation annot : node.getDeclaredAnnotations()) { if (Override.class.equals(annot.getType())) { // we assume the compiler has already checked it, so it's correct return super.visit(node, data); } } try { boolean overridden = currentLookup.peek().isOverridden(node.getName(), node.getFormalParameters()); if (overridden) { addViolation(data, node, new Object[]{node.getQualifiedName().getOperation()}); } } catch (NoSuchMethodException e) { // may happen in the body of an enum constant, // because the method lookup used is the one of // the parent class. LOG.warning("MissingOverride encountered unexpected method " + node.getMethodName()); // throw new RuntimeException(e); // uncomment when enum constants are handled by typeres } return super.visit(node, data); }
private boolean isMainMethod(ASTAnyTypeBodyDeclaration bodyDeclaration) { if (DeclarationKind.METHOD != bodyDeclaration.getKind()) { return false; } ASTMethodDeclaration decl = (ASTMethodDeclaration) bodyDeclaration.getDeclarationNode(); return decl.isStatic() && "main".equals(decl.getMethodName()) && decl.getResultType().isVoid() && decl.getFormalParameters().getParameterCount() == 1 && String[].class.equals(decl.getFormalParameters().iterator().next().getType()); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { if (currentLookup.peek() == null) { return super.visit(node, data); } for (ASTAnnotation annot : node.getDeclaredAnnotations()) { if (Override.class.equals(annot.getType())) { // we assume the compiler has already checked it, so it's correct return super.visit(node, data); } } try { boolean overridden = currentLookup.peek().isOverridden(node.getName(), node.getFormalParameters()); if (overridden) { addViolation(data, node, new Object[]{node.getQualifiedName().getOperation()}); } } catch (NoSuchMethodException e) { // may happen in the body of an enum constant, // because the method lookup used is the one of // the parent class. LOG.warning("MissingOverride encountered unexpected method " + node.getMethodName()); // throw new RuntimeException(e); // uncomment when enum constants are handled by typeres } return super.visit(node, data); }