private Map<String, VariableNameDeclaration> getVariables(ASTMethodDeclaration method) { Map<String, VariableNameDeclaration> variables = new HashMap<>(); for (VariableNameDeclaration vnd : method.getScope().getDeclarations(VariableNameDeclaration.class).keySet()) { variables.put(vnd.getName(), vnd); } return variables; }
private static boolean isGetterOrSetter(ASTMethodDeclaration node) { ClassScope scope = node.getScope().getEnclosingScope(ClassScope.class); // fields names mapped to their types Map<String, String> fieldNames = new HashMap<>(); for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> decl : scope.getVariableDeclarations().entrySet()) { ASTFieldDeclaration field = decl.getKey() .getNode() .getFirstParentOfType(ASTFieldDeclaration.class); Matcher matcher = FIELD_NAME_PATTERN.matcher(field.getVariableName()); String varName = matcher.find() ? matcher.group(1) : field.getVariableName(); fieldNames.put(varName, field.getFirstChildOfType(ASTType.class).getTypeImage()); } return isGetter(node, fieldNames) || isSetter(node, fieldNames); }
@Override public Object visit(ASTMethodDeclaration meth, Object data) { if (meth.isNative() || meth.isAbstract()) { return data; } this.lookForViolation(meth.getScope(), data); return super.visit(meth, data); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { createMethodScope(node); ASTMethodDeclarator md = node.getFirstChildOfType(ASTMethodDeclarator.class); node.getScope().getEnclosingScope(ClassScope.class).addDeclaration(new MethodNameDeclaration(md)); cont(node); return data; }
@Override public Object visit(ASTMethodDeclaration method, Object data) { if (isJUnitMethod(method, data)) { if (!isExpectAnnotated(method.jjtGetParent())) { Map<String, VariableNameDeclaration> variables = getVariables(method); Scope classScope = method.getScope().getParent(); Map<String, List<NameOccurrence>> expectables = getRuleAnnotatedExpectedExceptions(classScope); if (!containsExpectOrAssert(method.getBlock(), expectables, variables)) { addViolation(data, method); } } } return data; }
private Map<String, VariableNameDeclaration> getVariables(ASTMethodDeclaration method) { Map<String, VariableNameDeclaration> variables = new HashMap<>(); for (VariableNameDeclaration vnd : method.getScope().getDeclarations(VariableNameDeclaration.class).keySet()) { variables.put(vnd.getName(), vnd); } return variables; }
private static boolean isGetterOrSetter(ASTMethodDeclaration node) { ClassScope scope = node.getScope().getEnclosingScope(ClassScope.class); // fields names mapped to their types Map<String, String> fieldNames = new HashMap<>(); for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> decl : scope.getVariableDeclarations().entrySet()) { ASTFieldDeclaration field = decl.getKey() .getNode() .getFirstParentOfType(ASTFieldDeclaration.class); Matcher matcher = FIELD_NAME_PATTERN.matcher(field.getVariableName()); String varName = matcher.find() ? matcher.group(1) : field.getVariableName(); fieldNames.put(varName, field.getFirstChildOfType(ASTType.class).getTypeImage()); } return isGetter(node, fieldNames) || isSetter(node, fieldNames); }
@Override public Object visit(ASTMethodDeclaration meth, Object data) { if (meth.isNative() || meth.isAbstract()) { return data; } this.lookForViolation(meth.getScope(), data); return super.visit(meth, data); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { createMethodScope(node); ASTMethodDeclarator md = node.getFirstChildOfType(ASTMethodDeclarator.class); node.getScope().getEnclosingScope(ClassScope.class).addDeclaration(new MethodNameDeclaration(md)); cont(node); return data; }
@Override public Object visit(ASTMethodDeclaration method, Object data) { if (isJUnitMethod(method, data)) { if (!isExpectAnnotated(method.jjtGetParent())) { Map<String, VariableNameDeclaration> variables = getVariables(method); Scope classScope = method.getScope().getParent(); Map<String, List<NameOccurrence>> expectables = getRuleAnnotatedExpectedExceptions(classScope); if (!containsExpectOrAssert(method.getBlock(), expectables, variables)) { addViolation(data, method); } } } return data; }