001    /* Copyright (c) 2015, Jesper Öqvist <jesper.oqvist@cs.lth.se>
002     * All rights reserved.
003     *
004     * Redistribution and use in source and binary forms, with or without
005     * modification, are permitted provided that the following conditions are met:
006     *
007     * 1. Redistributions of source code must retain the above copyright notice,
008     * this list of conditions and the following disclaimer.
009     *
010     * 2. Redistributions in binary form must reproduce the above copyright notice,
011     * this list of conditions and the following disclaimer in the documentation
012     * and/or other materials provided with the distribution.
013     *
014     * 3. Neither the name of the copyright holder nor the names of its
015     * contributors may be used to endorse or promote products derived from this
016     * software without specific prior written permission.
017     *
018     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
022     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024     * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025     * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026     * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027     * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028     * POSSIBILITY OF SUCH DAMAGE.
029     */
030    
031    /**
032     * This is a generated aspect for pretty-printing Java programs.
033     */
034    aspect Java4PrettyPrint {
035      public void BasicCatch.prettyPrint(PrettyPrinter out) {
036        out.print("catch (");
037        out.print(getParameter());
038        out.print(") ");
039        out.print(getBlock());
040      }
041      public void FieldDeclaration.prettyPrint(PrettyPrinter out) {
042        if (hasDocComment()) {
043          out.print(docComment());
044        }
045        if (!out.isNewLine()) {
046          out.println();
047        }
048        out.print(getModifiers());
049        out.print(getTypeAccess());
050        out.print(" ");
051        out.print(getID());
052        if (hasInit()) {
053          out.print(" = ");
054          out.print(getInit());
055        }
056        out.print(";");
057      }
058      public void VariableDecl.prettyPrint(PrettyPrinter out) {
059        out.print(getID());
060        out.print(getDimsList());
061        if (hasInit()) {
062          out.print(" = ");
063          out.print(getInit());
064        }
065      }
066      public void MethodDecl.prettyPrint(PrettyPrinter out) {
067        if (hasDocComment()) {
068          out.print(docComment());
069        }
070        if (!out.isNewLine()) {
071          out.println();
072        }
073        out.print(getModifiers());
074        out.print(getTypeAccess());
075        out.print(" ");
076        out.print(getID());
077        out.print("(");
078        out.join(getParameterList(), new PrettyPrinter.Joiner() {
079          @Override
080          public void printSeparator(PrettyPrinter out) {
081            out.print(", ");
082          }
083        });
084        out.print(")");
085        if (hasExceptions()) {
086          out.print(" throws ");
087          out.join(getExceptionList(), new PrettyPrinter.Joiner() {
088            @Override
089            public void printSeparator(PrettyPrinter out) {
090              out.print(", ");
091            }
092          });
093        }
094        if (hasBlock()) {
095          out.print(" ");
096          out.print(getBlock());
097        } else {
098          out.print(";");
099        }
100      }
101      public void ByteType.prettyPrint(PrettyPrinter out) {
102        out.print("byte");
103      }
104      public void Modifier.prettyPrint(PrettyPrinter out) {
105        out.print(getID());
106      }
107      public void DoStmt.prettyPrint(PrettyPrinter out) {
108        out.print("do ");
109        out.print(getStmt());
110        out.print(" while(");
111        out.print(getCondition());
112        out.print(");");
113      }
114      public void CharacterLiteral.prettyPrint(PrettyPrinter out) {
115        out.print("'");
116        out.print(escapedLiteral());
117        out.print("'");
118      }
119      public void MemberInterfaceDecl.prettyPrint(PrettyPrinter out) {
120        out.print(getInterfaceDecl());
121      }
122      public void Modifiers.prettyPrint(PrettyPrinter out) {
123        if (hasModifier()) {
124          out.join(getModifierList(), new PrettyPrinter.Joiner() {
125            @Override
126            public void printSeparator(PrettyPrinter out) {
127              out.print(" ");
128            }
129          });
130          out.print(" ");
131        }
132      }
133      public void IntType.prettyPrint(PrettyPrinter out) {
134        out.print("int");
135      }
136      public void ThisAccess.prettyPrint(PrettyPrinter out) {
137        out.print("this");
138      }
139      public void PackageAccess.prettyPrint(PrettyPrinter out) {
140        out.print(getPackage());
141      }
142      public void ArrayTypeAccess.prettyPrint(PrettyPrinter out) {
143        out.print(getAccess());
144        out.print("[]");
145      }
146      public void ParExpr.prettyPrint(PrettyPrinter out) {
147        out.print("(");
148        out.print(getExpr());
149        out.print(")");
150      }
151      public void ExprStmt.prettyPrint(PrettyPrinter out) {
152        out.print(getExpr());
153        out.print(";");
154      }
155      public void LabeledStmt.prettyPrint(PrettyPrinter out) {
156        out.print(getLabel());
157        out.print(":");
158      }
159      public void LocalClassDeclStmt.prettyPrint(PrettyPrinter out) {
160        out.print(getClassDecl());
161      }
162      public void SuperAccess.prettyPrint(PrettyPrinter out) {
163        out.print("super");
164      }
165      public void VarDeclStmt.prettyPrint(PrettyPrinter out) {
166        out.print(getModifiers());
167        out.print(getTypeAccess());
168        out.print(" ");
169        out.join(getVariableDecls(), new PrettyPrinter.Joiner() {
170          @Override
171          public void printSeparator(PrettyPrinter out) {
172            out.print(", ");
173          }
174        });
175        out.print(";");
176      }
177      public void ConditionalExpr.prettyPrint(PrettyPrinter out) {
178        out.print(getCondition());
179        out.print(" ? ");
180        out.print(getTrueExpr());
181        out.print(" : ");
182        out.print(getFalseExpr());
183      }
184      public void Literal.prettyPrint(PrettyPrinter out) {
185        out.print(getLITERAL());
186      }
187      public void Binary.prettyPrint(PrettyPrinter out) {
188        out.print(getLeftOperand());
189        out.print(" ");
190        out.print(printOp());
191        out.print(" ");
192        out.print(getRightOperand());
193      }
194      public void ContinueStmt.prettyPrint(PrettyPrinter out) {
195        out.print("continue");
196        if (hasLabel()) {
197          out.print(" ");
198          out.print(getLabel());
199        }
200        out.print(";");
201      }
202      public void SynchronizedStmt.prettyPrint(PrettyPrinter out) {
203        out.print("synchronized ");
204        out.print(getExpr());
205        out.print(" ");
206        out.print(getBlock());
207        if (!out.isNewLine()) {
208          out.println();
209        }
210      }
211      public void InstanceOfExpr.prettyPrint(PrettyPrinter out) {
212        out.print(getExpr());
213        out.print(" instanceof ");
214        out.print(getTypeAccess());
215      }
216      public void CharType.prettyPrint(PrettyPrinter out) {
217        out.print("char");
218      }
219      public void ReturnStmt.prettyPrint(PrettyPrinter out) {
220        out.print("return");
221        if (hasResult()) {
222          out.print(" ");
223          out.print(getResult());
224        }
225        out.print(";");
226      }
227      public void ClassAccess.prettyPrint(PrettyPrinter out) {
228        out.print("class");
229      }
230      public void Unary.prettyPrint(PrettyPrinter out) {
231        out.print(printPreOp());
232        out.print(getOperand());
233        out.print(printPostOp());
234      }
235      public void EmptyStmt.prettyPrint(PrettyPrinter out) {
236        out.print(";");
237      }
238      public void SwitchStmt.prettyPrint(PrettyPrinter out) {
239        out.print("switch (");
240        out.print(getExpr());
241        out.print(") ");
242        out.print(getBlock());
243      }
244      public void StaticInitializer.prettyPrint(PrettyPrinter out) {
245        out.print("static ");
246        if (!blockIsEmpty()) {
247          out.print(getBlock());
248        }
249      }
250      public void Dims.prettyPrint(PrettyPrinter out) {
251        out.print("[");
252        out.print(getExprOpt());
253        out.print("]");
254      }
255      public void SingleTypeImportDecl.prettyPrint(PrettyPrinter out) {
256        out.print("import ");
257        out.print(getAccess());
258        out.print(";");
259        out.println();
260      }
261      public void DefaultCase.prettyPrint(PrettyPrinter out) {
262        out.print("default:");
263      }
264      public void InstanceInitializer.prettyPrint(PrettyPrinter out) {
265        if (!blockIsEmpty()) {
266          out.print(getBlock());
267        }
268      }
269      public void EmptyType.prettyPrint(PrettyPrinter out) {
270        out.print(";");
271      }
272      public void ConstCase.prettyPrint(PrettyPrinter out) {
273        out.print("case ");
274        out.print(getValue());
275        out.print(":");
276      }
277      public void BooleanType.prettyPrint(PrettyPrinter out) {
278        out.print("boolean");
279      }
280      public void LongLiteral.prettyPrint(PrettyPrinter out) {
281        out.print(getLITERAL());
282      }
283      public void ThrowStmt.prettyPrint(PrettyPrinter out) {
284        out.print("throw ");
285        out.print(getExpr());
286        out.print(";");
287      }
288      public void BreakStmt.prettyPrint(PrettyPrinter out) {
289        out.print("break");
290        if (hasLabel()) {
291          out.print(" ");
292          out.print(getLabel());
293        }
294        out.print(";");
295      }
296      public void NullType.prettyPrint(PrettyPrinter out) {
297        out.print("null");
298      }
299      public void MemberClassDecl.prettyPrint(PrettyPrinter out) {
300        out.print(getClassDecl());
301      }
302      public void CompilationUnit.prettyPrint(PrettyPrinter out) {
303        if (hasPackageDecl()) {
304          out.print("package ");
305          out.print(getPackageDecl());
306          out.print(";");
307          out.println();
308        }
309        if (!out.isNewLine()) {
310          out.println();
311        }
312        out.print(getImportDeclList());
313        if (!out.isNewLine()) {
314          out.println();
315        }
316        out.println();
317        out.join(getTypeDecls(), new PrettyPrinter.Joiner() {
318          @Override
319          public void printSeparator(PrettyPrinter out) {
320            out.println();
321            out.println();
322          }
323        });
324      }
325      public void InterfaceDecl.prettyPrint(PrettyPrinter out) {
326        if (hasDocComment()) {
327          out.print(docComment());
328        }
329        if (!out.isNewLine()) {
330          out.println();
331        }
332        out.print(getModifiers());
333        out.print("interface ");
334        out.print(getID());
335        if (hasSuperInterface()) {
336          out.print(" extends ");
337          out.join(getSuperInterfaceList(), new PrettyPrinter.Joiner() {
338            @Override
339            public void printSeparator(PrettyPrinter out) {
340              out.print(", ");
341            }
342          });
343        }
344        out.print(" {");
345        out.println();
346        out.indent(1);
347        out.join(getBodyDecls(), new PrettyPrinter.Joiner() {
348          @Override
349          public void printSeparator(PrettyPrinter out) {
350            out.println();
351            out.println();
352          }
353        });
354        if (!out.isNewLine()) {
355          out.println();
356        }
357        out.print("}");
358      }
359      public void FloatType.prettyPrint(PrettyPrinter out) {
360        out.print("float");
361      }
362      public void ClassDecl.prettyPrint(PrettyPrinter out) {
363        if (hasDocComment()) {
364          out.print(docComment());
365        }
366        if (!out.isNewLine()) {
367          out.println();
368        }
369        out.print(getModifiers());
370        out.print("class ");
371        out.print(getID());
372        if (hasSuperClass()) {
373          out.print(" extends ");
374          out.print(getSuperClass());
375        }
376        if (hasImplements()) {
377          out.print(" implements ");
378          out.join(getImplementss(), new PrettyPrinter.Joiner() {
379            @Override
380            public void printSeparator(PrettyPrinter out) {
381              out.print(", ");
382            }
383          });
384        }
385        out.print(" {");
386        out.println();
387        out.indent(1);
388        out.join(getBodyDecls(), new PrettyPrinter.Joiner() {
389          @Override
390          public void printSeparator(PrettyPrinter out) {
391            out.println();
392            out.println();
393          }
394        });
395        if (!out.isNewLine()) {
396          out.println();
397        }
398        out.print("}");
399      }
400      public void CastExpr.prettyPrint(PrettyPrinter out) {
401        out.print("(");
402        out.print(getTypeAccess());
403        out.print(") ");
404        out.print(getExpr());
405      }
406      public void AssignExpr.prettyPrint(PrettyPrinter out) {
407        out.print(getDest());
408        out.print(" ");
409        out.print(printOp());
410        out.print(" ");
411        out.print(getSource());
412      }
413      public void ParameterDeclaration.prettyPrint(PrettyPrinter out) {
414        out.print(getModifiers());
415        out.print(getTypeAccess());
416        out.print(" ");
417        out.print(getID());
418      }
419      public void AssertStmt.prettyPrint(PrettyPrinter out) {
420        if (hasMessage()) {
421          out.print("assert ");
422          out.print(getCondition());
423          out.print(" : ");
424          out.print(getMessage());
425          out.print(";");
426        } else {
427          out.print("assert ");
428          out.print(getCondition());
429          out.print(";");
430        }
431      }
432      public void ArrayAccess.prettyPrint(PrettyPrinter out) {
433        out.print("[");
434        out.print(getExpr());
435        out.print("]");
436      }
437      public void DoubleType.prettyPrint(PrettyPrinter out) {
438        out.print("double");
439      }
440      public void TryStmt.prettyPrint(PrettyPrinter out) {
441        out.print("try ");
442        out.print(getBlock());
443        out.print(" ");
444        out.join(getCatchClauseList(), new PrettyPrinter.Joiner() {
445          @Override
446          public void printSeparator(PrettyPrinter out) {
447            out.print(" ");
448          }
449        });
450        if (hasFinally()) {
451          out.print(" finally ");
452          out.print(getFinally());
453        }
454      }
455      public void Block.prettyPrint(PrettyPrinter out) {
456        out.print("{");
457        out.println();
458        out.indent(1);
459        out.join(getStmtList(), new PrettyPrinter.Joiner() {
460          @Override
461          public void printSeparator(PrettyPrinter out) {
462            out.println();
463          }
464        });
465        if (!out.isNewLine()) {
466          out.println();
467        }
468        out.print("}");
469      }
470      public void StringLiteral.prettyPrint(PrettyPrinter out) {
471        out.print("\"");
472        out.print(escapedLiteral());
473        out.print("\"");
474      }
475      public void ParseName.prettyPrint(PrettyPrinter out) {
476        out.print(getID());
477      }
478      public void ShortType.prettyPrint(PrettyPrinter out) {
479        out.print("short");
480      }
481      public void ConstructorAccess.prettyPrint(PrettyPrinter out) {
482        out.print(getID());
483        out.print("(");
484        out.join(getArgList(), new PrettyPrinter.Joiner() {
485          @Override
486          public void printSeparator(PrettyPrinter out) {
487            out.print(", ");
488          }
489        });
490        out.print(")");
491      }
492      public void VarAccess.prettyPrint(PrettyPrinter out) {
493        out.print(getID());
494      }
495      public void LongType.prettyPrint(PrettyPrinter out) {
496        out.print("long");
497      }
498      public void AbstractDot.prettyPrint(PrettyPrinter out) {
499        if (needsDot()) {
500          out.print(getLeft());
501          out.print(".");
502          out.print(getRight());
503        } else {
504          out.print(getLeft());
505          out.print(getRight());
506        }
507      }
508      public void ConstructorDecl.prettyPrint(PrettyPrinter out) {
509        if (!isImplicitConstructor()) {
510          if (hasDocComment()) {
511            out.print(docComment());
512          }
513          if (!out.isNewLine()) {
514            out.println();
515          }
516          out.print(getModifiers());
517          out.print(getID());
518          out.print("(");
519          out.join(getParameterList(), new PrettyPrinter.Joiner() {
520            @Override
521            public void printSeparator(PrettyPrinter out) {
522              out.print(", ");
523            }
524          });
525          out.print(")");
526          if (hasExceptions()) {
527            out.print(" throws ");
528            out.join(getExceptionList(), new PrettyPrinter.Joiner() {
529              @Override
530              public void printSeparator(PrettyPrinter out) {
531                out.print(", ");
532              }
533            });
534          }
535          out.print(" {");
536          out.println();
537          out.indent(1);
538          out.print(getParsedConstructorInvocationOpt());
539          if (!out.isNewLine()) {
540            out.println();
541          }
542          out.indent(1);
543          out.join(blockStmts(), new PrettyPrinter.Joiner() {
544            @Override
545            public void printSeparator(PrettyPrinter out) {
546              out.println();
547            }
548          });
549          if (!out.isNewLine()) {
550            out.println();
551          }
552          out.print("}");
553        }
554      }
555      public void ArrayTypeWithSizeAccess.prettyPrint(PrettyPrinter out) {
556        out.print(getAccess());
557        out.print("[");
558        out.print(getExpr());
559        out.print("]");
560      }
561      public void ClassInstanceExpr.prettyPrint(PrettyPrinter out) {
562        out.print("new ");
563        out.print(getAccess());
564        out.print("(");
565        out.join(getArgList(), new PrettyPrinter.Joiner() {
566          @Override
567          public void printSeparator(PrettyPrinter out) {
568            out.print(", ");
569          }
570        });
571        out.print(")");
572        if (hasTypeDecl()) {
573          if (hasPrintableBodyDecl()) {
574            out.print(" {");
575            out.println();
576            out.indent(1);
577            out.join(bodyDecls(), new PrettyPrinter.Joiner() {
578              @Override
579              public void printSeparator(PrettyPrinter out) {
580                out.println();
581              }
582            });
583            out.print("}");
584          } else {
585            out.print(" { }");
586          }
587        }
588      }
589      public void ArrayCreationExpr.prettyPrint(PrettyPrinter out) {
590        out.print("new ");
591        out.print(getTypeAccess());
592        if (hasArrayInit()) {
593          out.print(" ");
594          out.print(getArrayInit());
595        }
596      }
597      public void FloatingPointLiteral.prettyPrint(PrettyPrinter out) {
598        out.print(getLITERAL());
599      }
600      public void TypeAccess.prettyPrint(PrettyPrinter out) {
601        if (hasPackage()) {
602          out.print(getPackage());
603          out.print(".");
604        }
605        out.print(getID());
606      }
607      public void VoidType.prettyPrint(PrettyPrinter out) {
608        out.print("void");
609      }
610      public void ArrayInit.prettyPrint(PrettyPrinter out) {
611        out.print("{ ");
612        out.join(getInitList(), new PrettyPrinter.Joiner() {
613          @Override
614          public void printSeparator(PrettyPrinter out) {
615            out.print(", ");
616          }
617        });
618        out.print(" }");
619      }
620      public void TypeImportOnDemandDecl.prettyPrint(PrettyPrinter out) {
621        out.print("import ");
622        out.print(getAccess());
623        out.print(".*;");
624        out.println();
625      }
626      public void MethodAccess.prettyPrint(PrettyPrinter out) {
627        out.print(getID());
628        out.print("(");
629        out.join(getArgList(), new PrettyPrinter.Joiner() {
630          @Override
631          public void printSeparator(PrettyPrinter out) {
632            out.print(", ");
633          }
634        });
635        out.print(")");
636      }
637      public void DoubleLiteral.prettyPrint(PrettyPrinter out) {
638        out.print(getLITERAL());
639      }
640    }