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 Java5PrettyPrint { 035 public void ParClassDecl.prettyPrint(PrettyPrinter out) { 036 if (hasDocComment()) { 037 out.print(docComment()); 038 } 039 if (!out.isNewLine()) { 040 out.println(); 041 } 042 out.print(getModifiers()); 043 out.print("class "); 044 out.print(getID()); 045 out.print("<"); 046 out.join(getArgumentList(), new PrettyPrinter.Joiner() { 047 @Override 048 public void printSeparator(PrettyPrinter out) { 049 out.print(", "); 050 } 051 }); 052 out.print(">"); 053 if (hasSuperClass()) { 054 out.print(" extends "); 055 out.print(getSuperClass()); 056 } 057 if (hasImplements()) { 058 out.print(" implements "); 059 out.join(getImplementss(), new PrettyPrinter.Joiner() { 060 @Override 061 public void printSeparator(PrettyPrinter out) { 062 out.print(", "); 063 } 064 }); 065 } 066 out.print(" {"); 067 out.println(); 068 out.indent(1); 069 out.join(getBodyDecls(), new PrettyPrinter.Joiner() { 070 @Override 071 public void printSeparator(PrettyPrinter out) { 072 out.println(); 073 out.println(); 074 } 075 }); 076 if (!out.isNewLine()) { 077 out.println(); 078 } 079 out.print("}"); 080 } 081 public void ElementAnnotationValue.prettyPrint(PrettyPrinter out) { 082 out.print(getAnnotation()); 083 } 084 public void AnnotationMethodDecl.prettyPrint(PrettyPrinter out) { 085 if (hasDocComment()) { 086 out.print(docComment()); 087 } 088 if (!out.isNewLine()) { 089 out.println(); 090 } 091 out.print(getModifiers()); 092 out.print(getTypeAccess()); 093 out.print(" "); 094 out.print(getID()); 095 out.print("()"); 096 if (hasDefaultValue()) { 097 out.print(" default "); 098 out.print(getDefaultValue()); 099 } 100 out.print(";"); 101 } 102 public void ParTypeAccess.prettyPrint(PrettyPrinter out) { 103 out.print(getTypeAccess()); 104 out.print("<"); 105 out.join(getTypeArgumentList(), new PrettyPrinter.Joiner() { 106 @Override 107 public void printSeparator(PrettyPrinter out) { 108 out.print(", "); 109 } 110 }); 111 out.print(">"); 112 } 113 public void GenericInterfaceDecl.prettyPrint(PrettyPrinter out) { 114 if (hasDocComment()) { 115 out.print(docComment()); 116 } 117 if (!out.isNewLine()) { 118 out.println(); 119 } 120 out.print(getModifiers()); 121 out.print("interface "); 122 out.print(getID()); 123 out.print("<"); 124 out.join(getTypeParameterList(), new PrettyPrinter.Joiner() { 125 @Override 126 public void printSeparator(PrettyPrinter out) { 127 out.print(", "); 128 } 129 }); 130 out.print(">"); 131 if (hasSuperInterface()) { 132 out.print(" extends "); 133 out.join(getSuperInterfaceList(), new PrettyPrinter.Joiner() { 134 @Override 135 public void printSeparator(PrettyPrinter out) { 136 out.print(", "); 137 } 138 }); 139 } 140 out.print(" {"); 141 out.println(); 142 out.indent(1); 143 out.join(getBodyDecls(), new PrettyPrinter.Joiner() { 144 @Override 145 public void printSeparator(PrettyPrinter out) { 146 out.println(); 147 out.println(); 148 } 149 }); 150 if (!out.isNewLine()) { 151 out.println(); 152 } 153 out.print("}"); 154 } 155 public void ElementArrayValue.prettyPrint(PrettyPrinter out) { 156 out.print("{ "); 157 out.join(getElementValueList(), new PrettyPrinter.Joiner() { 158 @Override 159 public void printSeparator(PrettyPrinter out) { 160 out.print(", "); 161 } 162 }); 163 out.print(" }"); 164 } 165 public void Wildcard.prettyPrint(PrettyPrinter out) { 166 out.print("?"); 167 } 168 public void GenericConstructorDecl.prettyPrint(PrettyPrinter out) { 169 if (!isImplicitConstructor()) { 170 if (hasDocComment()) { 171 out.print(docComment()); 172 } 173 if (!out.isNewLine()) { 174 out.println(); 175 } 176 out.print(getModifiers()); 177 out.print("<"); 178 out.join(getTypeParameterList(), new PrettyPrinter.Joiner() { 179 @Override 180 public void printSeparator(PrettyPrinter out) { 181 out.print(", "); 182 } 183 }); 184 out.print("> "); 185 out.print(getID()); 186 out.print("("); 187 out.join(getParameterList(), new PrettyPrinter.Joiner() { 188 @Override 189 public void printSeparator(PrettyPrinter out) { 190 out.print(", "); 191 } 192 }); 193 out.print(")"); 194 if (hasExceptions()) { 195 out.print(" throws "); 196 out.join(getExceptionList(), new PrettyPrinter.Joiner() { 197 @Override 198 public void printSeparator(PrettyPrinter out) { 199 out.print(", "); 200 } 201 }); 202 } 203 out.print(" {"); 204 out.println(); 205 out.indent(1); 206 out.print(getParsedConstructorInvocation()); 207 if (!out.isNewLine()) { 208 out.println(); 209 } 210 out.println(); 211 out.indent(1); 212 out.join(blockStmts(), new PrettyPrinter.Joiner() { 213 @Override 214 public void printSeparator(PrettyPrinter out) { 215 out.println(); 216 } 217 }); 218 if (!out.isNewLine()) { 219 out.println(); 220 } 221 out.print("}"); 222 } 223 } 224 public void WildcardExtends.prettyPrint(PrettyPrinter out) { 225 out.print("? extends "); 226 out.print(getAccess()); 227 } 228 public void WildcardSuper.prettyPrint(PrettyPrinter out) { 229 out.print("? super "); 230 out.print(getAccess()); 231 } 232 public void ElementValuePair.prettyPrint(PrettyPrinter out) { 233 out.print(getName()); 234 out.print(" = "); 235 out.print(getElementValue()); 236 } 237 public void GenericMethodDecl.prettyPrint(PrettyPrinter out) { 238 if (hasDocComment()) { 239 out.print(docComment()); 240 } 241 if (!out.isNewLine()) { 242 out.println(); 243 } 244 out.print(getModifiers()); 245 out.print("<"); 246 out.join(getTypeParameterList(), new PrettyPrinter.Joiner() { 247 @Override 248 public void printSeparator(PrettyPrinter out) { 249 out.print(", "); 250 } 251 }); 252 out.print("> "); 253 out.print(getTypeAccess()); 254 out.print(" "); 255 out.print(getID()); 256 out.print("("); 257 out.join(getParameterList(), new PrettyPrinter.Joiner() { 258 @Override 259 public void printSeparator(PrettyPrinter out) { 260 out.print(", "); 261 } 262 }); 263 out.print(")"); 264 if (hasExceptions()) { 265 out.print(" throws "); 266 out.join(getExceptionList(), new PrettyPrinter.Joiner() { 267 @Override 268 public void printSeparator(PrettyPrinter out) { 269 out.print(", "); 270 } 271 }); 272 } 273 if (hasBlock()) { 274 out.print(" "); 275 out.print(getBlock()); 276 } else { 277 out.print(";"); 278 } 279 } 280 public void TypeVariable.prettyPrint(PrettyPrinter out) { 281 out.print(getID()); 282 if (hasTypeBound()) { 283 out.print(" extends "); 284 out.join(getTypeBoundList(), new PrettyPrinter.Joiner() { 285 @Override 286 public void printSeparator(PrettyPrinter out) { 287 out.print(" & "); 288 } 289 }); 290 } 291 } 292 public void AnnotationDecl.prettyPrint(PrettyPrinter out) { 293 out.print(getModifiers()); 294 out.print("@interface "); 295 out.print(getID()); 296 out.print(" {"); 297 out.println(); 298 out.indent(1); 299 out.join(getBodyDecls(), new PrettyPrinter.Joiner() { 300 @Override 301 public void printSeparator(PrettyPrinter out) { 302 out.println(); 303 out.println(); 304 } 305 }); 306 if (!out.isNewLine()) { 307 out.println(); 308 } 309 out.print("}"); 310 } 311 public void Annotation.prettyPrint(PrettyPrinter out) { 312 out.print("@"); 313 out.print(getAccess()); 314 if (hasElementValuePair()) { 315 out.print("("); 316 out.join(getElementValuePairList(), new PrettyPrinter.Joiner() { 317 @Override 318 public void printSeparator(PrettyPrinter out) { 319 out.print(", "); 320 } 321 }); 322 out.print(")"); 323 } 324 } 325 public void ElementConstantValue.prettyPrint(PrettyPrinter out) { 326 out.print(getExpr()); 327 } 328 public void StaticImportOnDemandDecl.prettyPrint(PrettyPrinter out) { 329 out.print("import static "); 330 out.print(getAccess()); 331 out.print(".*;"); 332 } 333 public void GenericClassDecl.prettyPrint(PrettyPrinter out) { 334 if (hasDocComment()) { 335 out.print(docComment()); 336 } 337 if (!out.isNewLine()) { 338 out.println(); 339 } 340 out.print(getModifiers()); 341 out.print("class "); 342 out.print(getID()); 343 out.print("<"); 344 out.join(getTypeParameterList(), new PrettyPrinter.Joiner() { 345 @Override 346 public void printSeparator(PrettyPrinter out) { 347 out.print(", "); 348 } 349 }); 350 out.print(">"); 351 if (hasSuperClass()) { 352 out.print(" extends "); 353 out.print(getSuperClass()); 354 } 355 if (hasImplements()) { 356 out.print(" implements "); 357 out.join(getImplementss(), new PrettyPrinter.Joiner() { 358 @Override 359 public void printSeparator(PrettyPrinter out) { 360 out.print(", "); 361 } 362 }); 363 } 364 out.print(" {"); 365 out.println(); 366 out.indent(1); 367 out.join(getBodyDecls(), new PrettyPrinter.Joiner() { 368 @Override 369 public void printSeparator(PrettyPrinter out) { 370 out.println(); 371 out.println(); 372 } 373 }); 374 if (!out.isNewLine()) { 375 out.println(); 376 } 377 out.print("}"); 378 } 379 public void VariableArityParameterDeclaration.prettyPrint(PrettyPrinter out) { 380 out.print(getModifiers()); 381 out.print(getTypeAccess()); 382 out.print("... "); 383 out.print(getID()); 384 } 385 public void SingleStaticImportDecl.prettyPrint(PrettyPrinter out) { 386 out.print("import static "); 387 out.print(getAccess()); 388 out.print("."); 389 out.print(getID()); 390 out.print(";"); 391 } 392 }