blob: 2175c9af39df5a2fc13b0fae1318922eddc25654 (
plain)
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
|
package com.github.javaparser.ast.validator;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.VariableDeclarationExpr;
import com.github.javaparser.ast.stmt.TryStmt;
import com.github.javaparser.ast.validator.chunks.ModifierValidator;
import com.github.javaparser.ast.validator.chunks.UnderscoreKeywordValidator;
/**
* This validator validates according to Java 9 syntax rules.
*/
public class Java9Validator extends Java8Validator {
protected final Validator underscoreKeywordValidator = new UnderscoreKeywordValidator();
protected final Validator modifiers = new ModifierValidator(true, true, true);
protected final SingleNodeTypeValidator<TryStmt> tryWithResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> {
if (n.getCatchClauses().isEmpty()
&& n.getResources().isEmpty()
&& !n.getFinallyBlock().isPresent()) {
reporter.report(n, "Try has no finally, no catch, and no resources.");
}
});
public Java9Validator() {
super();
add(underscoreKeywordValidator);
remove(noModules);
replace(modifiersWithoutPrivateInterfaceMethods, modifiers);
replace(tryWithLimitedResources, tryWithResources);
}
}
|