• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 210

26 Oct 2023 10:10PM UTC coverage: 62.609% (-1.1%) from 63.756%
210

push

circleci

web-flow
Jass And Wurst Formatter (#620)

Support for formatting .wurst and .j files.

Thanks @karlek 

Co-authored-by: Frotty <Frotty@users.noreply.github.com>
Co-authored-by: Peter Zeller <Peter.peq@googlemail.com>

17297 of 27627 relevant lines covered (62.61%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.32
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/prettyPrint/PrettyPrinter.java
1
package de.peeeq.wurstscript.attributes.prettyPrint;
2

3
import de.peeeq.wurstscript.ast.*;
4
import de.peeeq.wurstscript.ast.Element;
5
import de.peeeq.wurstscript.jassAst.*;
6
import de.peeeq.wurstscript.utils.Utils;
7
import de.peeeq.wurstscript.parser.WPos;
8
import de.peeeq.wurstscript.parser.WPosWithComments;
9
import de.peeeq.wurstscript.parser.WPosWithComments.Comment;
10
import org.apache.commons.lang.StringUtils;
11

12
import static de.peeeq.wurstscript.jassprinter.JassPrinter.precedence;
13

14
public class PrettyPrinter {
×
15

16
    private static void commaSeparatedList(Element e, Spacer spacer, StringBuilder sb, int indent) {
17
        for (int i = 0; i < e.size(); i++) {
×
18
            if (i > 0) {
×
19
                sb.append(",");
×
20
                spacer.addSpace(sb);
×
21
            }
22
            e.get(i).prettyPrint(spacer, sb, indent);
×
23
        }
24
    }
×
25

26
    private static void printClassOrModuleDeclaration(ClassOrModule e, Spacer spacer, StringBuilder sb, int indent) {
27
        e.getModuleUses().prettyPrint(spacer, sb, indent);
×
28
        e.getVars().prettyPrint(spacer, sb, indent);
×
29
        e.getConstructors().prettyPrint(spacer, sb, indent);
×
30
        e.getMethods().prettyPrint(spacer, sb, indent);
×
31
        e.getOnDestroy().prettyPrint(spacer, sb, indent);
×
32
        e.getInnerClasses().prettyPrint(spacer, sb, indent);
×
33
    }
×
34

35
    private static void printFirstNewline(Element e, StringBuilder sb, int indent) {
36
        // Don't add first new line.
37
        if (e.getParent().get(0).equals(e)) {
1✔
38
            return;
1✔
39
        }
40
        if (sb.charAt(sb.length() - 1) == '\n' && sb.charAt(sb.length() - 2) == '\n') {
×
41
            return;
×
42
        }
43
        sb.append("\n");
×
44
    }
×
45

46
    private static void printNewline(Element e, StringBuilder sb, int indent) {
47
        // Don't add a newline unless we are directly under statements.
48
        // Otherwise we would add newlines inside function calls, etc.
49
        if (!(e.getParent() instanceof WStatements)) {
×
50
            return;
×
51
        }
52
        sb.append("\n");
×
53
    }
×
54

55
    private static void printStuff(Documentable e, Spacer spacer, StringBuilder sb, int indent) {
56
        printCommentsBefore(sb, e, indent);
1✔
57
        printHotDoc(e.getModifiers(), spacer, sb, indent);
1✔
58
        printIndent(sb, indent);
1✔
59
        e.getModifiers().prettyPrint(spacer, sb, indent);
1✔
60
    }
1✔
61

62
    // For some reason comments are a kind of modifier.
63
    private static void printHotDoc(Modifiers e, Spacer spacer, StringBuilder sb, int indent) {
64
        for (Modifier modifier : e) {
1✔
65
            if (modifier instanceof WurstDoc) {
×
66
                modifier.prettyPrint(spacer, sb, indent);
×
67
            }
68
        }
×
69
    }
1✔
70

71
    private static void printCommentsBefore(StringBuilder sb, Element d, int indent) {
72
        if (!(d instanceof AstElementWithSource)) {
1✔
73
            return;
×
74
        }
75
        WPos source1 = ((AstElementWithSource) d).getSource();
1✔
76
        if (source1 instanceof WPosWithComments) {
1✔
77
            WPosWithComments source = (WPosWithComments) source1;
1✔
78
            for (Comment comment : source.getCommentsBefore()) {
1✔
79
                printIndent(sb, indent);
×
80
                sb.append(comment.getContent());
×
81
                if (comment.isSingleLine()) {
×
82
                    sb.append("\n");
×
83
                }
84
            }
×
85
        }
86
    }
1✔
87

88
    private static void printCommentsAfter(StringBuilder sb, Element d, int indent) {
89
        if (!(d instanceof AstElementWithSource)) {
1✔
90
            return;
×
91
        }
92
        WPos source1 = ((AstElementWithSource) d).getSource();
1✔
93
        if (source1 instanceof WPosWithComments) {
1✔
94
            WPosWithComments source = (WPosWithComments) source1;
1✔
95
            for (Comment comment : source.getCommentsAfter()) {
1✔
96
                printIndent(sb, indent);
×
97
                sb.append(comment.getContent());
×
98
                if (comment.isSingleLine()) {
×
99
                    sb.append("\n");
×
100
                }
101
            }
×
102
        }
103
    }
1✔
104

105

106
    private static void printIndent(StringBuilder sb, int indent) {
107
        if (sb.length() > 0 && sb.charAt(sb.length() - 1) == '\n') {
1✔
108
            for (int i = 0; i < indent; i++) {
1✔
109
                sb.append("    ");
1✔
110
            }
111
        }
112
    }
1✔
113

114
    private static String calculateIndent(int indent) {
115
        String s = "";
×
116
        for (int i = 0; i < indent; i++) {
×
117
            s += "\t";
×
118
        }
119
        return s;
×
120
    }
121

122
    public static void prettyPrint(JassToplevelDeclarations e, Spacer spacer, StringBuilder sb, int indent) {
123
    }
×
124

125
    public static void prettyPrint(JassGlobalBlock e, Spacer spacer, StringBuilder sb, int indent) {
126
    }
×
127

128
    public static void prettyPrint(Annotation e, Spacer spacer, StringBuilder sb, int indent) {
129
        sb.append(e.getAnnotationType());
×
130
        if (e.getAnnotationMessage() != null && e.getAnnotationMessage().length() >= 1) {
×
131
            sb.append("(");
×
132
            sb.append(e.getAnnotationMessage());
×
133
            sb.append(")");
×
134
        }
135
    }
×
136

137
    public static void prettyPrint(Arguments e, Spacer spacer, StringBuilder sb, int indent) {
138
        commaSeparatedList(e, spacer, sb, indent);
×
139
    }
×
140

141
    public static void prettyPrint(ExprList e, Spacer spacer, StringBuilder sb, int indent) {
142
        commaSeparatedList(e, spacer, sb, indent);
×
143
    }
×
144

145
    public static void prettyPrint(ArraySizes e, Spacer spacer, StringBuilder sb, int indent) {
146
        commaSeparatedList(e, spacer, sb, indent);
×
147
    }
×
148

149
    public static void prettyPrint(ClassDef e, Spacer spacer, StringBuilder sb, int indent) {
150
        printFirstNewline(e, sb, indent);
×
151
        printStuff(e, spacer, sb, indent);
×
152
        sb.append("class");
×
153
        spacer.addSpace(sb);
×
154
        sb.append(e.getName());
×
155
        e.getTypeParameters().prettyPrint(spacer, sb, indent);
×
156
        if (e.getExtendedClass() instanceof TypeExpr) {
×
157
            TypeExpr te = (TypeExpr) e.getExtendedClass();
×
158
            spacer.addSpace(sb);
×
159
            sb.append("extends");
×
160
            spacer.addSpace(sb);
×
161
            te.prettyPrint(spacer, sb, indent);
×
162
        }
163
        if (!e.getImplementsList().isEmpty()) {
×
164
            spacer.addSpace(sb);
×
165
            sb.append("implements");
×
166
            spacer.addSpace(sb);
×
167
            commaSeparatedList(e.getImplementsList(), spacer, sb, indent);
×
168
        }
169
        sb.append("\n");
×
170
        printClassOrModuleDeclaration(e, spacer, sb, indent + 1);
×
171
        printCommentsAfter(sb, e, indent);
×
172
    }
×
173

174
    public static void prettyPrint(CompilationUnit e, Spacer spacer, StringBuilder sb, int indent) {
175
        prettyPrint(e.getPackages(), spacer, sb, indent);
×
176
        jassPrettyPrint(e.getJassDecls(), spacer, sb, indent);
×
177
    }
×
178

179
    public static void prettyPrint(ConstructorDef e, Spacer spacer, StringBuilder sb, int indent) {
180
        printFirstNewline(e, sb, indent);
1✔
181
        printStuff(e, spacer, sb, indent);
1✔
182
        sb.append("construct");
1✔
183
        e.getParameters().prettyPrint(spacer, sb, indent);
1✔
184
        sb.append("\n");
1✔
185
        e.getSuperConstructorCall().prettyPrint(spacer, sb, indent);
1✔
186
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
187
        printCommentsAfter(sb, e, indent);
1✔
188
    }
1✔
189

190
    public static void prettyPrint(ConstructorDefs e, Spacer spacer, StringBuilder sb, int indent) {
191
        for (ConstructorDef constructorDef : e) {
1✔
192
            constructorDef.prettyPrint(spacer, sb, indent);
1✔
193
        }
1✔
194
    }
1✔
195

196
    public static void prettyPrint(EndFunctionStatement e, Spacer spacer, StringBuilder sb, int indent) {
197
    }
1✔
198

199
    public static void prettyPrint(EnumDef e, Spacer spacer, StringBuilder sb, int indent) {
200
        printFirstNewline(e, sb, indent);
×
201
        printStuff(e, spacer, sb, indent);
×
202
        sb.append("enum");
×
203
        spacer.addSpace(sb);
×
204
        sb.append(e.getName());
×
205
        sb.append("\n");
×
206
        e.getMembers().prettyPrint(spacer, sb, indent + 1);
×
207
        printCommentsAfter(sb, e, indent);
×
208
    }
×
209

210
    public static void prettyPrint(EnumMember e, Spacer spacer, StringBuilder sb, int indent) {
211
        printStuff(e, spacer, sb, indent);
×
212
        sb.append(e.getName());
×
213
        sb.append("\n");
×
214
        printCommentsAfter(sb, e, indent);
×
215
    }
×
216

217
    public static void prettyPrint(EnumMembers e, Spacer spacer, StringBuilder sb, int indent) {
218
        for (EnumMember enumMember : e) {
×
219
            enumMember.prettyPrint(spacer, sb, indent);
×
220
        }
×
221
    }
×
222

223

224
    public static void prettyPrint(ExprBinary e, Spacer spacer, StringBuilder sb, int indent) {
225
        boolean useParanthesesLeft = false;
×
226
        boolean useParanthesesRight = false;
×
227
        if (e.getLeft() instanceof ExprBinary) {
×
228
            ExprBinary left = (ExprBinary) e.getLeft();
×
229
            if (precedence(left.getOp().jassTranslateBinary()) < precedence(e.getOp().jassTranslateBinary())) {
×
230
                // if the precedence level on the left is _smaller_ we have to use parentheses
231
                useParanthesesLeft = true;
×
232
            }
233
            // if the precedence level is equal we can assume left associativity of all operators
234
            // so they are treated correctly
235
        } else if (e.getLeft() instanceof ExprUnary) {
×
236
            useParanthesesLeft = true;
×
237
        }
238
        if (e.getRight() instanceof ExprBinary) {
×
239
            ExprBinary right = (ExprBinary) e.getRight();
×
240
            JassOpBinary op = right.getOp().jassTranslateBinary();
×
241
            JassOpBinary op2 = e.getOp().jassTranslateBinary();
×
242
            if (precedence(op) < precedence(op2)) {
×
243
                // if the precedence level on the right is smaller we have to use parentheses
244
                useParanthesesRight = true;
×
245
            } else if (precedence(op) == precedence(op2)) {
×
246
                // if the precedence level is equal we have to parentheses as operators are
247
                // left associative but for commutative operators (+, *, and, or) we do not
248
                // need parentheses
249

250
                if (!((op instanceof JassOpPlus && op2 instanceof JassOpPlus)
×
251
                    || (op instanceof JassOpMult && op2 instanceof JassOpMult)
252
                    || (op instanceof JassOpOr && op2 instanceof JassOpOr)
253
                    || (op instanceof JassOpAnd && op2 instanceof JassOpAnd))) {
254
                    // in other cases use parentheses
255
                    // for example
256
                    useParanthesesRight = true;
×
257
                }
258
            }
259
        } else if (e.getRight() instanceof JassExprUnary) {
×
260
            useParanthesesRight = true;
×
261
        }
262

263
        sb.append(useParanthesesLeft ? "(" : "");
×
264
        e.getLeft().prettyPrint(spacer, sb, indent);
×
265
        sb.append(useParanthesesLeft ? ")" : "");
×
266
        spacer.addSpace(sb);
×
267
        sb.append(e.getOp().toString());
×
268
        spacer.addSpace(sb);
×
269
        sb.append(useParanthesesRight ? "(" : "");
×
270
        e.getRight().prettyPrint(spacer, sb, indent);
×
271
        sb.append(useParanthesesRight ? ")" : "");
×
272
    }
×
273

274
    public static void prettyPrint(ExprBoolVal e, Spacer spacer, StringBuilder sb, int indent) {
275
        sb.append(String.valueOf(e.getValB()));
×
276
    }
×
277

278
    public static void prettyPrint(ExprCast e, Spacer spacer, StringBuilder sb, int indent) {
279
        e.getExpr().prettyPrint(spacer, sb, indent);
×
280
        spacer.addSpace(sb);
×
281
        sb.append("castTo");
×
282
        spacer.addSpace(sb);
×
283
        e.getTyp().prettyPrint(spacer, sb, indent);
×
284
    }
×
285

286
    public static void prettyPrint(ExprClosure e, Spacer spacer, StringBuilder sb, int indent) {
287
        e.getShortParameters().prettyPrint(spacer, sb, indent);
×
288
        spacer.addSpace(sb);
×
289
        sb.append("->");
×
290
        spacer.addSpace(sb);
×
291
        e.getImplementation().prettyPrint(spacer, sb, indent);
×
292
    }
×
293

294
    public static void prettyPrint(ExprDestroy e, Spacer spacer, StringBuilder sb, int indent) {
295
        printFirstNewline(e, sb, indent);
×
296
        printIndent(sb, indent);
×
297
        sb.append("destroy");
×
298
        spacer.addSpace(sb);
×
299
        e.getDestroyedObj().prettyPrint(spacer, sb, indent);
×
300
        sb.append("\n");
×
301
    }
×
302

303
    public static void prettyPrint(ExprEmpty e, Spacer spacer, StringBuilder sb, int indent) {
304
    }
×
305

306
    public static void prettyPrint(ExprFuncRef e, Spacer spacer, StringBuilder sb, int indent) {
307
        sb.append("function");
×
308
        spacer.addSpace(sb);
×
309
        if (!StringUtils.isBlank(e.getScopeName())) {
×
310
            sb.append(e.getScopeName());
×
311
            sb.append(".");
×
312
        }
313
        sb.append(e.getFuncName());
×
314
    }
×
315

316
    public static void prettyPrint(ExprFunctionCall e, Spacer spacer, StringBuilder sb, int indent) {
317
        printIndent(sb, indent);
×
318
        sb.append(e.getFuncName());
×
319
        sb.append("(");
×
320
        e.getArgs().prettyPrint(spacer, sb, indent);
×
321
        sb.append(")");
×
322
        printNewline(e, sb, indent);
×
323
    }
×
324

325
    public static void prettyPrint(ExprIncomplete e, Spacer spacer, StringBuilder sb, int indent) {
326
    }
×
327

328
    public static void prettyPrint(ExprInstanceOf e, Spacer spacer, StringBuilder sb, int indent) {
329
        e.getExpr().prettyPrint(spacer, sb, indent);
×
330
        spacer.addSpace(sb);
×
331
        sb.append("instanceof");
×
332
        spacer.addSpace(sb);
×
333
        e.getTyp().prettyPrint(spacer, sb, indent);
×
334
    }
×
335

336
    public static void prettyPrint(ExprIntVal e, Spacer spacer, StringBuilder sb, int indent) {
337
        sb.append(e.getValIraw());
1✔
338
    }
1✔
339

340
    public static void prettyPrint(ExprMemberArrayVarDot e, Spacer spacer, StringBuilder sb, int indent) {
341
        e.getLeft().prettyPrint(spacer, sb, indent);
×
342
        sb.append(".");
×
343
        sb.append(e.getVarName());
×
344
        sb.append("[");
×
345
        e.getIndexes().prettyPrint(spacer, sb, indent);
×
346
        sb.append("]");
×
347
    }
×
348

349
    public static void prettyPrint(ExprMemberArrayVarDotDot e, Spacer spacer, StringBuilder sb, int indent) {
350
        e.getLeft().prettyPrint(spacer, sb, indent);
×
351
        sb.append("..");
×
352
        sb.append(e.getVarName());
×
353
        sb.append("[");
×
354
        e.getIndexes().prettyPrint(spacer, sb, indent);
×
355
        sb.append("]");
×
356
    }
×
357

358
    public static void prettyPrint(ExprMemberMethodDot e, Spacer spacer, StringBuilder sb, int indent) {
359
        printIndent(sb, indent);
×
360
        if (e.getLeft() instanceof ExprBinary) {
×
361
            sb.append("(");
×
362
            e.getLeft().prettyPrint(spacer, sb, indent);
×
363
            sb.append(")");
×
364
        } else {
365
            e.getLeft().prettyPrint(spacer, sb, indent);
×
366
        }
367
        sb.append(".");
×
368
        sb.append(e.getFuncName());
×
369
        sb.append("(");
×
370
        e.getArgs().prettyPrint(spacer, sb, indent);
×
371
        sb.append(")");
×
372
        printNewline(e, sb, indent);
×
373
    }
×
374

375
    public static void prettyPrint(ExprMemberMethodDotDot e, Spacer spacer, StringBuilder sb, int indent) {
376
        if (e.getLeft() instanceof ExprBinary) {
×
377
            sb.append("(");
×
378
            e.getLeft().prettyPrint(spacer, sb, indent);
×
379
            sb.append(")");
×
380
        } else {
381
            e.getLeft().prettyPrint(spacer, sb, indent);
×
382
        }
383
        sb.append("\n");
×
384
        printIndent(sb, indent + 1);
×
385
        sb.append("..");
×
386
        sb.append(e.getFuncName());
×
387
        sb.append("(");
×
388
        e.getArgs().prettyPrint(spacer, sb, indent);
×
389
        sb.append(")");
×
390
        printNewline(e, sb, indent);
×
391
    }
×
392

393
    public static void prettyPrint(ExprMemberVarDot e, Spacer spacer, StringBuilder sb, int indent) {
394
        e.getLeft().prettyPrint(spacer, sb, indent);
×
395
        sb.append(".");
×
396
        sb.append(e.getVarName());
×
397
    }
×
398

399
    public static void prettyPrint(ExprMemberVarDotDot e, Spacer spacer, StringBuilder sb, int indent) {
400
        printIndent(sb, indent);
×
401
        e.getLeft().prettyPrint(spacer, sb, indent);
×
402
        sb.append("..");
×
403
        sb.append(e.getVarName());
×
404
    }
×
405

406
    public static void prettyPrint(ExprNewObject e, Spacer spacer, StringBuilder sb, int indent) {
407
        printIndent(sb, indent);
×
408
        sb.append("new");
×
409
        spacer.addSpace(sb);
×
410
        sb.append(e.getTypeName());
×
411
        e.getTypeArgs().prettyPrint(spacer, sb, indent);
×
412
        if (e.getArgs().size() > 0) {
×
413
            sb.append("(");
×
414
            e.getArgs().prettyPrint(spacer, sb, indent);
×
415
            sb.append(")");
×
416
        }
417
        printNewline(e, sb, indent);
×
418
    }
×
419

420
    public static void prettyPrint(ExprNull e, Spacer spacer, StringBuilder sb, int indent) {
421
        sb.append("null");
×
422
    }
×
423

424
    public static void prettyPrint(ExprRealVal e, Spacer spacer, StringBuilder sb, int indent) {
425
        sb.append(e.getValR());
×
426
    }
×
427

428
    public static void prettyPrint(ExprStatementsBlock e, Spacer spacer, StringBuilder sb, int indent) {
429
        sb.append("begin");
×
430
        sb.append("\n");
×
431
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
432
        printIndent(sb, indent);
×
433
        sb.append("end");
×
434
    }
×
435

436
    public static void prettyPrint(ExprStringVal e, Spacer spacer, StringBuilder sb, int indent) {
437
        sb.append(Utils.escapeString(e.getValS()));
×
438
    }
×
439

440
    public static void prettyPrint(ExprSuper e, Spacer spacer, StringBuilder sb, int indent) {
441
        printIndent(sb, indent);
×
442
        sb.append("super");
×
443
    }
×
444

445
    public static void prettyPrint(ExprThis e, Spacer spacer, StringBuilder sb, int indent) {
446
        printIndent(sb, indent);
×
447
        sb.append("this");
×
448
    }
×
449

450
    public static void prettyPrint(ExprTypeId e, Spacer spacer, StringBuilder sb, int indent) {
451
        e.getLeft().prettyPrint(spacer, sb, indent);
×
452
        sb.append(".typeId");
×
453
    }
×
454

455
    public static void prettyPrint(ExprUnary e, Spacer spacer, StringBuilder sb, int indent) {
456
        sb.append(e.getOpU().toString());
×
457
        // Don't add space for unary minus, e.g -1.
458
        if (e.getOpU().toString() == "not") {
×
459
            spacer.addSpace(sb);
×
460
        }
461
        e.getRight().prettyPrint(spacer, sb, indent);
×
462
    }
×
463

464
    public static void prettyPrint(ExprVarAccess e, Spacer spacer, StringBuilder sb, int indent) {
465
        printIndent(sb, indent);
1✔
466
        sb.append(e.getVarName());
1✔
467
    }
1✔
468

469
    public static void prettyPrint(ExprVarArrayAccess e, Spacer spacer, StringBuilder sb, int indent) {
470
        printIndent(sb, indent);
×
471
        sb.append(e.getVarName());
×
472
        sb.append("[");
×
473
        e.getIndexes().prettyPrint(spacer, sb, indent);
×
474
        sb.append("]");
×
475
    }
×
476

477
    public static void prettyPrint(ExtensionFuncDef e, Spacer spacer, StringBuilder sb, int indent) {
478
        printFirstNewline(e, sb, indent);
×
479
        printStuff(e, spacer, sb, indent);
×
480
        sb.append("function");
×
481
        spacer.addSpace(sb);
×
482
        e.getExtendedType().prettyPrint(spacer, sb, indent);
×
483
        sb.append(".");
×
484
        printFunctionSignature(e, spacer, sb, indent);
×
485
        sb.append("\n");
×
486
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
487
        printCommentsAfter(sb, e, indent);
×
488
    }
×
489

490

491
    private static void printFunctionSignature(FunctionImplementation e, Spacer spacer, StringBuilder sb, int indent) {
492
        sb.append(e.getName());
×
493
        e.getTypeParameters().prettyPrint(spacer, sb, indent);
×
494
        e.getParameters().prettyPrint(spacer, sb, indent);
×
495
        if (!(e.getReturnTyp() instanceof NoTypeExpr)) {
×
496
            spacer.addSpace(sb);
×
497
            sb.append("returns");
×
498
            spacer.addSpace(sb);
×
499
            e.getReturnTyp().prettyPrint(spacer, sb, indent);
×
500
        }
501
    }
×
502

503
    public static void prettyPrint(FuncDef e, Spacer spacer, StringBuilder sb, int indent) {
504
        printFirstNewline(e, sb, indent);
×
505
        printStuff(e, spacer, sb, indent);
×
506
        sb.append("function");
×
507
        spacer.addSpace(sb);
×
508
        printFunctionSignature(e, spacer, sb, indent);
×
509
        sb.append("\n");
×
510
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
511
        printCommentsAfter(sb, e, indent);
×
512
    }
×
513

514
    public static void prettyPrint(FuncDefs e, Spacer spacer, StringBuilder sb, int indent) {
515
        printFirstNewline(e, sb, indent);
×
516
        for (FuncDef funcDef : e) {
×
517
            funcDef.prettyPrint(spacer, sb, indent);
×
518
        }
×
519
    }
×
520

521
    public static void prettyPrint(GlobalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
522
        printStuff(e, spacer, sb, indent);
×
523
        if ((e.getOptTyp() instanceof NoTypeExpr)) {
×
524
            if (!e.attrIsConstant()) {
×
525
                sb.append("var");
×
526
            }
527
        } else {
528
            e.getOptTyp().prettyPrint(spacer, sb, indent);
×
529
        }
530
        spacer.addSpace(sb);
×
531
        sb.append(e.getName());
×
532
        if (!(e.getInitialExpr() instanceof NoExpr)) {
×
533
            spacer.addSpace(sb);
×
534
            sb.append("=");
×
535
            spacer.addSpace(sb);
×
536
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
×
537
        }
538
        sb.append("\n");
×
539
        printCommentsAfter(sb, e, indent);
×
540
    }
×
541

542
    public static void prettyPrint(GlobalVarDefs e, Spacer spacer, StringBuilder sb, int indent) {
543
        if (e.size() <= 0) {
×
544
            return;
×
545
        }
546
        for (GlobalVarDef varDef : e) {
×
547
            varDef.prettyPrint(spacer, sb, indent);
×
548
        }
×
549
        sb.append("\n");
×
550
    }
×
551

552
    public static void prettyPrint(IdentifierWithTypeArgs e, Spacer spacer, StringBuilder sb, int indent) {
553
    }
×
554

555
    public static void prettyPrint(IdentifierWithTypeParamDefs e, Spacer spacer, StringBuilder sb, int indent) {
556
    }
×
557

558
    public static void prettyPrint(Indexes e, Spacer spacer, StringBuilder sb, int indent) {
559
        for (Expr expr : e) {
×
560
            expr.prettyPrint(spacer, sb, indent);
×
561
        }
×
562
    }
×
563

564
    public static void prettyPrint(InitBlock e, Spacer spacer, StringBuilder sb, int indent) {
565
        printFirstNewline(e, sb, indent);
×
566
        printIndent(sb, indent);
×
567
        sb.append("init");
×
568
        sb.append("\n");
×
569
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
570
    }
×
571

572
    public static void prettyPrint(InterfaceDef e, Spacer spacer, StringBuilder sb, int indent) {
573
        printFirstNewline(e, sb, indent);
×
574
        printStuff(e, spacer, sb, indent);
×
575
        sb.append("interface");
×
576
        spacer.addSpace(sb);
×
577
        sb.append(e.getName());
×
578
        e.getTypeParameters().prettyPrint(spacer, sb, indent);
×
579
        if (e.getExtendsList().size() >= 1) {
×
580
            spacer.addSpace(sb);
×
581
            sb.append("extends");
×
582
            spacer.addSpace(sb);
×
583
            e.getExtendsList().prettyPrint(spacer, sb, indent);
×
584
        }
585
        e.getModuleUses().prettyPrint(spacer, sb, indent + 1);
×
586
        e.getVars().prettyPrint(spacer, sb, indent + 1);
×
587
        e.getConstructors().prettyPrint(spacer, sb, indent + 1);
×
588
        e.getMethods().prettyPrint(spacer, sb, indent + 1);
×
589
        e.getOnDestroy().prettyPrint(spacer, sb, indent + 1);
×
590
        printCommentsAfter(sb, e, indent);
×
591
    }
×
592

593

594
    public static void jassPrettyPrint(GlobalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
595
        printStuff(e, spacer, sb, indent);
×
596
        jassPrettyPrint(e.getOptTyp(), spacer, sb, indent);
×
597
        spacer.addSpace(sb);
×
598
        sb.append(e.getName());
×
599
        if (!(e.getInitialExpr() instanceof NoExpr)) {
×
600
            spacer.addSpace(sb);
×
601
            sb.append("=");
×
602
            spacer.addSpace(sb);
×
603
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
×
604
        }
605
        sb.append("\n");
×
606
        printCommentsAfter(sb, e, indent);
×
607
    }
×
608

609
    public static void jassPrettyPrint(OptTypeExpr e, Spacer spacer, StringBuilder sb, int indent) {
610
        if (e instanceof NoTypeExpr) {
×
611
            sb.append("nothing");
×
612
        } else if (e instanceof TypeExpr) {
×
613
            jassPrettyPrint((TypeExpr) e, spacer, sb, indent);
×
614
        }
615
    }
×
616

617
    public static void jassPrettyPrint(TypeExpr e, Spacer spacer, StringBuilder sb, int indent) {
618
        if (e instanceof NoTypeExpr) {
×
619
            sb.append("nothing");
×
620
        } else if (e instanceof TypeExprSimple) {
×
621
            sb.append(((TypeExprSimple) e).getTypeName());
×
622
        } else if (e instanceof TypeExprArray) {
×
623
            jassPrettyPrint(((TypeExprArray) e).getBase(), spacer, sb, indent);
×
624
            spacer.addSpace(sb);
×
625
            sb.append("array");
×
626
        }
627
    }
×
628

629
    public static void jassPrettyPrint(JassToplevelDeclarations e, Spacer spacer, StringBuilder sb, int indent) {
630
        for (int i = 0; i < e.size(); i++) {
×
631
            jassPrettyPrint(e.get(i), spacer, sb, indent);
×
632
        }
633
    }
×
634

635
    private static void jassPrettyPrint(JassToplevelDeclaration e, Spacer spacer, StringBuilder sb, int indent) {
636
        if (e instanceof JassGlobalBlock) {
×
637
            jassPrettyPrint((JassGlobalBlock) e, spacer, sb, indent);
×
638
        } else if (e instanceof NativeFunc) {
×
639
            jassPrettyPrint((NativeFunc) e, spacer, sb, indent);
×
640
        } else if (e instanceof FuncDef) {
×
641
            jassPrettyPrint((FuncDef) e, spacer, sb, indent);
×
642
        }
643
    }
×
644

645
    public static void jassPrettyPrint(FuncDef e, Spacer spacer, StringBuilder sb, int indent) {
646
        printFirstNewline(e, sb, indent);
×
647
        printStuff(e, spacer, sb, indent);
×
648
        sb.append("function");
×
649
        spacer.addSpace(sb);
×
650
        sb.append(e.getName());
×
651
        spacer.addSpace(sb);
×
652
        sb.append("takes");
×
653
        spacer.addSpace(sb);
×
654
        jassPrettyPrint(e.getParameters(), spacer, sb, indent);
×
655
        spacer.addSpace(sb);
×
656
        sb.append("returns");
×
657
        spacer.addSpace(sb);
×
658
        if (e.getReturnTyp() instanceof NoTypeExpr) {
×
659
            sb.append("nothing");
×
660
        } else {
661
            e.getReturnTyp().prettyPrint(spacer, sb, indent);
×
662
        }
663
        sb.append("\n");
×
664
        jassPrettyPrint(e.getBody(), spacer, sb, indent + 1);
×
665
        printCommentsAfter(sb, e, indent);
×
666
        sb.append("endfunction\n");
×
667
    }
×
668

669

670
    public static void jassPrettyPrint(WStatements e, Spacer spacer, StringBuilder sb, int indent) {
671
        for (int i = 0; i < e.size(); i++) {
×
672
            jassPrettyPrint(e.get(i), spacer, sb, indent);
×
673
        }
674
    }
×
675

676
    public static void jassPrettyPrint(WStatement e, Spacer spacer, StringBuilder sb, int indent) {
677
        if (e instanceof LocalVarDef) {
×
678
            jassPrettyPrint((LocalVarDef) e, spacer, sb, indent);
×
679
        } else if (e instanceof StmtSet) {
×
680
            jassPrettyPrint((StmtSet) e, spacer, sb, indent);
×
681
        } else if (e instanceof StmtCall) {
×
682
            jassPrettyPrint((StmtCall) e, spacer, sb, indent);
×
683
        } else if (e instanceof StmtIf) {
×
684
            jassPrettyPrint((StmtIf) e, spacer, sb, indent);
×
685
        } else if (e instanceof StmtReturn) {
×
686
            jassPrettyPrint((StmtReturn) e, spacer, sb, indent);
×
687
        } else if (e instanceof StmtLoop) {
×
688
            jassPrettyPrint((StmtLoop) e, spacer, sb, indent);
×
689
        } else if (e instanceof StmtExitwhen) {
×
690
            jassPrettyPrint((StmtExitwhen) e, spacer, sb, indent);
×
691
        }
692
    }
×
693

694
    public static void jassPrettyPrint(StmtExitwhen e, Spacer spacer, StringBuilder sb, int indent) {
695
        printIndent(sb, indent);
×
696
        sb.append("exitwhen");
×
697
        spacer.addSpace(sb);
×
698
        e.getCond().prettyPrint(spacer, sb, indent);
×
699
        sb.append("\n");
×
700
    }
×
701

702
    public static void jassPrettyPrint(StmtLoop e, Spacer spacer, StringBuilder sb, int indent) {
703
        printIndent(sb, indent);
×
704
        sb.append("loop\n");
×
705
        jassPrettyPrint(e.getBody(), spacer, sb, indent + 1);
×
706
        printIndent(sb, indent);
×
707
        sb.append("endloop\n");
×
708
    }
×
709

710
    public static void jassPrettyPrint(StmtReturn e, Spacer spacer, StringBuilder sb, int indent) {
711
        printIndent(sb, indent);
×
712
        sb.append("return");
×
713
        spacer.addSpace(sb);
×
714
        e.getReturnedObj().prettyPrint(spacer, sb, indent);
×
715
        sb.append("\n");
×
716
    }
×
717

718
    public static void jassPrettyPrint(StmtIf e, Spacer spacer, StringBuilder sb, int indent) {
719
        printIndent(sb, indent);
×
720
        sb.append("if");
×
721
        spacer.addSpace(sb);
×
722
        e.getCond().prettyPrint(spacer, sb, indent);
×
723
        spacer.addSpace(sb);
×
724
        sb.append("then\n");
×
725
        jassPrettyPrint(e.getThenBlock(), spacer, sb, indent + 1);
×
726
        if (e.getElseBlock().size() > 0) {
×
727
            printIndent(sb, indent);
×
728
            sb.append("else");
×
729
            if (e.getElseBlock().size() == 1 && e.getElseBlock().get(0) instanceof StmtIf) {
×
730
                jassPrettyPrint(e.getElseBlock().get(0), spacer, sb, indent);
×
731
            } else {
732
                sb.append("\n");
×
733
                jassPrettyPrint(e.getElseBlock(), spacer, sb, indent + 1);
×
734
                printIndent(sb, indent);
×
735
                sb.append("endif\n");
×
736
            }
737
        } else {
738
            printIndent(sb, indent);
×
739
            sb.append("endif\n");
×
740
        }
741

742
    }
×
743

744
    public static void jassPrettyPrint(StmtCall e, Spacer spacer, StringBuilder sb, int indent) {
745
        if (e instanceof FunctionCall) {
×
746
            jassPrettyPrint((FunctionCall) e, spacer, sb, indent);
×
747
        }
748
    }
×
749

750
    public static void jassPrettyPrint(FunctionCall e, Spacer spacer, StringBuilder sb, int indent) {
751
        printIndent(sb, indent);
×
752
        sb.append("call");
×
753
        spacer.addSpace(sb);
×
754
        sb.append(e.getFuncName());
×
755
        sb.append("(");
×
756
        jassPrettyPrint(e.getArgs(), spacer, sb, indent);
×
757
        sb.append(")");
×
758
        sb.append("\n");
×
759
    }
×
760

761
    public static void jassPrettyPrint(Arguments e, Spacer spacer, StringBuilder sb, int indent) {
762
        commaSeparatedList(e, spacer, sb, indent);
×
763
    }
×
764

765
    public static void jassPrettyPrint(StmtSet e, Spacer spacer, StringBuilder sb, int indent) {
766
        printIndent(sb, indent);
×
767
        sb.append("set");
×
768
        spacer.addSpace(sb);
×
769
        e.getUpdatedExpr().prettyPrint(spacer, sb, indent);
×
770
        spacer.addSpace(sb);
×
771
        sb.append("=");
×
772
        spacer.addSpace(sb);
×
773
        e.getRight().prettyPrint(spacer, sb, indent);
×
774
        sb.append("\n");
×
775
    }
×
776

777

778
    public static void jassPrettyPrint(LocalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
779
        printCommentsBefore(sb, e, indent);
×
780
        printIndent(sb, indent);
×
781
        sb.append("local");
×
782
        spacer.addSpace(sb);
×
783
        e.getOptTyp().prettyPrint(spacer, sb, indent);
×
784
        spacer.addSpace(sb);
×
785
        sb.append(e.getName());
×
786
        if (!(e.getInitialExpr() instanceof NoExpr)) {
×
787
            spacer.addSpace(sb);
×
788
            sb.append("=");
×
789
            spacer.addSpace(sb);
×
790
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
×
791
        }
792
        printNewline(e, sb, indent);
×
793
        printCommentsAfter(sb, e, indent);
×
794
    }
×
795

796
    public static void jassPrettyPrint(JassGlobalBlock e, Spacer spacer, StringBuilder sb, int indent) {
797
        sb.append("globals\n");
×
798
        for (int i = 0; i < e.size(); i++) {
×
799
            jassPrettyPrint(e.get(i), spacer, sb, indent + 1);
×
800
        }
801
        sb.append("endglobals\n");
×
802
    }
×
803

804
    public static void jassPrettyPrint(WParameters wParameters, Spacer spacer, StringBuilder sb, int indent) {
805
        if (wParameters.size() == 0) {
×
806
            sb.append("nothing");
×
807
            return;
×
808
        }
809
        String prefix = "";
×
810
        for (WParameter wParameter : wParameters) {
×
811
            sb.append(prefix);
×
812
            prefix = ",";
×
813
            spacer.addSpace(sb);
×
814
            wParameter.prettyPrint(spacer, sb, indent);
×
815
        }
×
816
    }
×
817

818
    public static void jassPrettyPrint(NativeFunc e, Spacer spacer, StringBuilder sb, int indent) {
819
        printStuff(e, spacer, sb, indent);
×
820
        sb.append("native");
×
821
        spacer.addSpace(sb);
×
822
        e.getNameId().prettyPrint(spacer, sb, indent);
×
823
        spacer.addSpace(sb);
×
824
        sb.append("takes");
×
825
        spacer.addSpace(sb);
×
826
        jassPrettyPrint(e.getParameters(), spacer, sb, indent);
×
827
        spacer.addSpace(sb);
×
828
        sb.append("returns");
×
829
        spacer.addSpace(sb);
×
830
        e.getReturnTyp().prettyPrint(spacer, sb, indent);
×
831
        sb.append("\n");
×
832
        printCommentsAfter(sb, e, indent);
×
833
    }
×
834

835
    public static void prettyPrint(LocalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
836
        printCommentsBefore(sb, e, indent);
×
837
        printIndent(sb, indent);
×
838
        if ((e.getOptTyp() instanceof NoTypeExpr)) {
×
839
            if (e.attrIsConstant()) {
×
840
                sb.append("let");
×
841
            } else if (!(e.getParent() instanceof StmtForRange)) {
×
842
                sb.append("var");
×
843
            }
844
        } else {
845
            e.getOptTyp().prettyPrint(spacer, sb, indent);
×
846
        }
847
        spacer.addSpace(sb);
×
848
        sb.append(e.getName());
×
849
        if (!(e.getInitialExpr() instanceof NoExpr)) {
×
850
            spacer.addSpace(sb);
×
851
            sb.append("=");
×
852
            spacer.addSpace(sb);
×
853
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
×
854
        }
855
        printNewline(e, sb, indent);
×
856
        printCommentsAfter(sb, e, indent);
×
857
    }
×
858

859
    public static void prettyPrint(ModAbstract e, Spacer spacer, StringBuilder sb, int indent) {
860
        sb.append("abstract");
×
861
    }
×
862

863
    public static void prettyPrint(ModConstant e, Spacer spacer, StringBuilder sb, int indent) {
864
        sb.append("constant");
×
865
    }
×
866

867
    public static void prettyPrint(ModVararg e, Spacer spacer, StringBuilder sb, int indent) {
868
        sb.append("vararg");
×
869
    }
×
870

871
    public static void prettyPrint(Modifiers e, Spacer spacer, StringBuilder sb, int indent) {
872
        for (Modifier modifier : e) {
1✔
873
            // We handle WurstDoc separately.
874
            if (!(modifier instanceof WurstDoc)) {
×
875
                modifier.prettyPrint(spacer, sb, indent);
×
876
                spacer.addSpace(sb);
×
877
            }
878
        }
×
879
    }
1✔
880

881
    public static void prettyPrint(ModOverride e, Spacer spacer, StringBuilder sb, int indent) {
882
        sb.append("override");
×
883
    }
×
884

885
    public static void prettyPrint(ModStatic e, Spacer spacer, StringBuilder sb, int indent) {
886
        sb.append("static");
×
887
    }
×
888

889
    public static void prettyPrint(ModuleDef e, Spacer spacer, StringBuilder sb, int indent) {
890
        printFirstNewline(e, sb, indent);
×
891
        printStuff(e, spacer, sb, indent);
×
892
        sb.append("module");
×
893
        spacer.addSpace(sb);
×
894
        e.getNameId().prettyPrint(spacer, sb, indent);
×
895
        sb.append("\n");
×
896
        printClassOrModuleDeclaration(e, spacer, sb, indent + 1);
×
897
        printCommentsAfter(sb, e, indent);
×
898
    }
×
899

900
    public static void prettyPrint(ModuleInstanciation e, Spacer spacer, StringBuilder sb, int indent) {
901
        printCommentsBefore(sb, e, indent);
×
902
    }
×
903

904
    public static void prettyPrint(ModuleInstanciations e, Spacer spacer, StringBuilder sb, int indent) {
905
    }
×
906

907
    public static void prettyPrint(ModuleUse e, Spacer spacer, StringBuilder sb, int indent) {
908
        printIndent(sb, indent);
×
909
        sb.append("use");
×
910
        spacer.addSpace(sb);
×
911
        sb.append(e.getModuleName());
×
912
        sb.append("\n");
×
913
    }
×
914

915
    public static void prettyPrint(ModuleUses e, Spacer spacer, StringBuilder sb, int indent) {
916
        for (ModuleUse moduleUse : e) {
×
917
            moduleUse.prettyPrint(spacer, sb, indent);
×
918
        }
×
919
    }
×
920

921
    public static void prettyPrint(NativeFunc e, Spacer spacer, StringBuilder sb, int indent) {
922
        printStuff(e, spacer, sb, indent);
×
923
        sb.append("native");
×
924
        spacer.addSpace(sb);
×
925
        e.getNameId().prettyPrint(spacer, sb, indent);
×
926
        e.getParameters().prettyPrint(spacer, sb, indent);
×
927
        if (!(e.getReturnTyp() instanceof NoTypeExpr)) {
×
928
            spacer.addSpace(sb);
×
929
            sb.append("returns");
×
930
            spacer.addSpace(sb);
×
931
            e.getReturnTyp().prettyPrint(spacer, sb, indent);
×
932
        }
933
        sb.append("\n");
×
934
        printCommentsAfter(sb, e, indent);
×
935
    }
×
936

937
    public static void prettyPrint(NativeType e, Spacer spacer, StringBuilder sb, int indent) {
938
        printStuff(e, spacer, sb, indent);
×
939
        sb.append("nativetype");
×
940
        spacer.addSpace(sb);
×
941
        e.getNameId().prettyPrint(spacer, sb, indent);
×
942
        sb.append("\n");
×
943
        printCommentsAfter(sb, e, indent);
×
944
    }
×
945

946
    public static void prettyPrint(NoDefaultCase e, Spacer spacer, StringBuilder sb, int indent) {
947
    }
×
948

949
    public static void prettyPrint(NoExpr e, Spacer spacer, StringBuilder sb, int indent) {
950
    }
×
951

952
    public static void prettyPrint(NoTypeExpr e, Spacer spacer, StringBuilder sb, int indent) {
953
    }
×
954

955
    public static void prettyPrint(OnDestroyDef e, Spacer spacer, StringBuilder sb, int indent) {
956
        if (e.getBody().size() <= 0) {
×
957
            return;
×
958
        }
959
        printFirstNewline(e, sb, indent);
×
960
        printIndent(sb, indent);
×
961
        sb.append("ondestroy");
×
962
        sb.append("\n");
×
963
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
964
    }
×
965

966
    public static void prettyPrint(StartFunctionStatement e, Spacer spacer, StringBuilder sb, int indent) {
967
    }
1✔
968

969
    public static void prettyPrint(StmtErr e, Spacer spacer, StringBuilder sb, int indent) {
970
    }
×
971

972
    public static void prettyPrint(StmtExitwhen e, Spacer spacer, StringBuilder sb, int indent) {
973
        printIndent(sb, indent);
×
974
        sb.append("break");
×
975
        sb.append("\n");
×
976
    }
×
977

978
    public static void prettyPrint(StmtForFrom e, Spacer spacer, StringBuilder sb, int indent) {
979
        forIteratorLoop("from", e, e.getIn(), spacer, sb, indent);
×
980
    }
×
981

982
    public static void prettyPrint(StmtForIn e, Spacer spacer, StringBuilder sb, int indent) {
983
        forIteratorLoop("in", e, e.getIn(), spacer, sb, indent);
×
984
    }
×
985

986
    private static void forIteratorLoop(String method, LoopStatementWithVarDef e, Expr target, Spacer spacer, StringBuilder sb, int indent) {
987
        printIndent(sb, indent);
×
988
        sb.append("for");
×
989
        spacer.addSpace(sb);
×
990
        e.getLoopVar().getNameId().prettyPrint(spacer, sb, indent);
×
991
        spacer.addSpace(sb);
×
992
        sb.append(method);
×
993
        spacer.addSpace(sb);
×
994
        target.prettyPrint(spacer, sb, indent);
×
995
        sb.append("\n");
×
996
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
997
    }
×
998

999
    private static void forRangeLoop(String direction, StmtForRange e, Spacer spacer, StringBuilder sb, int indent) {
1000
        printIndent(sb, indent);
×
1001
        sb.append("for");
×
1002
        spacer.addSpace(sb);
×
1003
        e.getLoopVar().prettyPrint(spacer, sb, indent);
×
1004
        spacer.addSpace(sb);
×
1005
        sb.append(direction);
×
1006
        spacer.addSpace(sb);
×
1007
        e.getTo().prettyPrint(spacer, sb, indent);
×
1008
        if (e.getStep() instanceof ExprIntVal && ((ExprIntVal) e.getStep()).getValI() != 1) {
×
1009
            spacer.addSpace(sb);
×
1010
            sb.append("step");
×
1011
            spacer.addSpace(sb);
×
1012
            e.getStep().prettyPrint(spacer, sb, indent);
×
1013
        }
1014
        sb.append("\n");
×
1015
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
1016
    }
×
1017

1018
    public static void prettyPrint(StmtForRangeDown e, Spacer spacer, StringBuilder sb, int indent) {
1019
        forRangeLoop("downto", e, spacer, sb, indent);
×
1020
    }
×
1021

1022
    public static void prettyPrint(StmtForRangeUp e, Spacer spacer, StringBuilder sb, int indent) {
1023
        forRangeLoop("to", e, spacer, sb, indent);
×
1024
    }
×
1025

1026
    public static void prettyPrint(StmtIf e, Spacer spacer, StringBuilder sb, int indent) {
1027
        printIndent(sb, indent);
×
1028
        sb.append("if");
×
1029
        spacer.addSpace(sb);
×
1030
        e.getCond().prettyPrint(spacer, sb, indent);
×
1031
        sb.append("\n");
×
1032
        e.getThenBlock().prettyPrint(spacer, sb, indent + 1);
×
1033
        if (e.getElseBlock().size() > 0) {
×
1034
            printIndent(sb, indent);
×
1035
            sb.append("else");
×
1036
            if (e.getElseBlock().size() > 0 && e.getElseBlock().get(0) instanceof StmtIf) {
×
1037
                spacer.addSpace(sb);
×
1038
                e.getElseBlock().get(0).prettyPrint(spacer, sb, indent);
×
1039
            } else {
1040
                sb.append("\n");
×
1041
                e.getElseBlock().prettyPrint(spacer, sb, indent + 1);
×
1042
            }
1043
        }
1044
    }
×
1045

1046
    public static void prettyPrint(StmtLoop e, Spacer spacer, StringBuilder sb, int indent) {
1047
    }
×
1048

1049
    public static void prettyPrint(StmtReturn e, Spacer spacer, StringBuilder sb, int indent) {
1050
        printIndent(sb, indent);
×
1051
        sb.append("return");
×
1052
        spacer.addSpace(sb);
×
1053
        e.getReturnedObj().prettyPrint(spacer, sb, indent);
×
1054
        sb.append("\n");
×
1055
    }
×
1056

1057
    private static boolean printAssignmentShorthands(Expr left, Expr right, Spacer spacer, StringBuilder sb, int indent) {
1058
        if (!(right instanceof ExprBinary)) {
1✔
1059
            return false;
1✔
1060
        }
1061

1062
        if (!(left.toString().equals(((ExprBinary) right).getLeft().toString()))) {
×
1063
            return false;
×
1064
        }
1065

1066
        String operator = ((ExprBinary) right).getOp().toString();
×
1067
        Expr val = ((ExprBinary) right).getRight();
×
1068

1069
        // i++ and i--
1070
        if (val instanceof ExprIntVal
×
1071
            && ((ExprIntVal) val).getValI() == 1
×
1072
            && (operator.equals("+") || operator.equals("-"))) {
×
1073
            sb.append(operator);
×
1074
            sb.append(operator);
×
1075
            return true;
×
1076
        }
1077

1078
        // i +=, ...
1079
        spacer.addSpace(sb);
×
1080
        sb.append(operator);
×
1081
        sb.append("=");
×
1082
        spacer.addSpace(sb);
×
1083
        val.prettyPrint(spacer, sb, indent);
×
1084
        return true;
×
1085
    }
1086

1087
    public static void prettyPrint(StmtSet e, Spacer spacer, StringBuilder sb, int indent) {
1088
        printIndent(sb, indent);
1✔
1089
        e.getUpdatedExpr().prettyPrint(spacer, sb, indent);
1✔
1090

1091
        // Special cases for assignment shorthands i++ and i += variants.
1092
        boolean shortened = printAssignmentShorthands(e.getUpdatedExpr(), e.getRight(), spacer, sb, indent);
1✔
1093

1094
        if (!shortened) {
1✔
1095
            spacer.addSpace(sb);
1✔
1096
            sb.append("=");
1✔
1097
            spacer.addSpace(sb);
1✔
1098
            e.getRight().prettyPrint(spacer, sb, indent);
1✔
1099
        }
1100
        sb.append("\n");
1✔
1101
    }
1✔
1102

1103
    public static void prettyPrint(StmtSkip e, Spacer spacer, StringBuilder sb, int indent) {
1104
        printIndent(sb, indent);
×
1105
        sb.append("skip");
×
1106
        sb.append("\n");
×
1107
    }
×
1108

1109
    public static void prettyPrint(StmtWhile e, Spacer spacer, StringBuilder sb, int indent) {
1110
        printIndent(sb, indent);
×
1111
        sb.append("while");
×
1112
        spacer.addSpace(sb);
×
1113
        e.getCond().prettyPrint(spacer, sb, indent);
×
1114
        sb.append("\n");
×
1115
        e.getBody().prettyPrint(spacer, sb, indent + 1);
×
1116
    }
×
1117

1118
    public static void prettyPrint(SwitchCase e, Spacer spacer, StringBuilder sb, int indent) {
1119
        printIndent(sb, indent);
×
1120
        sb.append("case");
×
1121
        spacer.addSpace(sb);
×
1122
        e.getExpressions().prettyPrint(spacer, sb, indent);
×
1123
        sb.append("\n");
×
1124
        e.getStmts().prettyPrint(spacer, sb, indent + 1);
×
1125
    }
×
1126

1127
    public static void prettyPrint(SwitchCases sw, Spacer spacer, StringBuilder sb, int indent) {
1128
        for (SwitchCase c : sw) {
×
1129
            c.prettyPrint(spacer, sb, indent);
×
1130
        }
×
1131
    }
×
1132

1133
    public static void prettyPrint(SwitchDefaultCaseStatements e, Spacer spacer, StringBuilder sb, int indent) {
1134
        printIndent(sb, indent);
×
1135
        sb.append("default");
×
1136
        sb.append("\n");
×
1137
        e.getStmts().prettyPrint(spacer, sb, indent + 1);
×
1138
    }
×
1139

1140
    public static void prettyPrint(SwitchStmt sw, Spacer spacer, StringBuilder sb, int indent) {
1141
        printIndent(sb, indent);
×
1142
        sb.append("switch");
×
1143
        spacer.addSpace(sb);
×
1144
        sw.getExpr().prettyPrint(spacer, sb, indent);
×
1145
        sb.append("\n");
×
1146
        sw.getCases().prettyPrint(spacer, sb, indent + 1);
×
1147
        sw.getSwitchDefault().prettyPrint(spacer, sb, indent + 1);
×
1148
    }
×
1149

1150
    public static void prettyPrint(TopLevelDeclarations e, Spacer spacer, StringBuilder sb, int indent) {
1151
    }
×
1152

1153
    public static void prettyPrint(TupleDef e, Spacer spacer, StringBuilder sb, int indent) {
1154
        printStuff(e, spacer, sb, indent);
×
1155
        spacer.addSpace(sb);
×
1156
        sb.append("tuple");
×
1157
        spacer.addSpace(sb);
×
1158
        e.getNameId().prettyPrint(spacer, sb, indent);
×
1159
        e.getParameters().prettyPrint(spacer, sb, indent);
×
1160
        sb.append("\n");
×
1161
        printCommentsAfter(sb, e, indent);
×
1162
    }
×
1163

1164
    public static void prettyPrint(TypeExprArray e, Spacer spacer, StringBuilder sb, int indent) {
1165
        e.getBase().prettyPrint(spacer, sb, indent);
×
1166
        spacer.addSpace(sb);
×
1167
        sb.append("array");
×
1168
    }
×
1169

1170
    public static void prettyPrint(TypeExprList typeExprList, Spacer spacer, StringBuilder sb, int indent) {
1171
        if (typeExprList.size() == 0) {
×
1172
            return;
×
1173
        }
1174
        sb.append("<");
×
1175
        commaSeparatedList(typeExprList, spacer, sb, indent);
×
1176
        sb.append(">");
×
1177
    }
×
1178

1179
    public static void prettyPrint(TypeExprResolved e, Spacer spacer, StringBuilder sb, int indent) {
1180
    }
×
1181

1182
    public static void prettyPrint(TypeExprSimple e, Spacer spacer, StringBuilder sb, int indent) {
1183
        sb.append(e.getTypeName());
×
1184
        e.getTypeArgs().prettyPrint(spacer, sb, indent);
×
1185
    }
×
1186

1187
    public static void prettyPrint(TypeExprThis e, Spacer spacer, StringBuilder sb, int indent) {
1188
        if (!(e.getScopeType() instanceof NoTypeExpr)) {
×
1189
            e.getScopeType().prettyPrint(spacer, sb, indent);
×
1190
            sb.append(".");
×
1191
        }
1192
        sb.append("thistype");
×
1193
    }
×
1194

1195
    public static void prettyPrint(TypeParamDef e, Spacer spacer, StringBuilder sb, int indent) {
1196
        printCommentsBefore(sb, e, indent);
×
1197
        e.getNameId().prettyPrint(spacer, sb, indent);
×
1198
        printCommentsAfter(sb, e, indent);
×
1199
    }
×
1200

1201
    public static void prettyPrint(TypeParamDefs e, Spacer spacer, StringBuilder sb, int indent) {
1202
        if (e.size() >= 1) {
×
1203
            sb.append("<");
×
1204
            commaSeparatedList(e, spacer, sb, indent);
×
1205
            sb.append(">");
×
1206
        }
1207
    }
×
1208

1209
    public static void prettyPrint(VisibilityDefault e, Spacer spacer, StringBuilder sb, int indent) {
1210
    }
×
1211

1212
    public static void prettyPrint(VisibilityPrivate e, Spacer spacer, StringBuilder sb, int indent) {
1213
        sb.append("private");
×
1214
    }
×
1215

1216
    public static void prettyPrint(VisibilityProtected e, Spacer spacer, StringBuilder sb, int indent) {
1217
        sb.append("protected");
×
1218
    }
×
1219

1220
    public static void prettyPrint(VisibilityPublic e, Spacer spacer, StringBuilder sb, int indent) {
1221
        sb.append("public");
×
1222
    }
×
1223

1224
    public static void prettyPrint(VisibilityPublicread e, Spacer spacer, StringBuilder sb, int indent) {
1225
        sb.append("publicread");
×
1226
    }
×
1227

1228
    public static void prettyPrint(WBlock wBlock, Spacer spacer, StringBuilder sb, int indent) {
1229
        // TODO Auto-generated method stub
1230
        throw new Error("not implemented");
×
1231
    }
1232

1233
    public static void prettyPrint(WEntities wEntities, Spacer spacer, StringBuilder sb, int indent) {
1234
        for (WEntity entity : wEntities) {
×
1235
            entity.prettyPrint(spacer, sb, indent);
×
1236
        }
×
1237
    }
×
1238

1239
    public static void prettyPrint(WImport wImport, Spacer spacer, StringBuilder sb, int indent) {
1240
        sb.append("import");
×
1241
        spacer.addSpace(sb);
×
1242
        sb.append(wImport.getIsInitLater() ? "initlater" : "");
×
1243
        spacer.addSpace(sb);
×
1244
        sb.append(wImport.getIsPublic() ? "public" : "");
×
1245
        spacer.addSpace(sb);
×
1246
        sb.append(wImport.getPackagename());
×
1247
        sb.append("\n");
×
1248
    }
×
1249

1250
    public static void prettyPrint(WurstModel wurstModel, Spacer spacer, StringBuilder sb, int indent) {
1251
        for (CompilationUnit compilationUnit : wurstModel) {
×
1252
            compilationUnit.prettyPrint(spacer, sb, indent);
×
1253
        }
×
1254
    }
×
1255

1256
    private static String spaces(int indentation) {
1257
        return " " + "{" + indentation + "}";
×
1258
    }
1259

1260
    public static void prettyPrint(WurstDoc wurstDoc, Spacer spacer, StringBuilder sb, int indent) {
1261
        printIndent(sb, indent);
×
1262
        sb.append(wurstDoc.getRawComment());
×
1263
        sb.append("\n");
×
1264
    }
×
1265

1266
    public static void prettyPrint(WStatements wStatements, Spacer spacer, StringBuilder sb, int indent) {
1267
        for (WStatement wStatement : wStatements) {
1✔
1268
            wStatement.prettyPrint(spacer, sb, indent);
1✔
1269
        }
1✔
1270
    }
1✔
1271

1272
    public static void prettyPrint(WParameters wParameters, Spacer spacer, StringBuilder sb, int indent) {
1273
        sb.append("(");
1✔
1274
        String prefix = "";
1✔
1275
        for (WParameter wParameter : wParameters) {
1✔
1276
            sb.append(prefix);
×
1277
            prefix = ",";
×
1278
            spacer.addSpace(sb);
×
1279
            wParameter.prettyPrint(spacer, sb, indent);
×
1280
        }
×
1281
        sb.append(")");
1✔
1282
    }
1✔
1283

1284
    public static void prettyPrint(WShortParameters wParameters, Spacer spacer, StringBuilder sb, int indent) {
1285
        sb.append("(");
×
1286
        String prefix = "";
×
1287
        for (WShortParameter wParameter : wParameters) {
×
1288
            sb.append(prefix);
×
1289
            prefix = ",";
×
1290
            spacer.addSpace(sb);
×
1291
            wParameter.prettyPrint(spacer, sb, indent);
×
1292
        }
×
1293
        sb.append(")");
×
1294
    }
×
1295

1296
    public static void prettyPrint(WParameter wParameter, Spacer spacer, StringBuilder sb, int indent) {
1297
        wParameter.getTyp().prettyPrint(spacer, sb, indent);
×
1298
        spacer.addSpace(sb);
×
1299
        sb.append(wParameter.getName());
×
1300
    }
×
1301

1302
    public static void prettyPrint(WShortParameter wParameter, Spacer spacer, StringBuilder sb, int indent) {
1303
        OptTypeExpr t = wParameter.getTypOpt();
×
1304
        if (t instanceof TypeExpr) {
×
1305
            t.prettyPrint(spacer, sb, indent);
×
1306
            spacer.addSpace(sb);
×
1307
        }
1308
        sb.append(wParameter.getName());
×
1309
    }
×
1310

1311
    public static void prettyPrint(WPackages wPackages, Spacer spacer, StringBuilder sb, int indent) {
1312
        for (WPackage wPackage : wPackages) {
×
1313
            wPackage.prettyPrint(spacer, sb, indent);
×
1314
        }
×
1315
    }
×
1316

1317
    public static void prettyPrint(WPackage wPackage, Spacer spacer, StringBuilder sb, int indent) {
1318
        printCommentsBefore(sb, wPackage, indent);
×
1319
        sb.append("package");
×
1320
        spacer.addSpace(sb);
×
1321
        sb.append(wPackage.getName());
×
1322
        sb.append("\n\n");
×
1323
        wPackage.getImports().prettyPrint(spacer, sb, indent);
×
1324
        wPackage.getElements().prettyPrint(spacer, sb, indent);
×
1325
        printCommentsAfter(sb, wPackage, indent);
×
1326
    }
×
1327

1328
    public static void prettyPrint(WImports wImports, Spacer spacer, StringBuilder sb, int indent) {
1329
        if (wImports.size() <= 0) {
×
1330
            return;
×
1331
        }
1332
        for (WImport wImport : wImports) {
×
1333
            if (!wImport.getPackagename().equals("Wurst")) {
×
1334
                wImport.prettyPrint(spacer, sb, indent);
×
1335
            }
1336
        }
×
1337
        sb.append("\n");
×
1338
    }
×
1339

1340
    public static void prettyPrint(ClassDefs classDefs, Spacer spacer, StringBuilder sb, int indent) {
1341
        for (ClassDef classDef : classDefs) {
×
1342
            classDef.prettyPrint(spacer, sb, indent);
×
1343
        }
×
1344
    }
×
1345

1346
    public static void prettyPrint(Identifier identifier, Spacer spacer, StringBuilder sb, int indent) {
1347
        sb.append(identifier.getName());
×
1348
    }
×
1349

1350
    public static void prettyPrint(ExprIfElse e, Spacer spacer, StringBuilder sb, int indent) {
1351
        boolean shouldBracket = e.getParent() instanceof ExprBinary;
×
1352
        if (shouldBracket) {
×
1353
            sb.append("(");
×
1354
        }
1355
        e.getCond().prettyPrint(spacer, sb, indent);
×
1356
        spacer.addSpace(sb);
×
1357
        sb.append("?");
×
1358
        spacer.addSpace(sb);
×
1359
        e.getIfTrue().prettyPrint(spacer, sb, indent);
×
1360
        spacer.addSpace(sb);
×
1361
        sb.append(":");
×
1362
        spacer.addSpace(sb);
×
1363
        e.getIfFalse().prettyPrint(spacer, sb, indent);
×
1364
        if (shouldBracket) {
×
1365
            sb.append(")");
×
1366
        }
1367
    }
×
1368

1369
    public static void prettyPrint(ArrayInitializer arrayInitializer, Spacer spacer, StringBuilder sb, int indent) {
1370
        sb.append("[");
×
1371
        arrayInitializer.getValues().prettyPrint(spacer, sb, indent);
×
1372
        sb.append("]");
×
1373
    }
×
1374

1375
    public static void prettyPrint(NoSuperConstructorCall noSuperConstructorCall, Spacer spacer, StringBuilder sb, int indent) {
1376
        // nothing
1377
    }
1✔
1378

1379
    public static void prettyPrint(SomeSuperConstructorCall c, Spacer spacer, StringBuilder sb, int indent) {
1380
        printIndent(sb, indent + 1);
×
1381
        sb.append("super(");
×
1382
        c.getSuperArgs().prettyPrint(spacer, sb, indent);
×
1383
        sb.append(")\n");
×
1384

1385
    }
×
1386

1387
    public static void prettyPrint(NoTypeParamConstraints noTypeParamConstraints, Spacer spacer, StringBuilder sb, int indent) {
1388
        // nothing
1389
    }
×
1390
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc