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

wurstscript / WurstScript / 271

29 Sep 2025 12:12PM UTC coverage: 64.649% (+2.4%) from 62.222%
271

Pull #1096

circleci

Frotty
Merge branch 'perf-improvements' of https://github.com/wurstscript/WurstScript into perf-improvements
Pull Request #1096: Perf improvements

18202 of 28155 relevant lines covered (64.65%)

0.65 hits per line

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

58.57
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.WurstOperator;
4
import de.peeeq.wurstscript.ast.*;
5
import de.peeeq.wurstscript.ast.Element;
6
import de.peeeq.wurstscript.jassAst.*;
7
import de.peeeq.wurstscript.parser.WPos;
8
import de.peeeq.wurstscript.parser.WPosWithComments;
9
import de.peeeq.wurstscript.parser.WPosWithComments.Comment;
10
import de.peeeq.wurstscript.utils.Utils;
11
import org.apache.commons.lang.StringUtils;
12

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

15
public class PrettyPrinter {
×
16

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

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

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

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

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

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

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

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

106

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

224
    public static int precedence(WurstOperator op) {
225
        // Higher number = binds tighter
226
        // 5: unary (not, unary minus)
227
        // 4: * / % (mod)
228
        // 3: + -
229
        // 2: comparisons (<= >= > < == !=)
230
        // 1: or
231
        // 0: and
232
        switch (op) {
1✔
233
            case NOT:
234
            case UNARY_MINUS:
235
                return 5;
×
236

237
            case MULT:
238
            case DIV_INT:
239
            case DIV_REAL:
240
            case MOD_INT:
241
            case MOD_REAL:
242
                return 4;
1✔
243

244
            case PLUS:
245
            case MINUS:
246
                return 3;
1✔
247

248
            case LESS:
249
            case LESS_EQ:
250
            case GREATER:
251
            case GREATER_EQ:
252
            case EQ:
253
            case NOTEQ:
254
                return 2;
1✔
255

256
            case OR:
257
                return 1;
×
258

259
            case AND:
260
                return 0;
1✔
261
        }
262
        // Fallback if new ops appear
263
        return 0;
×
264
    }
265

266

267
    public static void prettyPrint(ExprBinary e, Spacer spacer, StringBuilder sb, int indent) {
268
        boolean useParanthesesLeft = false;
1✔
269
        boolean useParanthesesRight = false;
1✔
270
        if (e.getLeft() instanceof ExprBinary) {
1✔
271
            ExprBinary left = (ExprBinary) e.getLeft();
1✔
272
            if (precedence(left.getOp()) < precedence(e.getOp())) {
1✔
273
                // if the precedence level on the left is _smaller_ we have to use parentheses
274
                useParanthesesLeft = true;
×
275
            }
276
            // if the precedence level is equal we can assume left associativity of all operators
277
            // so they are treated correctly
278
        } else if (e.getLeft() instanceof ExprUnary) {
1✔
279
            useParanthesesLeft = true;
×
280
        }
281
        if (e.getRight() instanceof ExprBinary) {
1✔
282
            ExprBinary right = (ExprBinary) e.getRight();
1✔
283
            WurstOperator op = right.getOp();
1✔
284
            WurstOperator op2 = e.getOp();
1✔
285
            if (precedence(op) < precedence(op2)) {
1✔
286
                // if the precedence level on the right is smaller we have to use parentheses
287
                useParanthesesRight = true;
×
288
            } else if (precedence(op) == precedence(op2)) {
1✔
289
                // if the precedence level is equal we have to parentheses as operators are
290
                // left associative but for commutative operators (+, *, and, or) we do not
291
                // need parentheses
292

293
                if (!((op == WurstOperator.PLUS && op2 == WurstOperator.PLUS)
×
294
                    || (op == WurstOperator.MULT && op2 == WurstOperator.MULT)
295
                    || (op == WurstOperator.OR && op2 == WurstOperator.OR)
296
                    || (op == WurstOperator.AND && op2 == WurstOperator.AND))) {
297
                    // in other cases use parentheses
298
                    // for example
299
                    useParanthesesRight = true;
×
300
                }
301
            }
302
        } else if (e.getRight() instanceof JassExprUnary) {
1✔
303
            useParanthesesRight = true;
×
304
        }
305

306
        sb.append(useParanthesesLeft ? "(" : "");
1✔
307
        e.getLeft().prettyPrint(spacer, sb, indent);
1✔
308
        sb.append(useParanthesesLeft ? ")" : "");
1✔
309
        spacer.addSpace(sb);
1✔
310
        sb.append(e.getOp().toString());
1✔
311
        spacer.addSpace(sb);
1✔
312
        sb.append(useParanthesesRight ? "(" : "");
1✔
313
        e.getRight().prettyPrint(spacer, sb, indent);
1✔
314
        sb.append(useParanthesesRight ? ")" : "");
1✔
315
    }
1✔
316

317
    public static void prettyPrint(ExprBoolVal e, Spacer spacer, StringBuilder sb, int indent) {
318
        sb.append(e.getValB());
1✔
319
    }
1✔
320

321
    public static void prettyPrint(ExprCast e, Spacer spacer, StringBuilder sb, int indent) {
322
        e.getExpr().prettyPrint(spacer, sb, indent);
×
323
        spacer.addSpace(sb);
×
324
        sb.append("castTo");
×
325
        spacer.addSpace(sb);
×
326
        e.getTyp().prettyPrint(spacer, sb, indent);
×
327
    }
×
328

329
    public static void prettyPrint(ExprClosure e, Spacer spacer, StringBuilder sb, int indent) {
330
        e.getShortParameters().prettyPrint(spacer, sb, indent);
1✔
331
        spacer.addSpace(sb);
1✔
332
        sb.append("->");
1✔
333
        spacer.addSpace(sb);
1✔
334
        e.getImplementation().prettyPrint(spacer, sb, indent);
1✔
335
    }
1✔
336

337
    public static void prettyPrint(ExprDestroy e, Spacer spacer, StringBuilder sb, int indent) {
338
        printFirstNewline(e, sb, indent);
×
339
        printIndent(sb, indent);
×
340
        sb.append("destroy");
×
341
        spacer.addSpace(sb);
×
342
        e.getDestroyedObj().prettyPrint(spacer, sb, indent);
×
343
        sb.append("\n");
×
344
    }
×
345

346
    public static void prettyPrint(ExprEmpty e, Spacer spacer, StringBuilder sb, int indent) {
347
    }
×
348

349
    public static void prettyPrint(ExprFuncRef e, Spacer spacer, StringBuilder sb, int indent) {
350
        sb.append("function");
1✔
351
        spacer.addSpace(sb);
1✔
352
        if (!StringUtils.isBlank(e.getScopeName())) {
1✔
353
            sb.append(e.getScopeName());
×
354
            sb.append(".");
×
355
        }
356
        sb.append(e.getFuncName());
1✔
357
    }
1✔
358

359
    public static void prettyPrint(ExprFunctionCall e, Spacer spacer, StringBuilder sb, int indent) {
360
        printIndent(sb, indent);
1✔
361
        sb.append(e.getFuncName());
1✔
362
        sb.append("(");
1✔
363
        e.getArgs().prettyPrint(spacer, sb, indent);
1✔
364
        sb.append(")");
1✔
365
        printNewline(e, sb, indent);
1✔
366
    }
1✔
367

368
    public static void prettyPrint(ExprIncomplete e, Spacer spacer, StringBuilder sb, int indent) {
369
    }
×
370

371
    public static void prettyPrint(ExprInstanceOf e, Spacer spacer, StringBuilder sb, int indent) {
372
        e.getExpr().prettyPrint(spacer, sb, indent);
×
373
        spacer.addSpace(sb);
×
374
        sb.append("instanceof");
×
375
        spacer.addSpace(sb);
×
376
        e.getTyp().prettyPrint(spacer, sb, indent);
×
377
    }
×
378

379
    public static void prettyPrint(ExprIntVal e, Spacer spacer, StringBuilder sb, int indent) {
380
        sb.append(e.getValIraw());
1✔
381
    }
1✔
382

383
    public static void prettyPrint(ExprMemberArrayVarDot e, Spacer spacer, StringBuilder sb, int indent) {
384
        e.getLeft().prettyPrint(spacer, sb, indent);
×
385
        sb.append(".");
×
386
        sb.append(e.getVarName());
×
387
        sb.append("[");
×
388
        e.getIndexes().prettyPrint(spacer, sb, indent);
×
389
        sb.append("]");
×
390
    }
×
391

392
    public static void prettyPrint(ExprMemberArrayVarDotDot e, Spacer spacer, StringBuilder sb, int indent) {
393
        e.getLeft().prettyPrint(spacer, sb, indent);
×
394
        sb.append("..");
×
395
        sb.append(e.getVarName());
×
396
        sb.append("[");
×
397
        e.getIndexes().prettyPrint(spacer, sb, indent);
×
398
        sb.append("]");
×
399
    }
×
400

401
    public static void prettyPrint(ExprMemberMethodDot e, Spacer spacer, StringBuilder sb, int indent) {
402
        printIndent(sb, indent);
1✔
403
        if (e.getLeft() instanceof ExprBinary) {
1✔
404
            sb.append("(");
1✔
405
            e.getLeft().prettyPrint(spacer, sb, indent);
1✔
406
            sb.append(")");
1✔
407
        } else {
408
            e.getLeft().prettyPrint(spacer, sb, indent);
1✔
409
        }
410
        sb.append(".");
1✔
411
        sb.append(e.getFuncName());
1✔
412
        sb.append("(");
1✔
413
        e.getArgs().prettyPrint(spacer, sb, indent);
1✔
414
        sb.append(")");
1✔
415
        printNewline(e, sb, indent);
1✔
416
    }
1✔
417

418
    public static void prettyPrint(ExprMemberMethodDotDot e, Spacer spacer, StringBuilder sb, int indent) {
419
        if (e.getLeft() instanceof ExprBinary) {
1✔
420
            sb.append("(");
×
421
            e.getLeft().prettyPrint(spacer, sb, indent);
×
422
            sb.append(")");
×
423
        } else {
424
            e.getLeft().prettyPrint(spacer, sb, indent);
1✔
425
        }
426
        sb.append("\n");
1✔
427
        printIndent(sb, indent + 1);
1✔
428
        sb.append("..");
1✔
429
        sb.append(e.getFuncName());
1✔
430
        sb.append("(");
1✔
431
        e.getArgs().prettyPrint(spacer, sb, indent);
1✔
432
        sb.append(")");
1✔
433
        printNewline(e, sb, indent);
1✔
434
    }
1✔
435

436
    public static void prettyPrint(ExprMemberVarDot e, Spacer spacer, StringBuilder sb, int indent) {
437
        e.getLeft().prettyPrint(spacer, sb, indent);
1✔
438
        sb.append(".");
1✔
439
        sb.append(e.getVarName());
1✔
440
    }
1✔
441

442
    public static void prettyPrint(ExprMemberVarDotDot e, Spacer spacer, StringBuilder sb, int indent) {
443
        printIndent(sb, indent);
×
444
        e.getLeft().prettyPrint(spacer, sb, indent);
×
445
        sb.append("..");
×
446
        sb.append(e.getVarName());
×
447
    }
×
448

449
    public static void prettyPrint(ExprNewObject e, Spacer spacer, StringBuilder sb, int indent) {
450
        printIndent(sb, indent);
1✔
451
        sb.append("new");
1✔
452
        spacer.addSpace(sb);
1✔
453
        sb.append(e.getTypeName());
1✔
454
        e.getTypeArgs().prettyPrint(spacer, sb, indent);
1✔
455
        if (e.getArgs().size() > 0) {
1✔
456
            sb.append("(");
1✔
457
            e.getArgs().prettyPrint(spacer, sb, indent);
1✔
458
            sb.append(")");
1✔
459
        }
460
        printNewline(e, sb, indent);
1✔
461
    }
1✔
462

463
    public static void prettyPrint(ExprNull e, Spacer spacer, StringBuilder sb, int indent) {
464
        sb.append("null");
×
465
    }
×
466

467
    public static void prettyPrint(ExprRealVal e, Spacer spacer, StringBuilder sb, int indent) {
468
        sb.append(e.getValR());
1✔
469
    }
1✔
470

471
    public static void prettyPrint(ExprStatementsBlock e, Spacer spacer, StringBuilder sb, int indent) {
472
        sb.append("begin");
1✔
473
        sb.append("\n");
1✔
474
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
475
        printIndent(sb, indent);
1✔
476
        sb.append("end");
1✔
477
    }
1✔
478

479
    public static void prettyPrint(ExprStringVal e, Spacer spacer, StringBuilder sb, int indent) {
480
        sb.append(Utils.escapeString(e.getValS()));
1✔
481
    }
1✔
482

483
    public static void prettyPrint(ExprSuper e, Spacer spacer, StringBuilder sb, int indent) {
484
        printIndent(sb, indent);
×
485
        sb.append("super");
×
486
    }
×
487

488
    public static void prettyPrint(ExprThis e, Spacer spacer, StringBuilder sb, int indent) {
489
        printIndent(sb, indent);
1✔
490
        sb.append("this");
1✔
491
    }
1✔
492

493
    public static void prettyPrint(ExprTypeId e, Spacer spacer, StringBuilder sb, int indent) {
494
        e.getLeft().prettyPrint(spacer, sb, indent);
×
495
        sb.append(".typeId");
×
496
    }
×
497

498
    public static void prettyPrint(ExprUnary e, Spacer spacer, StringBuilder sb, int indent) {
499
        sb.append(e.getOpU().toString());
×
500
        // Don't add space for unary minus, e.g -1.
501
        if (e.getOpU().toString() == "not") {
×
502
            spacer.addSpace(sb);
×
503
        }
504
        e.getRight().prettyPrint(spacer, sb, indent);
×
505
    }
×
506

507
    public static void prettyPrint(ExprVarAccess e, Spacer spacer, StringBuilder sb, int indent) {
508
        printIndent(sb, indent);
1✔
509
        sb.append(e.getVarName());
1✔
510
    }
1✔
511

512
    public static void prettyPrint(ExprVarArrayAccess e, Spacer spacer, StringBuilder sb, int indent) {
513
        printIndent(sb, indent);
×
514
        sb.append(e.getVarName());
×
515
        sb.append("[");
×
516
        e.getIndexes().prettyPrint(spacer, sb, indent);
×
517
        sb.append("]");
×
518
    }
×
519

520
    public static void prettyPrint(ExtensionFuncDef e, Spacer spacer, StringBuilder sb, int indent) {
521
        printFirstNewline(e, sb, indent);
1✔
522
        printStuff(e, spacer, sb, indent);
1✔
523
        sb.append("function");
1✔
524
        spacer.addSpace(sb);
1✔
525
        e.getExtendedType().prettyPrint(spacer, sb, indent);
1✔
526
        sb.append(".");
1✔
527
        printFunctionSignature(e, spacer, sb, indent);
1✔
528
        sb.append("\n");
1✔
529
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
530
        printCommentsAfter(sb, e, indent);
1✔
531
    }
1✔
532

533

534
    private static void printFunctionSignature(FunctionImplementation e, Spacer spacer, StringBuilder sb, int indent) {
535
        sb.append(e.getName());
1✔
536
        e.getTypeParameters().prettyPrint(spacer, sb, indent);
1✔
537
        e.getParameters().prettyPrint(spacer, sb, indent);
1✔
538
        if (!(e.getReturnTyp() instanceof NoTypeExpr)) {
1✔
539
            spacer.addSpace(sb);
1✔
540
            sb.append("returns");
1✔
541
            spacer.addSpace(sb);
1✔
542
            e.getReturnTyp().prettyPrint(spacer, sb, indent);
1✔
543
        }
544
    }
1✔
545

546
    public static void prettyPrint(FuncDef e, Spacer spacer, StringBuilder sb, int indent) {
547
        printFirstNewline(e, sb, indent);
1✔
548
        printStuff(e, spacer, sb, indent);
1✔
549
        sb.append("function");
1✔
550
        spacer.addSpace(sb);
1✔
551
        printFunctionSignature(e, spacer, sb, indent);
1✔
552
        sb.append("\n");
1✔
553
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
554
        printCommentsAfter(sb, e, indent);
1✔
555
    }
1✔
556

557
    public static void prettyPrint(FuncDefs e, Spacer spacer, StringBuilder sb, int indent) {
558
        printFirstNewline(e, sb, indent);
1✔
559
        for (FuncDef funcDef : e) {
1✔
560
            funcDef.prettyPrint(spacer, sb, indent);
1✔
561
        }
1✔
562
    }
1✔
563

564
    public static void prettyPrint(GlobalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
565
        printStuff(e, spacer, sb, indent);
1✔
566
        if ((e.getOptTyp() instanceof NoTypeExpr)) {
1✔
567
            if (!e.attrIsConstant()) {
1✔
568
                sb.append("var");
×
569
            }
570
        } else {
571
            e.getOptTyp().prettyPrint(spacer, sb, indent);
1✔
572
        }
573
        spacer.addSpace(sb);
1✔
574
        sb.append(e.getName());
1✔
575
        if (!(e.getInitialExpr() instanceof NoExpr)) {
1✔
576
            spacer.addSpace(sb);
1✔
577
            sb.append("=");
1✔
578
            spacer.addSpace(sb);
1✔
579
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
1✔
580
        }
581
        sb.append("\n");
1✔
582
        printCommentsAfter(sb, e, indent);
1✔
583
    }
1✔
584

585
    public static void prettyPrint(GlobalVarDefs e, Spacer spacer, StringBuilder sb, int indent) {
586
        if (e.size() <= 0) {
1✔
587
            return;
1✔
588
        }
589
        for (GlobalVarDef varDef : e) {
1✔
590
            varDef.prettyPrint(spacer, sb, indent);
1✔
591
        }
1✔
592
        sb.append("\n");
1✔
593
    }
1✔
594

595
    public static void prettyPrint(IdentifierWithTypeArgs e, Spacer spacer, StringBuilder sb, int indent) {
596
    }
×
597

598
    public static void prettyPrint(IdentifierWithTypeParamDefs e, Spacer spacer, StringBuilder sb, int indent) {
599
    }
×
600

601
    public static void prettyPrint(Indexes e, Spacer spacer, StringBuilder sb, int indent) {
602
        for (Expr expr : e) {
×
603
            expr.prettyPrint(spacer, sb, indent);
×
604
        }
×
605
    }
×
606

607
    public static void prettyPrint(InitBlock e, Spacer spacer, StringBuilder sb, int indent) {
608
        printFirstNewline(e, sb, indent);
1✔
609
        printIndent(sb, indent);
1✔
610
        sb.append("init");
1✔
611
        sb.append("\n");
1✔
612
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
613
    }
1✔
614

615
    public static void prettyPrint(InterfaceDef e, Spacer spacer, StringBuilder sb, int indent) {
616
        printFirstNewline(e, sb, indent);
1✔
617
        printStuff(e, spacer, sb, indent);
1✔
618
        sb.append("interface");
1✔
619
        spacer.addSpace(sb);
1✔
620
        sb.append(e.getName());
1✔
621
        e.getTypeParameters().prettyPrint(spacer, sb, indent);
1✔
622
        if (e.getExtendsList().size() >= 1) {
1✔
623
            spacer.addSpace(sb);
×
624
            sb.append("extends");
×
625
            spacer.addSpace(sb);
×
626
            e.getExtendsList().prettyPrint(spacer, sb, indent);
×
627
        }
628
        e.getModuleUses().prettyPrint(spacer, sb, indent + 1);
1✔
629
        e.getVars().prettyPrint(spacer, sb, indent + 1);
1✔
630
        e.getConstructors().prettyPrint(spacer, sb, indent + 1);
1✔
631
        e.getMethods().prettyPrint(spacer, sb, indent + 1);
1✔
632
        e.getOnDestroy().prettyPrint(spacer, sb, indent + 1);
1✔
633
        printCommentsAfter(sb, e, indent);
1✔
634
    }
1✔
635

636

637
    public static void jassPrettyPrint(GlobalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
638
        printStuff(e, spacer, sb, indent);
×
639
        jassPrettyPrint(e.getOptTyp(), spacer, sb, indent);
×
640
        spacer.addSpace(sb);
×
641
        sb.append(e.getName());
×
642
        if (!(e.getInitialExpr() instanceof NoExpr)) {
×
643
            spacer.addSpace(sb);
×
644
            sb.append("=");
×
645
            spacer.addSpace(sb);
×
646
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
×
647
        }
648
        sb.append("\n");
×
649
        printCommentsAfter(sb, e, indent);
×
650
    }
×
651

652
    public static void jassPrettyPrint(OptTypeExpr e, Spacer spacer, StringBuilder sb, int indent) {
653
        if (e instanceof NoTypeExpr) {
×
654
            sb.append("nothing");
×
655
        } else if (e instanceof TypeExpr) {
×
656
            jassPrettyPrint((TypeExpr) e, spacer, sb, indent);
×
657
        }
658
    }
×
659

660
    public static void jassPrettyPrint(TypeExpr e, Spacer spacer, StringBuilder sb, int indent) {
661
        if (e instanceof NoTypeExpr) {
×
662
            sb.append("nothing");
×
663
        } else if (e instanceof TypeExprSimple) {
×
664
            sb.append(((TypeExprSimple) e).getTypeName());
×
665
        } else if (e instanceof TypeExprArray) {
×
666
            jassPrettyPrint(((TypeExprArray) e).getBase(), spacer, sb, indent);
×
667
            spacer.addSpace(sb);
×
668
            sb.append("array");
×
669
        }
670
    }
×
671

672
    public static void jassPrettyPrint(JassToplevelDeclarations e, Spacer spacer, StringBuilder sb, int indent) {
673
        for (int i = 0; i < e.size(); i++) {
1✔
674
            jassPrettyPrint(e.get(i), spacer, sb, indent);
×
675
        }
676
    }
1✔
677

678
    private static void jassPrettyPrint(JassToplevelDeclaration e, Spacer spacer, StringBuilder sb, int indent) {
679
        if (e instanceof JassGlobalBlock) {
×
680
            jassPrettyPrint((JassGlobalBlock) e, spacer, sb, indent);
×
681
        } else if (e instanceof NativeFunc) {
×
682
            jassPrettyPrint((NativeFunc) e, spacer, sb, indent);
×
683
        } else if (e instanceof FuncDef) {
×
684
            jassPrettyPrint((FuncDef) e, spacer, sb, indent);
×
685
        }
686
    }
×
687

688
    public static void jassPrettyPrint(FuncDef e, Spacer spacer, StringBuilder sb, int indent) {
689
        printFirstNewline(e, sb, indent);
×
690
        printStuff(e, spacer, sb, indent);
×
691
        sb.append("function");
×
692
        spacer.addSpace(sb);
×
693
        sb.append(e.getName());
×
694
        spacer.addSpace(sb);
×
695
        sb.append("takes");
×
696
        spacer.addSpace(sb);
×
697
        jassPrettyPrint(e.getParameters(), spacer, sb, indent);
×
698
        spacer.addSpace(sb);
×
699
        sb.append("returns");
×
700
        spacer.addSpace(sb);
×
701
        if (e.getReturnTyp() instanceof NoTypeExpr) {
×
702
            sb.append("nothing");
×
703
        } else {
704
            e.getReturnTyp().prettyPrint(spacer, sb, indent);
×
705
        }
706
        sb.append("\n");
×
707
        jassPrettyPrint(e.getBody(), spacer, sb, indent + 1);
×
708
        printCommentsAfter(sb, e, indent);
×
709
        sb.append("endfunction\n");
×
710
    }
×
711

712

713
    public static void jassPrettyPrint(WStatements e, Spacer spacer, StringBuilder sb, int indent) {
714
        for (int i = 0; i < e.size(); i++) {
×
715
            jassPrettyPrint(e.get(i), spacer, sb, indent);
×
716
        }
717
    }
×
718

719
    public static void jassPrettyPrint(WStatement e, Spacer spacer, StringBuilder sb, int indent) {
720
        if (e instanceof LocalVarDef) {
×
721
            jassPrettyPrint((LocalVarDef) e, spacer, sb, indent);
×
722
        } else if (e instanceof StmtSet) {
×
723
            jassPrettyPrint((StmtSet) e, spacer, sb, indent);
×
724
        } else if (e instanceof StmtCall) {
×
725
            jassPrettyPrint((StmtCall) e, spacer, sb, indent);
×
726
        } else if (e instanceof StmtIf) {
×
727
            jassPrettyPrint((StmtIf) e, spacer, sb, indent);
×
728
        } else if (e instanceof StmtReturn) {
×
729
            jassPrettyPrint((StmtReturn) e, spacer, sb, indent);
×
730
        } else if (e instanceof StmtLoop) {
×
731
            jassPrettyPrint((StmtLoop) e, spacer, sb, indent);
×
732
        } else if (e instanceof StmtExitwhen) {
×
733
            jassPrettyPrint((StmtExitwhen) e, spacer, sb, indent);
×
734
        }
735
    }
×
736

737
    public static void jassPrettyPrint(StmtExitwhen e, Spacer spacer, StringBuilder sb, int indent) {
738
        printIndent(sb, indent);
×
739
        sb.append("exitwhen");
×
740
        spacer.addSpace(sb);
×
741
        e.getCond().prettyPrint(spacer, sb, indent);
×
742
        sb.append("\n");
×
743
    }
×
744

745
    public static void jassPrettyPrint(StmtLoop e, Spacer spacer, StringBuilder sb, int indent) {
746
        printIndent(sb, indent);
×
747
        sb.append("loop\n");
×
748
        jassPrettyPrint(e.getBody(), spacer, sb, indent + 1);
×
749
        printIndent(sb, indent);
×
750
        sb.append("endloop\n");
×
751
    }
×
752

753
    public static void jassPrettyPrint(StmtReturn e, Spacer spacer, StringBuilder sb, int indent) {
754
        printIndent(sb, indent);
×
755
        sb.append("return");
×
756
        spacer.addSpace(sb);
×
757
        e.getReturnedObj().prettyPrint(spacer, sb, indent);
×
758
        sb.append("\n");
×
759
    }
×
760

761
    public static void jassPrettyPrint(StmtIf e, Spacer spacer, StringBuilder sb, int indent) {
762
        printIndent(sb, indent);
×
763
        sb.append("if");
×
764
        spacer.addSpace(sb);
×
765
        e.getCond().prettyPrint(spacer, sb, indent);
×
766
        spacer.addSpace(sb);
×
767
        sb.append("then\n");
×
768
        jassPrettyPrint(e.getThenBlock(), spacer, sb, indent + 1);
×
769
        if (e.getElseBlock().size() > 0) {
×
770
            printIndent(sb, indent);
×
771
            sb.append("else");
×
772
            if (e.getElseBlock().size() == 1 && e.getElseBlock().get(0) instanceof StmtIf) {
×
773
                jassPrettyPrint(e.getElseBlock().get(0), spacer, sb, indent);
×
774
            } else {
775
                sb.append("\n");
×
776
                jassPrettyPrint(e.getElseBlock(), spacer, sb, indent + 1);
×
777
                printIndent(sb, indent);
×
778
                sb.append("endif\n");
×
779
            }
780
        } else {
781
            printIndent(sb, indent);
×
782
            sb.append("endif\n");
×
783
        }
784

785
    }
×
786

787
    public static void jassPrettyPrint(StmtCall e, Spacer spacer, StringBuilder sb, int indent) {
788
        if (e instanceof FunctionCall) {
×
789
            jassPrettyPrint((FunctionCall) e, spacer, sb, indent);
×
790
        }
791
    }
×
792

793
    public static void jassPrettyPrint(FunctionCall e, Spacer spacer, StringBuilder sb, int indent) {
794
        printIndent(sb, indent);
×
795
        sb.append("call");
×
796
        spacer.addSpace(sb);
×
797
        sb.append(e.getFuncName());
×
798
        sb.append("(");
×
799
        jassPrettyPrint(e.getArgs(), spacer, sb, indent);
×
800
        sb.append(")");
×
801
        sb.append("\n");
×
802
    }
×
803

804
    public static void jassPrettyPrint(Arguments e, Spacer spacer, StringBuilder sb, int indent) {
805
        commaSeparatedList(e, spacer, sb, indent);
×
806
    }
×
807

808
    public static void jassPrettyPrint(StmtSet e, Spacer spacer, StringBuilder sb, int indent) {
809
        printIndent(sb, indent);
×
810
        sb.append("set");
×
811
        spacer.addSpace(sb);
×
812
        e.getUpdatedExpr().prettyPrint(spacer, sb, indent);
×
813
        spacer.addSpace(sb);
×
814
        sb.append("=");
×
815
        spacer.addSpace(sb);
×
816
        e.getRight().prettyPrint(spacer, sb, indent);
×
817
        sb.append("\n");
×
818
    }
×
819

820

821
    public static void jassPrettyPrint(LocalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
822
        printCommentsBefore(sb, e, indent);
×
823
        printIndent(sb, indent);
×
824
        sb.append("local");
×
825
        spacer.addSpace(sb);
×
826
        e.getOptTyp().prettyPrint(spacer, sb, indent);
×
827
        spacer.addSpace(sb);
×
828
        sb.append(e.getName());
×
829
        if (!(e.getInitialExpr() instanceof NoExpr)) {
×
830
            spacer.addSpace(sb);
×
831
            sb.append("=");
×
832
            spacer.addSpace(sb);
×
833
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
×
834
        }
835
        printNewline(e, sb, indent);
×
836
        printCommentsAfter(sb, e, indent);
×
837
    }
×
838

839
    public static void jassPrettyPrint(JassGlobalBlock e, Spacer spacer, StringBuilder sb, int indent) {
840
        sb.append("globals\n");
×
841
        for (int i = 0; i < e.size(); i++) {
×
842
            jassPrettyPrint(e.get(i), spacer, sb, indent + 1);
×
843
        }
844
        sb.append("endglobals\n");
×
845
    }
×
846

847
    public static void jassPrettyPrint(WParameters wParameters, Spacer spacer, StringBuilder sb, int indent) {
848
        if (wParameters.size() == 0) {
×
849
            sb.append("nothing");
×
850
            return;
×
851
        }
852
        String prefix = "";
×
853
        for (WParameter wParameter : wParameters) {
×
854
            sb.append(prefix);
×
855
            prefix = ",";
×
856
            spacer.addSpace(sb);
×
857
            wParameter.prettyPrint(spacer, sb, indent);
×
858
        }
×
859
    }
×
860

861
    public static void jassPrettyPrint(NativeFunc e, Spacer spacer, StringBuilder sb, int indent) {
862
        printStuff(e, spacer, sb, indent);
×
863
        sb.append("native");
×
864
        spacer.addSpace(sb);
×
865
        e.getNameId().prettyPrint(spacer, sb, indent);
×
866
        spacer.addSpace(sb);
×
867
        sb.append("takes");
×
868
        spacer.addSpace(sb);
×
869
        jassPrettyPrint(e.getParameters(), spacer, sb, indent);
×
870
        spacer.addSpace(sb);
×
871
        sb.append("returns");
×
872
        spacer.addSpace(sb);
×
873
        e.getReturnTyp().prettyPrint(spacer, sb, indent);
×
874
        sb.append("\n");
×
875
        printCommentsAfter(sb, e, indent);
×
876
    }
×
877

878
    public static void prettyPrint(LocalVarDef e, Spacer spacer, StringBuilder sb, int indent) {
879
        printCommentsBefore(sb, e, indent);
1✔
880
        printIndent(sb, indent);
1✔
881
        if ((e.getOptTyp() instanceof NoTypeExpr)) {
1✔
882
            if (e.attrIsConstant()) {
1✔
883
                sb.append("let");
1✔
884
            } else if (!(e.getParent() instanceof StmtForRange)) {
1✔
885
                sb.append("var");
1✔
886
            }
887
        } else {
888
            e.getOptTyp().prettyPrint(spacer, sb, indent);
1✔
889
        }
890
        spacer.addSpace(sb);
1✔
891
        sb.append(e.getName());
1✔
892
        if (!(e.getInitialExpr() instanceof NoExpr)) {
1✔
893
            spacer.addSpace(sb);
1✔
894
            sb.append("=");
1✔
895
            spacer.addSpace(sb);
1✔
896
            e.getInitialExpr().prettyPrint(spacer, sb, indent);
1✔
897
        }
898
        printNewline(e, sb, indent);
1✔
899
        printCommentsAfter(sb, e, indent);
1✔
900
    }
1✔
901

902
    public static void prettyPrint(ModAbstract e, Spacer spacer, StringBuilder sb, int indent) {
903
        sb.append("abstract");
1✔
904
    }
1✔
905

906
    public static void prettyPrint(ModConstant e, Spacer spacer, StringBuilder sb, int indent) {
907
        sb.append("constant");
1✔
908
    }
1✔
909

910
    public static void prettyPrint(ModVararg e, Spacer spacer, StringBuilder sb, int indent) {
911
        sb.append("vararg");
×
912
    }
×
913

914
    public static void prettyPrint(Modifiers e, Spacer spacer, StringBuilder sb, int indent) {
915
        for (Modifier modifier : e) {
1✔
916
            // We handle WurstDoc separately.
917
            if (!(modifier instanceof WurstDoc)) {
1✔
918
                modifier.prettyPrint(spacer, sb, indent);
1✔
919
                spacer.addSpace(sb);
1✔
920
            }
921
        }
1✔
922
    }
1✔
923

924
    public static void prettyPrint(ModOverride e, Spacer spacer, StringBuilder sb, int indent) {
925
        sb.append("override");
×
926
    }
×
927

928
    public static void prettyPrint(ModStatic e, Spacer spacer, StringBuilder sb, int indent) {
929
        sb.append("static");
×
930
    }
×
931

932
    public static void prettyPrint(ModuleDef e, Spacer spacer, StringBuilder sb, int indent) {
933
        printFirstNewline(e, sb, indent);
×
934
        printStuff(e, spacer, sb, indent);
×
935
        sb.append("module");
×
936
        spacer.addSpace(sb);
×
937
        e.getNameId().prettyPrint(spacer, sb, indent);
×
938
        sb.append("\n");
×
939
        printClassOrModuleDeclaration(e, spacer, sb, indent + 1);
×
940
        printCommentsAfter(sb, e, indent);
×
941
    }
×
942

943
    public static void prettyPrint(ModuleInstanciation e, Spacer spacer, StringBuilder sb, int indent) {
944
        printCommentsBefore(sb, e, indent);
×
945
    }
×
946

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

950
    public static void prettyPrint(ModuleUse e, Spacer spacer, StringBuilder sb, int indent) {
951
        printIndent(sb, indent);
×
952
        sb.append("use");
×
953
        spacer.addSpace(sb);
×
954
        sb.append(e.getModuleName());
×
955
        sb.append("\n");
×
956
    }
×
957

958
    public static void prettyPrint(ModuleUses e, Spacer spacer, StringBuilder sb, int indent) {
959
        for (ModuleUse moduleUse : e) {
1✔
960
            moduleUse.prettyPrint(spacer, sb, indent);
×
961
        }
×
962
    }
1✔
963

964
    public static void prettyPrint(NativeFunc e, Spacer spacer, StringBuilder sb, int indent) {
965
        printStuff(e, spacer, sb, indent);
×
966
        sb.append("native");
×
967
        spacer.addSpace(sb);
×
968
        e.getNameId().prettyPrint(spacer, sb, indent);
×
969
        e.getParameters().prettyPrint(spacer, sb, indent);
×
970
        if (!(e.getReturnTyp() instanceof NoTypeExpr)) {
×
971
            spacer.addSpace(sb);
×
972
            sb.append("returns");
×
973
            spacer.addSpace(sb);
×
974
            e.getReturnTyp().prettyPrint(spacer, sb, indent);
×
975
        }
976
        sb.append("\n");
×
977
        printCommentsAfter(sb, e, indent);
×
978
    }
×
979

980
    public static void prettyPrint(NativeType e, Spacer spacer, StringBuilder sb, int indent) {
981
        printStuff(e, spacer, sb, indent);
×
982
        sb.append("nativetype");
×
983
        spacer.addSpace(sb);
×
984
        e.getNameId().prettyPrint(spacer, sb, indent);
×
985
        sb.append("\n");
×
986
        printCommentsAfter(sb, e, indent);
×
987
    }
×
988

989
    public static void prettyPrint(NoDefaultCase e, Spacer spacer, StringBuilder sb, int indent) {
990
    }
×
991

992
    public static void prettyPrint(NoExpr e, Spacer spacer, StringBuilder sb, int indent) {
993
    }
×
994

995
    public static void prettyPrint(NoTypeExpr e, Spacer spacer, StringBuilder sb, int indent) {
996
    }
×
997

998
    public static void prettyPrint(OnDestroyDef e, Spacer spacer, StringBuilder sb, int indent) {
999
        if (e.getBody().size() <= 0) {
1✔
1000
            return;
1✔
1001
        }
1002
        printFirstNewline(e, sb, indent);
1✔
1003
        printIndent(sb, indent);
1✔
1004
        sb.append("ondestroy");
1✔
1005
        sb.append("\n");
1✔
1006
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
1007
    }
1✔
1008

1009
    public static void prettyPrint(StartFunctionStatement e, Spacer spacer, StringBuilder sb, int indent) {
1010
    }
1✔
1011

1012
    public static void prettyPrint(StmtErr e, Spacer spacer, StringBuilder sb, int indent) {
1013
    }
×
1014

1015
    public static void prettyPrint(StmtExitwhen e, Spacer spacer, StringBuilder sb, int indent) {
1016
        printIndent(sb, indent);
×
1017
        sb.append("break");
×
1018
        sb.append("\n");
×
1019
    }
×
1020

1021
    public static void prettyPrint(StmtForFrom e, Spacer spacer, StringBuilder sb, int indent) {
1022
        forIteratorLoop("from", e, e.getIn(), spacer, sb, indent);
1✔
1023
    }
1✔
1024

1025
    public static void prettyPrint(StmtForIn e, Spacer spacer, StringBuilder sb, int indent) {
1026
        forIteratorLoop("in", e, e.getIn(), spacer, sb, indent);
1✔
1027
    }
1✔
1028

1029
    private static void forIteratorLoop(String method, LoopStatementWithVarDef e, Expr target, Spacer spacer, StringBuilder sb, int indent) {
1030
        printIndent(sb, indent);
1✔
1031
        sb.append("for");
1✔
1032
        spacer.addSpace(sb);
1✔
1033
        e.getLoopVar().getNameId().prettyPrint(spacer, sb, indent);
1✔
1034
        spacer.addSpace(sb);
1✔
1035
        sb.append(method);
1✔
1036
        spacer.addSpace(sb);
1✔
1037
        target.prettyPrint(spacer, sb, indent);
1✔
1038
        sb.append("\n");
1✔
1039
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
1040
    }
1✔
1041

1042
    private static void forRangeLoop(String direction, StmtForRange e, Spacer spacer, StringBuilder sb, int indent) {
1043
        printIndent(sb, indent);
1✔
1044
        sb.append("for");
1✔
1045
        spacer.addSpace(sb);
1✔
1046
        e.getLoopVar().prettyPrint(spacer, sb, indent);
1✔
1047
        spacer.addSpace(sb);
1✔
1048
        sb.append(direction);
1✔
1049
        spacer.addSpace(sb);
1✔
1050
        e.getTo().prettyPrint(spacer, sb, indent);
1✔
1051
        if (e.getStep() instanceof ExprIntVal && ((ExprIntVal) e.getStep()).getValI() != 1) {
1✔
1052
            spacer.addSpace(sb);
1✔
1053
            sb.append("step");
1✔
1054
            spacer.addSpace(sb);
1✔
1055
            e.getStep().prettyPrint(spacer, sb, indent);
1✔
1056
        }
1057
        sb.append("\n");
1✔
1058
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
1059
    }
1✔
1060

1061
    public static void prettyPrint(StmtForRangeDown e, Spacer spacer, StringBuilder sb, int indent) {
1062
        forRangeLoop("downto", e, spacer, sb, indent);
1✔
1063
    }
1✔
1064

1065
    public static void prettyPrint(StmtForRangeUp e, Spacer spacer, StringBuilder sb, int indent) {
1066
        forRangeLoop("to", e, spacer, sb, indent);
1✔
1067
    }
1✔
1068

1069
    public static void prettyPrint(StmtIf e, Spacer spacer, StringBuilder sb, int indent) {
1070
        printIndent(sb, indent);
1✔
1071
        sb.append("if");
1✔
1072
        spacer.addSpace(sb);
1✔
1073
        e.getCond().prettyPrint(spacer, sb, indent);
1✔
1074
        sb.append("\n");
1✔
1075
        e.getThenBlock().prettyPrint(spacer, sb, indent + 1);
1✔
1076
        if (e.getElseBlock().size() > 0) {
1✔
1077
            printIndent(sb, indent);
1✔
1078
            sb.append("else");
1✔
1079
            if (e.getElseBlock().size() > 0 && e.getElseBlock().get(0) instanceof StmtIf) {
1✔
1080
                spacer.addSpace(sb);
1✔
1081
                e.getElseBlock().get(0).prettyPrint(spacer, sb, indent);
1✔
1082
            } else {
1083
                sb.append("\n");
1✔
1084
                e.getElseBlock().prettyPrint(spacer, sb, indent + 1);
1✔
1085
            }
1086
        }
1087
    }
1✔
1088

1089
    public static void prettyPrint(StmtLoop e, Spacer spacer, StringBuilder sb, int indent) {
1090
    }
×
1091

1092
    public static void prettyPrint(StmtReturn e, Spacer spacer, StringBuilder sb, int indent) {
1093
        printIndent(sb, indent);
1✔
1094
        sb.append("return");
1✔
1095
        spacer.addSpace(sb);
1✔
1096
        e.getReturnedObj().prettyPrint(spacer, sb, indent);
1✔
1097
        sb.append("\n");
1✔
1098
    }
1✔
1099

1100
    private static boolean printAssignmentShorthands(Expr left, Expr right, Spacer spacer, StringBuilder sb, int indent) {
1101
        if (!(right instanceof ExprBinary)) {
1✔
1102
            return false;
1✔
1103
        }
1104

1105
        if (!(left.toString().equals(((ExprBinary) right).getLeft().toString()))) {
1✔
1106
            return false;
×
1107
        }
1108

1109
        String operator = ((ExprBinary) right).getOp().toString();
1✔
1110
        Expr val = ((ExprBinary) right).getRight();
1✔
1111

1112
        // i++ and i--
1113
        if (val instanceof ExprIntVal
1✔
1114
            && ((ExprIntVal) val).getValI() == 1
1✔
1115
            && (operator.equals("+") || operator.equals("-"))) {
1✔
1116
            sb.append(operator);
1✔
1117
            sb.append(operator);
1✔
1118
            return true;
1✔
1119
        }
1120

1121
        // i +=, ...
1122
        spacer.addSpace(sb);
1✔
1123
        sb.append(operator);
1✔
1124
        sb.append("=");
1✔
1125
        spacer.addSpace(sb);
1✔
1126
        val.prettyPrint(spacer, sb, indent);
1✔
1127
        return true;
1✔
1128
    }
1129

1130
    public static void prettyPrint(StmtSet e, Spacer spacer, StringBuilder sb, int indent) {
1131
        printIndent(sb, indent);
1✔
1132
        e.getUpdatedExpr().prettyPrint(spacer, sb, indent);
1✔
1133

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

1137
        if (!shortened) {
1✔
1138
            spacer.addSpace(sb);
1✔
1139
            sb.append("=");
1✔
1140
            spacer.addSpace(sb);
1✔
1141
            e.getRight().prettyPrint(spacer, sb, indent);
1✔
1142
        }
1143
        sb.append("\n");
1✔
1144
    }
1✔
1145

1146
    public static void prettyPrint(StmtSkip e, Spacer spacer, StringBuilder sb, int indent) {
1147
        printIndent(sb, indent);
1✔
1148
        sb.append("skip");
1✔
1149
        sb.append("\n");
1✔
1150
    }
1✔
1151

1152
    public static void prettyPrint(StmtWhile e, Spacer spacer, StringBuilder sb, int indent) {
1153
        printIndent(sb, indent);
1✔
1154
        sb.append("while");
1✔
1155
        spacer.addSpace(sb);
1✔
1156
        e.getCond().prettyPrint(spacer, sb, indent);
1✔
1157
        sb.append("\n");
1✔
1158
        e.getBody().prettyPrint(spacer, sb, indent + 1);
1✔
1159
    }
1✔
1160

1161
    public static void prettyPrint(SwitchCase e, Spacer spacer, StringBuilder sb, int indent) {
1162
        printIndent(sb, indent);
1✔
1163
        sb.append("case");
1✔
1164
        spacer.addSpace(sb);
1✔
1165
        e.getExpressions().prettyPrint(spacer, sb, indent);
1✔
1166
        sb.append("\n");
1✔
1167
        e.getStmts().prettyPrint(spacer, sb, indent + 1);
1✔
1168
    }
1✔
1169

1170
    public static void prettyPrint(SwitchCases sw, Spacer spacer, StringBuilder sb, int indent) {
1171
        for (SwitchCase c : sw) {
1✔
1172
            c.prettyPrint(spacer, sb, indent);
1✔
1173
        }
1✔
1174
    }
1✔
1175

1176
    public static void prettyPrint(SwitchDefaultCaseStatements e, Spacer spacer, StringBuilder sb, int indent) {
1177
        printIndent(sb, indent);
1✔
1178
        sb.append("default");
1✔
1179
        sb.append("\n");
1✔
1180
        e.getStmts().prettyPrint(spacer, sb, indent + 1);
1✔
1181
    }
1✔
1182

1183
    public static void prettyPrint(SwitchStmt sw, Spacer spacer, StringBuilder sb, int indent) {
1184
        printIndent(sb, indent);
1✔
1185
        sb.append("switch");
1✔
1186
        spacer.addSpace(sb);
1✔
1187
        sw.getExpr().prettyPrint(spacer, sb, indent);
1✔
1188
        sb.append("\n");
1✔
1189
        sw.getCases().prettyPrint(spacer, sb, indent + 1);
1✔
1190
        sw.getSwitchDefault().prettyPrint(spacer, sb, indent + 1);
1✔
1191
    }
1✔
1192

1193
    public static void prettyPrint(TopLevelDeclarations e, Spacer spacer, StringBuilder sb, int indent) {
1194
    }
×
1195

1196
    public static void prettyPrint(TupleDef e, Spacer spacer, StringBuilder sb, int indent) {
1197
        printStuff(e, spacer, sb, indent);
×
1198
        spacer.addSpace(sb);
×
1199
        sb.append("tuple");
×
1200
        spacer.addSpace(sb);
×
1201
        e.getNameId().prettyPrint(spacer, sb, indent);
×
1202
        e.getParameters().prettyPrint(spacer, sb, indent);
×
1203
        sb.append("\n");
×
1204
        printCommentsAfter(sb, e, indent);
×
1205
    }
×
1206

1207
    public static void prettyPrint(TypeExprArray e, Spacer spacer, StringBuilder sb, int indent) {
1208
        e.getBase().prettyPrint(spacer, sb, indent);
×
1209
        spacer.addSpace(sb);
×
1210
        sb.append("array");
×
1211
    }
×
1212

1213
    public static void prettyPrint(TypeExprList typeExprList, Spacer spacer, StringBuilder sb, int indent) {
1214
        if (typeExprList.size() == 0) {
1✔
1215
            return;
1✔
1216
        }
1217
        sb.append("<");
1✔
1218
        commaSeparatedList(typeExprList, spacer, sb, indent);
1✔
1219
        sb.append(">");
1✔
1220
    }
1✔
1221

1222
    public static void prettyPrint(TypeExprResolved e, Spacer spacer, StringBuilder sb, int indent) {
1223
    }
×
1224

1225
    public static void prettyPrint(TypeExprSimple e, Spacer spacer, StringBuilder sb, int indent) {
1226
        sb.append(e.getTypeName());
1✔
1227
        e.getTypeArgs().prettyPrint(spacer, sb, indent);
1✔
1228
    }
1✔
1229

1230
    public static void prettyPrint(TypeExprThis e, Spacer spacer, StringBuilder sb, int indent) {
1231
        if (!(e.getScopeType() instanceof NoTypeExpr)) {
×
1232
            e.getScopeType().prettyPrint(spacer, sb, indent);
×
1233
            sb.append(".");
×
1234
        }
1235
        sb.append("thistype");
×
1236
    }
×
1237

1238
    public static void prettyPrint(TypeParamDef e, Spacer spacer, StringBuilder sb, int indent) {
1239
        printCommentsBefore(sb, e, indent);
×
1240
        e.getNameId().prettyPrint(spacer, sb, indent);
×
1241
        printCommentsAfter(sb, e, indent);
×
1242
    }
×
1243

1244
    public static void prettyPrint(TypeParamDefs e, Spacer spacer, StringBuilder sb, int indent) {
1245
        if (e.size() >= 1) {
1✔
1246
            sb.append("<");
×
1247
            commaSeparatedList(e, spacer, sb, indent);
×
1248
            sb.append(">");
×
1249
        }
1250
    }
1✔
1251

1252
    public static void prettyPrint(VisibilityDefault e, Spacer spacer, StringBuilder sb, int indent) {
1253
    }
×
1254

1255
    public static void prettyPrint(VisibilityPrivate e, Spacer spacer, StringBuilder sb, int indent) {
1256
        sb.append("private");
×
1257
    }
×
1258

1259
    public static void prettyPrint(VisibilityProtected e, Spacer spacer, StringBuilder sb, int indent) {
1260
        sb.append("protected");
×
1261
    }
×
1262

1263
    public static void prettyPrint(VisibilityPublic e, Spacer spacer, StringBuilder sb, int indent) {
1264
        sb.append("public");
1✔
1265
    }
1✔
1266

1267
    public static void prettyPrint(VisibilityPublicread e, Spacer spacer, StringBuilder sb, int indent) {
1268
        sb.append("publicread");
×
1269
    }
×
1270

1271
    public static void prettyPrint(WBlock wBlock, Spacer spacer, StringBuilder sb, int indent) {
1272
        // TODO Auto-generated method stub
1273
        throw new Error("not implemented");
×
1274
    }
1275

1276
    public static void prettyPrint(WEntities wEntities, Spacer spacer, StringBuilder sb, int indent) {
1277
        for (WEntity entity : wEntities) {
1✔
1278
            entity.prettyPrint(spacer, sb, indent);
1✔
1279
        }
1✔
1280
    }
1✔
1281

1282
    public static void prettyPrint(WImport wImport, Spacer spacer, StringBuilder sb, int indent) {
1283
        sb.append("import");
1✔
1284
        spacer.addSpace(sb);
1✔
1285
        sb.append(wImport.getIsInitLater() ? "initlater" : "");
1✔
1286
        spacer.addSpace(sb);
1✔
1287
        sb.append(wImport.getIsPublic() ? "public" : "");
1✔
1288
        spacer.addSpace(sb);
1✔
1289
        sb.append(wImport.getPackagename());
1✔
1290
        sb.append("\n");
1✔
1291
    }
1✔
1292

1293
    public static void prettyPrint(WurstModel wurstModel, Spacer spacer, StringBuilder sb, int indent) {
1294
        for (CompilationUnit compilationUnit : wurstModel) {
×
1295
            compilationUnit.prettyPrint(spacer, sb, indent);
×
1296
        }
×
1297
    }
×
1298

1299
    private static String spaces(int indentation) {
1300
        return " " + "{" + indentation + "}";
×
1301
    }
1302

1303
    public static void prettyPrint(WurstDoc wurstDoc, Spacer spacer, StringBuilder sb, int indent) {
1304
        printIndent(sb, indent);
×
1305
        sb.append(wurstDoc.getRawComment());
×
1306
        sb.append("\n");
×
1307
    }
×
1308

1309
    public static void prettyPrint(WStatements wStatements, Spacer spacer, StringBuilder sb, int indent) {
1310
        for (WStatement wStatement : wStatements) {
1✔
1311
            wStatement.prettyPrint(spacer, sb, indent);
1✔
1312
        }
1✔
1313
    }
1✔
1314

1315
    public static void prettyPrint(WParameters wParameters, Spacer spacer, StringBuilder sb, int indent) {
1316
        sb.append("(");
1✔
1317
        String prefix = "";
1✔
1318
        for (WParameter wParameter : wParameters) {
1✔
1319
            sb.append(prefix);
1✔
1320
            prefix = ",";
1✔
1321
            spacer.addSpace(sb);
1✔
1322
            wParameter.prettyPrint(spacer, sb, indent);
1✔
1323
        }
1✔
1324
        sb.append(")");
1✔
1325
    }
1✔
1326

1327
    public static void prettyPrint(WShortParameters wParameters, Spacer spacer, StringBuilder sb, int indent) {
1328
        sb.append("(");
1✔
1329
        String prefix = "";
1✔
1330
        for (WShortParameter wParameter : wParameters) {
1✔
1331
            sb.append(prefix);
1✔
1332
            prefix = ",";
1✔
1333
            spacer.addSpace(sb);
1✔
1334
            wParameter.prettyPrint(spacer, sb, indent);
1✔
1335
        }
1✔
1336
        sb.append(")");
1✔
1337
    }
1✔
1338

1339
    public static void prettyPrint(WParameter wParameter, Spacer spacer, StringBuilder sb, int indent) {
1340
        wParameter.getTyp().prettyPrint(spacer, sb, indent);
1✔
1341
        spacer.addSpace(sb);
1✔
1342
        sb.append(wParameter.getName());
1✔
1343
    }
1✔
1344

1345
    public static void prettyPrint(WShortParameter wParameter, Spacer spacer, StringBuilder sb, int indent) {
1346
        OptTypeExpr t = wParameter.getTypOpt();
1✔
1347
        if (t instanceof TypeExpr) {
1✔
1348
            t.prettyPrint(spacer, sb, indent);
1✔
1349
            spacer.addSpace(sb);
1✔
1350
        }
1351
        sb.append(wParameter.getName());
1✔
1352
    }
1✔
1353

1354
    public static void prettyPrint(WPackages wPackages, Spacer spacer, StringBuilder sb, int indent) {
1355
        for (WPackage wPackage : wPackages) {
1✔
1356
            wPackage.prettyPrint(spacer, sb, indent);
1✔
1357
        }
1✔
1358
    }
1✔
1359

1360
    public static void prettyPrint(WPackage wPackage, Spacer spacer, StringBuilder sb, int indent) {
1361
        printCommentsBefore(sb, wPackage, indent);
1✔
1362
        sb.append("package");
1✔
1363
        spacer.addSpace(sb);
1✔
1364
        sb.append(wPackage.getName());
1✔
1365
        sb.append("\n\n");
1✔
1366
        wPackage.getImports().prettyPrint(spacer, sb, indent);
1✔
1367
        wPackage.getElements().prettyPrint(spacer, sb, indent);
1✔
1368
        printCommentsAfter(sb, wPackage, indent);
1✔
1369
    }
1✔
1370

1371
    public static void prettyPrint(WImports wImports, Spacer spacer, StringBuilder sb, int indent) {
1372
        if (wImports.size() <= 0) {
1✔
1373
            return;
1✔
1374
        }
1375
        for (WImport wImport : wImports) {
1✔
1376
            if (!wImport.getPackagename().equals("Wurst")) {
1✔
1377
                wImport.prettyPrint(spacer, sb, indent);
1✔
1378
            }
1379
        }
1✔
1380
        sb.append("\n");
1✔
1381
    }
1✔
1382

1383
    public static void prettyPrint(ClassDefs classDefs, Spacer spacer, StringBuilder sb, int indent) {
1384
        for (ClassDef classDef : classDefs) {
1✔
1385
            classDef.prettyPrint(spacer, sb, indent);
×
1386
        }
×
1387
    }
1✔
1388

1389
    public static void prettyPrint(Identifier identifier, Spacer spacer, StringBuilder sb, int indent) {
1390
        sb.append(identifier.getName());
1✔
1391
    }
1✔
1392

1393
    public static void prettyPrint(ExprIfElse e, Spacer spacer, StringBuilder sb, int indent) {
1394
        boolean shouldBracket = e.getParent() instanceof ExprBinary;
1✔
1395
        if (shouldBracket) {
1✔
1396
            sb.append("(");
×
1397
        }
1398
        e.getCond().prettyPrint(spacer, sb, indent);
1✔
1399
        spacer.addSpace(sb);
1✔
1400
        sb.append("?");
1✔
1401
        spacer.addSpace(sb);
1✔
1402
        e.getIfTrue().prettyPrint(spacer, sb, indent);
1✔
1403
        spacer.addSpace(sb);
1✔
1404
        sb.append(":");
1✔
1405
        spacer.addSpace(sb);
1✔
1406
        e.getIfFalse().prettyPrint(spacer, sb, indent);
1✔
1407
        if (shouldBracket) {
1✔
1408
            sb.append(")");
×
1409
        }
1410
    }
1✔
1411

1412
    public static void prettyPrint(ArrayInitializer arrayInitializer, Spacer spacer, StringBuilder sb, int indent) {
1413
        sb.append("[");
×
1414
        arrayInitializer.getValues().prettyPrint(spacer, sb, indent);
×
1415
        sb.append("]");
×
1416
    }
×
1417

1418
    public static void prettyPrint(NoSuperConstructorCall noSuperConstructorCall, Spacer spacer, StringBuilder sb, int indent) {
1419
        // nothing
1420
    }
1✔
1421

1422
    public static void prettyPrint(SomeSuperConstructorCall c, Spacer spacer, StringBuilder sb, int indent) {
1423
        printIndent(sb, indent + 1);
1✔
1424
        sb.append("super(");
1✔
1425
        c.getSuperArgs().prettyPrint(spacer, sb, indent);
1✔
1426
        sb.append(")\n");
1✔
1427

1428
    }
1✔
1429

1430
    public static void prettyPrint(NoTypeParamConstraints noTypeParamConstraints, Spacer spacer, StringBuilder sb, int indent) {
1431
        // nothing
1432
    }
×
1433
}
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