PrettyPrinterVisitor extends StandardVisitor { public static String defaultIndent(int level) { StringBuilder result = new StringBuilder(); for (int i = 0; i < level; i++) { for (int j = 0; j < PrettyPrinterVisitor.DEFAULT_INDENTATION_WIDTH; j++) { result.append(" "); } } return result.toString(); } PrettyPrinterVisitor(PrintStream out);  PrettyPrinterVisitor(PrintStream out,
                              int indentationWidth,
                              Supplier<String> newLineSupplier,
                              boolean emitGraphicsFuzzDefines,
                              Optional<String> license,
                              Optional<UniformValueSupplier> uniformValues); static String prettyPrintAsString(IAstNode node); static String prettyPrintAsString(IAstNode node, UniformValueSupplier uniformValues); static void emitShader(TranslationUnit shader,
                                Optional<String> license,
                                PrintStream stream,
                                int indentationWidth,
                                Supplier<String> newlineSupplier); static void emitShader(TranslationUnit shader,
                                Optional<String> license,
                                PrintStream stream,
                                int indentationWidth,
                                Supplier<String> newlineSupplier,
                                Optional<UniformValueSupplier> uniformValueSupplier); @Override void visitPrecisionDeclaration(PrecisionDeclaration precisionDeclaration); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitFunctionPrototype(FunctionPrototype functionPrototype); @Override void visitParameterDecl(ParameterDecl parameterDecl); @Override void visitBlockStmt(BlockStmt stmt); @Override void visitIfStmt(IfStmt ifStmt); @Override void visitBinaryExpr(BinaryExpr binaryExpr); @Override void visitParenExpr(ParenExpr parenExpr); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); @Override void visitUnaryExpr(UnaryExpr unaryExpr); @Override void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr); @Override void visitIntConstantExpr(IntConstantExpr intConstantExpr); @Override void visitUIntConstantExpr(UIntConstantExpr intConstantExpr); @Override void visitFloatConstantExpr(FloatConstantExpr floatConstantExpr); @Override void visitBoolConstantExpr(BoolConstantExpr boolConstantExpr); @Override void visitBreakStmt(BreakStmt breakStmt); @Override void visitContinueStmt(ContinueStmt continueStmt); @Override void visitDiscardStmt(DiscardStmt discardStmt); @Override void visitReturnStmt(ReturnStmt returnStmt); @Override void visitExprStmt(ExprStmt exprStmt); @Override void visitFunctionCallExpr(FunctionCallExpr functionCallExpr); @Override void visitTypeConstructorExpr(TypeConstructorExpr typeConstructorExpr); @Override void visitQualifiedType(QualifiedType qualifiedType); @Override void visitBasicType(BasicType basicType); @Override void visitSamplerType(SamplerType samplerType); @Override void visitImageType(ImageType imageType); @Override void visitVoidType(VoidType voidType); @Override void visitAtomicIntType(AtomicIntType atomicIntType); @Override void visitNullStmt(NullStmt nullStmt); @Override void visitWhileStmt(WhileStmt whileStmt); @Override void visitForStmt(ForStmt forStmt); @Override void visitDoStmt(DoStmt doStmt); @Override void visitTernaryExpr(TernaryExpr ternaryExpr); @Override void visitArrayIndexExpr(ArrayIndexExpr arrayIndexExpr); @Override void visitStructNameType(StructNameType structNameType); @Override void visitArrayType(ArrayType arrayType); @Override void visitArrayConstructorExpr(ArrayConstructorExpr arrayConstructorExpr); @Override void visitStructDefinitionType(StructDefinitionType structDefinitionType); @Override void visitSwitchStmt(SwitchStmt switchStmt); @Override void visitDefaultCaseLabel(DefaultCaseLabel defaultCaseLabel); @Override void visitExprCaseLabel(ExprCaseLabel exprCaseLabel); @Override void visitInterfaceBlock(InterfaceBlock interfaceBlock); @Override void visitDefaultLayout(DefaultLayout defaultLayout); @Override void visitTranslationUnit(TranslationUnit translationUnit); @Override void visitPragmaStatement(PragmaStatement pragmaStatement); @Override void visitExtensionStatement(ExtensionStatement extensionStatement); @Override String toString(); static String defaultIndent(int level); static void emitGraphicsFuzzDefines(PrintStream out,
                                             ShadingLanguageVersion shadingLanguageVersion); static final int DEFAULT_INDENTATION_WIDTH; static final Supplier<String> DEFAULT_NEWLINE_SUPPLIER; }
@Test public void testParseAndPrintSwitch() throws Exception { final String program = "" + "void main()\n" + "{\n" + PrettyPrinterVisitor.defaultIndent(1) + "int x = 3;\n" + PrettyPrinterVisitor.defaultIndent(1) + "switch(x)\n" + PrettyPrinterVisitor.defaultIndent(2) + "{\n" + PrettyPrinterVisitor.defaultIndent(3) + "case 0:\n" + PrettyPrinterVisitor.defaultIndent(3) + "x ++;\n" + PrettyPrinterVisitor.defaultIndent(3) + "case 1:\n" + PrettyPrinterVisitor.defaultIndent(3) + "case 3:\n" + PrettyPrinterVisitor.defaultIndent(3) + "x ++;\n" + PrettyPrinterVisitor.defaultIndent(3) + "break;\n" + PrettyPrinterVisitor.defaultIndent(3) + "case 4:\n" + PrettyPrinterVisitor.defaultIndent(3) + "break;\n" + PrettyPrinterVisitor.defaultIndent(3) + "default:\n" + PrettyPrinterVisitor.defaultIndent(3) + "break;\n" + PrettyPrinterVisitor.defaultIndent(2) + "}\n" + "}\n"; TranslationUnit tu = ParseHelper.parse(program); CompareAstsDuplicate.assertEqualAsts(tu, tu.clone()); }