File tree Expand file tree Collapse file tree
main/java/com/google/api/generator/engine
test/java/com/google/api/generator/engine/writer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,6 +87,8 @@ public interface AstNodeVisitor {
8787
8888 public void visit (CommentStatement commentStatement );
8989
90+ public void visit (EmptyLineStatement emptyLineStatement );
91+
9092 /** =============================== OTHER =============================== */
9193 public void visit (MethodDefinition methodDefinition );
9294
Original file line number Diff line number Diff line change 1+ // Copyright 2020 Google LLC
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ package com .google .api .generator .engine .ast ;
16+
17+ public class EmptyLineStatement implements Statement {
18+ private EmptyLineStatement () {}
19+
20+ @ Override
21+ public void accept (AstNodeVisitor visitor ) {
22+ visitor .visit (this );
23+ }
24+
25+ public static EmptyLineStatement create () {
26+ return new EmptyLineStatement ();
27+ }
28+ }
Original file line number Diff line number Diff line change 2525import com .google .api .generator .engine .ast .CastExpr ;
2626import com .google .api .generator .engine .ast .ClassDefinition ;
2727import com .google .api .generator .engine .ast .CommentStatement ;
28+ import com .google .api .generator .engine .ast .EmptyLineStatement ;
2829import com .google .api .generator .engine .ast .EnumRefExpr ;
2930import com .google .api .generator .engine .ast .Expr ;
3031import com .google .api .generator .engine .ast .ExprStatement ;
@@ -316,23 +317,28 @@ public void visit(SynchronizedStatement synchronizedStatement) {
316317
317318 @ Override
318319 public void visit (CommentStatement commentStatement ) {
319- // Do nothing
320+ // Nothing to do.
321+ }
322+
323+ @ Override
324+ public void visit (EmptyLineStatement emptyLineStatement ) {
325+ // Nothing to do.
320326 }
321327
322328 /** =============================== COMMENT =============================== */
323329 @ Override
324330 public void visit (LineComment lineComment ) {
325- // Do nothing
331+ // Nothing to do.
326332 }
327333
328334 @ Override
329335 public void visit (BlockComment blockComment ) {
330- // Do nothing
336+ // Nothing to do.
331337 }
332338
333339 @ Override
334340 public void visit (JavaDocComment javaDocComment ) {
335- // Do nothing
341+ // Nothing to do.
336342 }
337343
338344 /** =============================== OTHER =============================== */
Original file line number Diff line number Diff line change 2525import com .google .api .generator .engine .ast .CastExpr ;
2626import com .google .api .generator .engine .ast .ClassDefinition ;
2727import com .google .api .generator .engine .ast .CommentStatement ;
28+ import com .google .api .generator .engine .ast .EmptyLineStatement ;
2829import com .google .api .generator .engine .ast .EnumRefExpr ;
2930import com .google .api .generator .engine .ast .Expr ;
3031import com .google .api .generator .engine .ast .ExprStatement ;
@@ -622,6 +623,11 @@ public void visit(CommentStatement commentStatement) {
622623 commentStatement .comment ().accept (this );
623624 }
624625
626+ @ Override
627+ public void visit (EmptyLineStatement emptyLineStatement ) {
628+ newline ();
629+ }
630+
625631 /** =============================== COMMENT =============================== */
626632 public void visit (LineComment lineComment ) {
627633 // Split comments by new line and add `//` to each line.
Original file line number Diff line number Diff line change 1414
1515package com .google .api .generator .engine .writer ;
1616
17+ import static com .google .common .truth .Truth .assertThat ;
1718import static junit .framework .Assert .assertEquals ;
1819import static junit .framework .Assert .assertFalse ;
1920import static junit .framework .Assert .assertTrue ;
2526import com .google .api .generator .engine .ast .CastExpr ;
2627import com .google .api .generator .engine .ast .ClassDefinition ;
2728import com .google .api .generator .engine .ast .ConcreteReference ;
29+ import com .google .api .generator .engine .ast .EmptyLineStatement ;
2830import com .google .api .generator .engine .ast .EnumRefExpr ;
2931import com .google .api .generator .engine .ast .Expr ;
3032import com .google .api .generator .engine .ast .ExprStatement ;
@@ -1020,6 +1022,13 @@ public void writeLogicalOperationExprImports() {
10201022 "import com.google.api.generator.engine.ast.UnaryOperationExpr;\n \n " );
10211023 }
10221024
1025+ @ Test
1026+ public void writeEmptyLineStatementImports () {
1027+ EmptyLineStatement statement = EmptyLineStatement .create ();
1028+ statement .accept (writerVisitor );
1029+ assertThat (writerVisitor .write ()).isEmpty ();
1030+ }
1031+
10231032 private static TypeNode createType (Class clazz ) {
10241033 return TypeNode .withReference (ConcreteReference .withClazz (clazz ));
10251034 }
Original file line number Diff line number Diff line change 2828import com .google .api .generator .engine .ast .ClassDefinition ;
2929import com .google .api .generator .engine .ast .CommentStatement ;
3030import com .google .api .generator .engine .ast .ConcreteReference ;
31+ import com .google .api .generator .engine .ast .EmptyLineStatement ;
3132import com .google .api .generator .engine .ast .EnumRefExpr ;
3233import com .google .api .generator .engine .ast .Expr ;
3334import com .google .api .generator .engine .ast .ExprStatement ;
@@ -2234,6 +2235,13 @@ public void writeAssignmentOperationExpr_xorAssignment() {
22342235 assertThat (writerVisitor .write ()).isEqualTo ("h ^= Objects.hashCode(fixedValue)" );
22352236 }
22362237
2238+ @ Test
2239+ public void writeEmptyLineStatement () {
2240+ EmptyLineStatement statement = EmptyLineStatement .create ();
2241+ statement .accept (writerVisitor );
2242+ assertEquals (writerVisitor .write (), "\n " );
2243+ }
2244+
22372245 private static String createLines (int numLines ) {
22382246 return new String (new char [numLines ]).replace ("\0 " , "%s" );
22392247 }
You can’t perform that action at this time.
0 commit comments