/
DefaultValidator.java
40 lines (38 loc) · 1.7 KB
/
DefaultValidator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.github.javaparser.ast.validator;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.stmt.TryStmt;
/**
* The validator that is used by default by the static JavaParser methods.
*/
public class DefaultValidator extends Validators {
public DefaultValidator() {
super(
new VisitorValidator() {
@Override
public void visit(TryStmt n, ProblemReporter reporter) {
if (n.getCatchClauses().isEmpty()
&& n.getResources().isEmpty()
&& !n.getFinallyBlock().isPresent()) {
reporter.report("Try has no finally, no catch, and no resources", n);
}
}
},
new VisitorValidator() {
@Override
public void visit(ClassOrInterfaceDeclaration n, ProblemReporter reporter) {
if (!n.isInterface() && n.getExtendedTypes().size() > 1) {
reporter.report("A class cannot extend more than one other class", n.getExtendedTypes(1));
}
}
},
new VisitorValidator() {
@Override
public void visit(ClassOrInterfaceDeclaration n, ProblemReporter reporter) {
if (n.isInterface() && !n.getImplementedTypes().isEmpty()) {
reporter.report("An interface cannot implement other interfaces", n.getImplementedTypes(0));
}
}
}
);
}
}