Home | History | Annotate | Download | only in validator
      1 package com.github.javaparser.ast.validator;
      2 
      3 import com.github.javaparser.ast.expr.Expression;
      4 import com.github.javaparser.ast.expr.VariableDeclarationExpr;
      5 import com.github.javaparser.ast.stmt.TryStmt;
      6 import com.github.javaparser.ast.validator.chunks.ModifierValidator;
      7 import com.github.javaparser.ast.validator.chunks.UnderscoreKeywordValidator;
      8 
      9 /**
     10  * This validator validates according to Java 9 syntax rules.
     11  */
     12 public class Java9Validator extends Java8Validator {
     13     protected final Validator underscoreKeywordValidator = new UnderscoreKeywordValidator();
     14     protected final Validator modifiers = new ModifierValidator(true, true, true);
     15     protected final SingleNodeTypeValidator<TryStmt> tryWithResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> {
     16         if (n.getCatchClauses().isEmpty()
     17                 && n.getResources().isEmpty()
     18                 && !n.getFinallyBlock().isPresent()) {
     19             reporter.report(n, "Try has no finally, no catch, and no resources.");
     20         }
     21     });
     22 
     23     public Java9Validator() {
     24         super();
     25         add(underscoreKeywordValidator);
     26         remove(noModules);
     27         replace(modifiersWithoutPrivateInterfaceMethods, modifiers);
     28         replace(tryWithLimitedResources, tryWithResources);
     29     }
     30 }
     31