/** * Print this statement as the "ifTrue" branch of an if-then-else having just printed the * parenthesized test, but no newline. This allows us to override the behaviour for Blocks to * match the desired output formatting. The elseStmt parameter specifies the corresponding else * statement that should also be printed. For current purposes, there are no if-then-else * statements that do not have an else branch. */ public void printThenElse(TextOutput out, int n, Stmt elseStmt) { out.println(" {"); printBlock(out, n + 1); out.indent(n); out.print("} else"); elseStmt.printElse(out, n); }
/** * Generate a pretty-printed description of this abstract syntax node using the concrete syntax of * the mini programming language. */ public void print(TextOutput out, int n) { out.indent(n); out.println("{"); this.printBlock(out, n + 1); out.indent(n); out.println("}"); }
@Override public void appendFinishedValueTypeName(TextOutput out) { if (isList) { out.append("java.util.List<"); componentParser.appendFinishedValueTypeName(out); out.append('>'); } else { componentParser.appendFinishedValueTypeName(out); out.append("[]"); } }
void write(ClassScope scope, Method method, TextOutput out) { MethodHandler.writeMethodDeclarationJava(out, method, paramNames); out.openBlock(); out.append("return "); if (isList) { out.append("readObjectArray(") .append(Util.READER_NAME) .append(", null, new ") .append(scope.requireFactoryGenerationAndGetName(typeHandler)) .append(Util.TYPE_FACTORY_NAME_POSTFIX) .append("()") .append(", false)"); } else { typeHandler.writeInstantiateCode(scope, out); out.append('(').append(Util.READER_NAME); out.comma().space(); out.append(paramNames.size() == 1 ? "null" : "nextName"); out.append(')'); } out.semi(); out.closeBlock(); }
/** * Print out a program. In general, we expect a top-level program to be represented by a Block, * whose contents will be displayed here without the enclosing braces that might otherwise be * expected. We will also define an implementation of this method for arbitrary Stmt values too so * that it can be used for debugging and testing. */ public void printProgram(TextOutput out) { printBlock(out, 0); out.println(); }
/** Print out a description of this identifier as plain text. */ void printText(TextOutput out) { out.print(name); }
/** Print out this expression. */ public void print(TextOutput out) { out.printUse(this); }
/** * Generate a pretty-printed description of this expression using the concrete syntax of the mini * programming language. */ public void print(TextOutput out) { lhs.print(out); out.print(" = "); rhs.print(out); }
/** * Print this statement as the "ifFalse" branch of an if-then-else having just printed the "else" * keyword but no newline. Again, this allows us to override the behavior for Blocks. */ public void printElse(TextOutput out, int n) { out.println(); print(out, n + 1); }