/** Attempts to determine if the method is a getter. */ private static boolean isGetter(ASTMethodDeclaration node, Map<String, String> fieldNames) { if (node.getFirstDescendantOfType(ASTFormalParameters.class).getParameterCount() != 0 || node.getFirstDescendantOfType(ASTResultType.class).isVoid()) { return false; } if (node.getName().startsWith("get")) { return containsIgnoreCase(fieldNames.keySet(), node.getName().substring(3)); } else if (node.getName().startsWith("is")) { return containsIgnoreCase(fieldNames.keySet(), node.getName().substring(2)); } return fieldNames.containsKey(node.getName()); }
/** Attempts to determine if the method is a setter. */ private static boolean isSetter(ASTMethodDeclaration node, Map<String, String> fieldNames) { if (node.getFirstDescendantOfType(ASTFormalParameters.class).getParameterCount() != 1 || !node.getFirstDescendantOfType(ASTResultType.class).isVoid()) { return false; } if (node.getName().startsWith("set")) { return containsIgnoreCase(fieldNames.keySet(), node.getName().substring(3)); } return fieldNames.containsKey(node.getName()); }
for (ASTMethodDeclaration method : methods) { if (method.getName().equals("getInstance")) { count++; if (count > 1) {
@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); }
/** Attempts to determine if the method is a getter. */ private static boolean isGetter(ASTMethodDeclaration node, Map<String, String> fieldNames) { if (node.getFirstDescendantOfType(ASTFormalParameters.class).getParameterCount() != 0 || node.getFirstDescendantOfType(ASTResultType.class).isVoid()) { return false; } if (node.getName().startsWith("get")) { return containsIgnoreCase(fieldNames.keySet(), node.getName().substring(3)); } else if (node.getName().startsWith("is")) { return containsIgnoreCase(fieldNames.keySet(), node.getName().substring(2)); } return fieldNames.containsKey(node.getName()); }
/** Attempts to determine if the method is a setter. */ private static boolean isSetter(ASTMethodDeclaration node, Map<String, String> fieldNames) { if (node.getFirstDescendantOfType(ASTFormalParameters.class).getParameterCount() != 1 || !node.getFirstDescendantOfType(ASTResultType.class).isVoid()) { return false; } if (node.getName().startsWith("set")) { return containsIgnoreCase(fieldNames.keySet(), node.getName().substring(3)); } return fieldNames.containsKey(node.getName()); }
for (ASTMethodDeclaration method : methods) { if (method.getName().equals("getInstance")) { count++; if (count > 1) {
@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); }
I18nResources.getMessage("java.other.MethodTooLongRule.violation.msg", node.getName()));