@Override public void visitNode(AstNode node) { MethodHelper methodHelper = new MethodHelper(node); if ("equals".equalsIgnoreCase(methodHelper.getName().getTokenOriginalValue()) && !hasSingleObjectParameter(methodHelper)) { getContext() .createLineViolation( this, "Either override Object.equals(Object), or totally rename the method to prevent any confusion.", methodHelper.getName()); } }
private static boolean hasSingleObjectParameter(MethodHelper methodHelper) { List<AstNode> parameters = methodHelper.getParameters(); if (parameters.size() != 1) { return false; } return isObjectType(parameters.get(0).getFirstChild(JavaGrammar.TYPE)); }
@Override public void init() { MethodHelper.subscribe(this); }