@Override public String toString() { StringBuilder out = new StringBuilder(); try { CodeWriter codeWriter = new CodeWriter(out); emit(codeWriter, null, Collections.emptySet()); return out.toString(); } catch (IOException e) { throw new AssertionError(); } }
private void emitLiteral(Object o) throws IOException { if (o instanceof TypeSpec) { TypeSpec typeSpec = (TypeSpec) o; typeSpec.emit(this, null, Collections.emptySet()); } else if (o instanceof AnnotationSpec) { AnnotationSpec annotationSpec = (AnnotationSpec) o; annotationSpec.emit(this, true); } else if (o instanceof CodeBlock) { CodeBlock codeBlock = (CodeBlock) o; emit(codeBlock); } else { emitAndIndent(String.valueOf(o)); } }
private void emit(CodeWriter codeWriter) throws IOException { codeWriter.pushPackage(packageName); if (!fileComment.isEmpty()) { codeWriter.emitComment(fileComment); } if (!packageName.isEmpty()) { codeWriter.emit("package $L;\n", packageName); codeWriter.emit("\n"); } if (!staticImports.isEmpty()) { for (String signature : staticImports) { codeWriter.emit("import static $L;\n", signature); } codeWriter.emit("\n"); } int importedTypesCount = 0; for (ClassName className : new TreeSet<>(codeWriter.importedTypes().values())) { if (skipJavaLangImports && className.packageName().equals("java.lang")) continue; codeWriter.emit("import $L;\n", className.withoutAnnotations()); importedTypesCount++; } if (importedTypesCount > 0) { codeWriter.emit("\n"); } typeSpec.emit(codeWriter, null, Collections.emptySet()); codeWriter.popPackage(); }
Map.Entry<String, TypeSpec> enumConstant = i.next(); if (!firstMember) codeWriter.emit("\n"); enumConstant.getValue().emit(codeWriter, enumConstant.getKey(), Collections.emptySet()); firstMember = false; if (i.hasNext()) { typeSpec.emit(codeWriter, null, kind.implicitTypeModifiers); firstMember = false;
@Override public String toString() { StringBuilder out = new StringBuilder(); try { CodeWriter codeWriter = new CodeWriter(out); emit(codeWriter, null, Collections.<Modifier>emptySet()); return out.toString(); } catch (IOException e) { throw new AssertionError(); } }
@Override public String toString() { StringBuilder out = new StringBuilder(); try { CodeWriter codeWriter = new CodeWriter(out); emit(codeWriter, null, Collections.<Modifier>emptySet()); return out.toString(); } catch (IOException e) { throw new AssertionError(); } }
private void emitLiteral(Object o) throws IOException { if (o instanceof TypeSpec) { TypeSpec typeSpec = (TypeSpec) o; typeSpec.emit(this, null, Collections.<Modifier>emptySet()); } else if (o instanceof AnnotationSpec) { AnnotationSpec annotationSpec = (AnnotationSpec) o; annotationSpec.emit(this, true); } else if (o instanceof CodeBlock) { CodeBlock codeBlock = (CodeBlock) o; emit(codeBlock); } else { emitAndIndent(String.valueOf(o)); } }
private void emitLiteral(Object o) throws IOException { if (o instanceof TypeSpec) { TypeSpec typeSpec = (TypeSpec) o; typeSpec.emit(this, null, Collections.<Modifier>emptySet()); } else if (o instanceof AnnotationSpec) { AnnotationSpec annotationSpec = (AnnotationSpec) o; annotationSpec.emit(this, true); } else if (o instanceof CodeBlock) { CodeBlock codeBlock = (CodeBlock) o; emit(codeBlock); } else { emitAndIndent(String.valueOf(o)); } }
private void emit(CodeWriter codeWriter) throws IOException { codeWriter.pushPackage(packageName); if (!fileComment.isEmpty()) { codeWriter.emitComment(fileComment); } if (!packageName.isEmpty()) { codeWriter.emit("package $L;\n", packageName); codeWriter.emit("\n"); } if (!staticImports.isEmpty()) { for (String signature : staticImports) { codeWriter.emit("import static $L;\n", signature); } codeWriter.emit("\n"); } int importedTypesCount = 0; for (ClassName className : new TreeSet<>(codeWriter.importedTypes().values())) { if (skipJavaLangImports && className.packageName().equals("java.lang")) continue; codeWriter.emit("import $L;\n", className); importedTypesCount++; } if (importedTypesCount > 0) { codeWriter.emit("\n"); } typeSpec.emit(codeWriter, null, Collections.<Modifier>emptySet()); codeWriter.popPackage(); }
private void emit(CodeWriter codeWriter) throws IOException { codeWriter.pushPackage(packageName); if (!fileComment.isEmpty()) { codeWriter.emitComment(fileComment); } if (!packageName.isEmpty()) { codeWriter.emit("package $L;\n", packageName); codeWriter.emit("\n"); } if (!staticImports.isEmpty()) { for (String signature : staticImports) { codeWriter.emit("import static $L;\n", signature); } codeWriter.emit("\n"); } int importedTypesCount = 0; for (ClassName className : new TreeSet<>(codeWriter.importedTypes().values())) { if (skipJavaLangImports && className.packageName().equals("java.lang")) continue; codeWriter.emit("import $L;\n", className); importedTypesCount++; } if (importedTypesCount > 0) { codeWriter.emit("\n"); } typeSpec.emit(codeWriter, null, Collections.<Modifier>emptySet()); codeWriter.popPackage(); }