Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all movable validations from grammar to framework
- Loading branch information
Showing
5 changed files
with
111 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
javaparser-core/src/main/java/com/github/javaparser/ast/validator/BaseJavaValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.github.javaparser.ast.validator; | ||
|
||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; | ||
import com.github.javaparser.ast.body.InitializerDeclaration; | ||
import com.github.javaparser.ast.body.MethodDeclaration; | ||
import com.github.javaparser.ast.stmt.TryStmt; | ||
|
||
/** | ||
* Contains validations that are valid for every Java version. | ||
* Used by default by the static JavaParser methods. | ||
*/ | ||
public class BaseJavaValidator extends Validators { | ||
public BaseJavaValidator() { | ||
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)); | ||
} | ||
} | ||
}, | ||
new VisitorValidator() { | ||
@Override | ||
public void visit(ClassOrInterfaceDeclaration n, ProblemReporter reporter) { | ||
if (n.isInterface()) { | ||
new VisitorValidator() { | ||
public void visit(InitializerDeclaration n, ProblemReporter reporter1) { | ||
reporter.report("An interface cannot have initializers", n); | ||
} | ||
}.validate(n, reporter); | ||
} | ||
} | ||
}, | ||
new VisitorValidator() { | ||
@Override | ||
public void visit(ClassOrInterfaceDeclaration n, ProblemReporter reporter) { | ||
if (n.isInterface()) { | ||
new VisitorValidator() { | ||
public void visit(MethodDeclaration n, ProblemReporter reporter1) { | ||
if (n.isDefault() && !n.getBody().isPresent()) { | ||
reporter.report("\"default\" methods must have a body", n); | ||
} | ||
} | ||
}.validate(n, reporter); | ||
} | ||
} | ||
}, | ||
new VisitorValidator() { | ||
@Override | ||
public void visit(ClassOrInterfaceDeclaration n, ProblemReporter reporter) { | ||
if (!n.isInterface()) { | ||
new VisitorValidator() { | ||
public void visit(MethodDeclaration n, ProblemReporter reporter1) { | ||
if (n.isDefault()) { | ||
reporter.report("A class cannot have default members", n); | ||
} | ||
} | ||
}.validate(n, reporter); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
javaparser-core/src/main/java/com/github/javaparser/ast/validator/DefaultValidator.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters