Beispiel #1
0
  public void write(final Type type, final EnumConstraint<String> constraint) throws IOException {
    JavaWriter jw = javaClassWriter.getOutput();
    jw.emitPackage(options.getPackageName());
    javaClassWriter.writeImports(Collections.<String>emptySet());

    if (type.getDescription() != null) {
      jw.emitJavadoc(type.getDescription());
    }

    String enumName = Names.capitalize(type.getCanonicalName());
    jw.beginType(enumName, "enum", EnumSet.of(PUBLIC));

    Iterator<String> valuesIterator = constraint.getValues().iterator();
    while (valuesIterator.hasNext()) {
      String value = valuesIterator.next();

      javaClassWriter.writeEnumValue(value, !valuesIterator.hasNext());
    }

    jw.endType();
  }
  public void generate() throws IOException {
    String qualifiedGeneratedClassName =
        String.format("%s.%s", Constants.REALM_PACKAGE_NAME, Constants.DEFAULT_MODULE_CLASS_NAME);
    JavaFileObject sourceFile = env.getFiler().createSourceFile(qualifiedGeneratedClassName);
    JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
    writer.setIndent("    ");

    writer.emitPackage(Constants.REALM_PACKAGE_NAME);
    writer.emitEmptyLine();

    Map<String, Boolean> attributes = new HashMap<String, Boolean>();
    attributes.put("allClasses", Boolean.TRUE);
    writer.emitAnnotation(RealmModule.class, attributes);
    writer.beginType(
        qualifiedGeneratedClassName, // full qualified name of the item to generate
        "class", // the type of the item
        Collections.<Modifier>emptySet(), // modifiers to apply
        null); // class to extend
    writer.emitEmptyLine();

    writer.endType();
    writer.close();
  }
 private void beginType(String newSourceName, JavaWriter writer) throws IOException {
   writer.beginType(newSourceName, "class", EnumSet.of(Modifier.PUBLIC));
 }