Skip to content

Commit

Permalink
[ggj][ast][engx] fix: validate non-null elements for MethodDefinition (
Browse files Browse the repository at this point in the history
…#463)

* fix: swap assertEquals args in JavaWriterVisitorTest to match (expected, actusl) order

* fix: swap assertEquals args in ImportWriterVisitorTest to match (expected, actusl) order

* fix: add node validator to refactor/centralize null element checks

* fix: validate non-null elements for IfStatement

* fix: validate non-null elements for AnonymousClassExpr

* fix: validate non-null elements for BlockStatement

* fix: validate non-null elements for ClassDefinition

* fix: validate non-null elements for ConcreteReference

* fix: validate non-null elements for ForStatement

* fix: validate non-null elements for GeneralForStatement

* fix: validate non-null elements for MethodDefinition
  • Loading branch information
miraleung authored Nov 7, 2020
1 parent 018e6b1 commit e6c9726
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ public Builder setReturnExpr(Expr expr) {
abstract Builder setMethodIdentifier(IdentifierNode methodIdentifier);

// Private accessors.

abstract String name();

abstract ImmutableList<CommentStatement> headerCommentStatements();

abstract ImmutableList<AnnotationNode> annotations();

abstract ImmutableList<TypeNode> throwsExceptions();

abstract TypeNode returnType();

abstract boolean isOverride();
Expand All @@ -195,6 +198,8 @@ public Builder setReturnExpr(Expr expr) {
abstract ImmutableList<String> returnTemplateNames();

public MethodDefinition build() {
performNullChecks();

// Handle templates.
setTemplateIdentifiers(
templateNames().stream()
Expand Down Expand Up @@ -329,5 +334,16 @@ public MethodDefinition build() {

return method;
}

void performNullChecks() {
String contextInfo = String.format("method definition of %s", name());
NodeValidator.checkNoNullElements(headerCommentStatements(), "header comments", contextInfo);
NodeValidator.checkNoNullElements(annotations(), "annotations", contextInfo);
NodeValidator.checkNoNullElements(throwsExceptions(), "declared exceptions", contextInfo);
NodeValidator.checkNoNullElements(body(), "body", contextInfo);
NodeValidator.checkNoNullElements(templateNames(), "template names", contextInfo);
NodeValidator.checkNoNullElements(
returnTemplateNames(), "return template names", contextInfo);
}
}
}

0 comments on commit e6c9726

Please sign in to comment.