Skip to content

Commit

Permalink
[ggj][ast] feat: add EmptyLineStatement (#375)
Browse files Browse the repository at this point in the history
* fix: refactor requestBuilder into separate method in ServiceClientClassComposer

* feat: add EmptyLineStatement
  • Loading branch information
miraleung authored Oct 10, 2020
1 parent c789364 commit 3cea014
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public interface AstNodeVisitor {

public void visit(CommentStatement commentStatement);

public void visit(EmptyLineStatement emptyLineStatement);

/** =============================== OTHER =============================== */
public void visit(MethodDefinition methodDefinition);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.engine.ast;

public class EmptyLineStatement implements Statement {
private EmptyLineStatement() {}

@Override
public void accept(AstNodeVisitor visitor) {
visitor.visit(this);
}

public static EmptyLineStatement create() {
return new EmptyLineStatement();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.api.generator.engine.ast.CastExpr;
import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.CommentStatement;
import com.google.api.generator.engine.ast.EmptyLineStatement;
import com.google.api.generator.engine.ast.EnumRefExpr;
import com.google.api.generator.engine.ast.Expr;
import com.google.api.generator.engine.ast.ExprStatement;
Expand Down Expand Up @@ -316,23 +317,28 @@ public void visit(SynchronizedStatement synchronizedStatement) {

@Override
public void visit(CommentStatement commentStatement) {
// Do nothing
// Nothing to do.
}

@Override
public void visit(EmptyLineStatement emptyLineStatement) {
// Nothing to do.
}

/** =============================== COMMENT =============================== */
@Override
public void visit(LineComment lineComment) {
// Do nothing
// Nothing to do.
}

@Override
public void visit(BlockComment blockComment) {
// Do nothing
// Nothing to do.
}

@Override
public void visit(JavaDocComment javaDocComment) {
// Do nothing
// Nothing to do.
}

/** =============================== OTHER =============================== */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.api.generator.engine.ast.CastExpr;
import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.CommentStatement;
import com.google.api.generator.engine.ast.EmptyLineStatement;
import com.google.api.generator.engine.ast.EnumRefExpr;
import com.google.api.generator.engine.ast.Expr;
import com.google.api.generator.engine.ast.ExprStatement;
Expand Down Expand Up @@ -622,6 +623,11 @@ public void visit(CommentStatement commentStatement) {
commentStatement.comment().accept(this);
}

@Override
public void visit(EmptyLineStatement emptyLineStatement) {
newline();
}

/** =============================== COMMENT =============================== */
public void visit(LineComment lineComment) {
// Split comments by new line and add `//` to each line.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.api.generator.engine.writer;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
Expand All @@ -25,6 +26,7 @@
import com.google.api.generator.engine.ast.CastExpr;
import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.ConcreteReference;
import com.google.api.generator.engine.ast.EmptyLineStatement;
import com.google.api.generator.engine.ast.EnumRefExpr;
import com.google.api.generator.engine.ast.Expr;
import com.google.api.generator.engine.ast.ExprStatement;
Expand Down Expand Up @@ -1020,6 +1022,13 @@ public void writeLogicalOperationExprImports() {
"import com.google.api.generator.engine.ast.UnaryOperationExpr;\n\n");
}

@Test
public void writeEmptyLineStatementImports() {
EmptyLineStatement statement = EmptyLineStatement.create();
statement.accept(writerVisitor);
assertThat(writerVisitor.write()).isEmpty();
}

private static TypeNode createType(Class clazz) {
return TypeNode.withReference(ConcreteReference.withClazz(clazz));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.CommentStatement;
import com.google.api.generator.engine.ast.ConcreteReference;
import com.google.api.generator.engine.ast.EmptyLineStatement;
import com.google.api.generator.engine.ast.EnumRefExpr;
import com.google.api.generator.engine.ast.Expr;
import com.google.api.generator.engine.ast.ExprStatement;
Expand Down Expand Up @@ -2234,6 +2235,13 @@ public void writeAssignmentOperationExpr_xorAssignment() {
assertThat(writerVisitor.write()).isEqualTo("h ^= Objects.hashCode(fixedValue)");
}

@Test
public void writeEmptyLineStatement() {
EmptyLineStatement statement = EmptyLineStatement.create();
statement.accept(writerVisitor);
assertEquals(writerVisitor.write(), "\n");
}

private static String createLines(int numLines) {
return new String(new char[numLines]).replace("\0", "%s");
}
Expand Down

0 comments on commit 3cea014

Please sign in to comment.