protected void outputDelegatingForCase( NodeType t, TabPrintWriter writer, NodeType root, String retType, String suff, String defaultMethod) { outputForCaseHeader(t, writer, retType, suff); writer.indent(); if (!retType.equals("void")) { writer.startLine("return "); } else { writer.startLine(); } Option<NodeType> sup = ast.parent(t); if (sup.isSome() && !t.equals(root)) { writer.print(visitorMethodName(sup.unwrap()) + suff + "(that);"); } else { writer.print(defaultMethod + "(that);"); } writer.unindent(); writer.startLine("}"); writer.println(); }
protected void outputDefaultCaseMethod(TabPrintWriter writer, NodeType root) { writer.startLine("/**"); writer.startLine(" * This method is run for all cases that are not handled elsewhere."); writer.startLine( " * By default, an exception is thrown; subclasses may override this behavior."); writer.startLine(" * @throws IllegalArgumentException"); writer.startLine("**/"); writer.startLine("public RetType defaultCase(" + root.name() + " that) {"); writer.indent(); writer.startLine("throw new IllegalArgumentException(\"Visitor \" + getClass().getName()"); writer.print(" + \" does not support visiting values of type \" + that.getClass().getName());"); writer.unindent(); writer.startLine("}"); }