示例#1
0
  @Override
  public void handle(ProcessorManager processorManager, RoundEnvironment roundEnvironment) {
    for (BaseContainerHandler containerHandler : handlers) {
      containerHandler.handle(processorManager, roundEnvironment);
    }

    ContentProviderValidator validator = new ContentProviderValidator();
    Collection<ContentProviderDefinition> contentProviderDefinitions = providerMap.values();
    for (ContentProviderDefinition contentProviderDefinition : contentProviderDefinitions) {
      if (validator.validate(processorManager, contentProviderDefinition)) {
        WriterUtils.writeBaseDefinition(contentProviderDefinition, processorManager);
      }
    }
    List<DatabaseWriter> databaseWriters = getManagerWriters();
    for (DatabaseWriter databaseWriter : databaseWriters) {
      try {
        JavaWriter javaWriter =
            new JavaWriter(
                processorManager
                    .getProcessingEnvironment()
                    .getFiler()
                    .createSourceFile(databaseWriter.getSourceFileName())
                    .openWriter());
        databaseWriter.write(javaWriter);
        javaWriter.close();
      } catch (IOException e) {
        processorManager.getMessager().printMessage(Diagnostic.Kind.WARNING, e.getMessage());
      }
    }

    if (roundEnvironment.processingOver()) {
      try {
        JavaWriter staticFlowManager =
            new JavaWriter(
                processorManager
                    .getProcessingEnvironment()
                    .getFiler()
                    .createSourceFile(
                        Classes.FLOW_MANAGER_PACKAGE
                            + "."
                            + Classes.DATABASE_HOLDER_STATIC_CLASS_NAME)
                    .openWriter());
        new FlowManagerHolderWriter(processorManager).write(staticFlowManager);

        staticFlowManager.close();
      } catch (IOException e) {
        processorManager.getMessager().printMessage(Diagnostic.Kind.WARNING, e.getMessage());
      }
    }
  }
  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();
  }
示例#3
0
 private void emitClose(JavaWriter writer) throws IOException {
   writer.endMethod();
   writer.endType();
   writer.close();
 }