code: public void writeTo(Filer filer) throws IOException {
      String fileName = packageName.isEmpty()
          ? typeSpec.name
          : packageName + "." + typeSpec.name;
      List<Element> originatingElements = typeSpec.originatingElements;
      JavaFileObject filerSourceFile = filer.createSourceFile(fileName,
          originatingElements.toArray(new Element[originatingElements.size()]));
      try (Writer writer = filerSourceFile.openWriter()) {
        writeTo(writer);
      } catch (Exception e) {
        try {
          filerSourceFile.delete();
        } catch (Exception ignored) {
        }
        throw e;
      }
    }
docs: Writes this to {@code filer}.