/**
   * ソース生成.
   *
   * @throws IOException
   * @author vvakame
   */
  public void write() throws IOException {

    Filer filer = processingEnv.getFiler();
    String generateClassName = classElement.asType().toString() + postfix;
    JavaFileObject fileObject = filer.createSourceFile(generateClassName, classElement);
    Template.write(fileObject, g);
  }
Exemplo n.º 2
0
 @Override
 public Reader getResource(String resourcePath) throws IOException {
   return processingEnv
       .getFiler()
       .getResource(StandardLocation.CLASS_OUTPUT, "", resourcePath)
       .openReader(true);
 }
Exemplo n.º 3
0
 @Override
 public Writer newResource(String resourcePath) throws IOException {
   return processingEnv
       .getFiler()
       .createResource(StandardLocation.CLASS_OUTPUT, "", resourcePath)
       .openWriter();
 }
Exemplo n.º 4
0
  public void writeXSD(Model m) throws IOException {
    try {
      for (MainInfo main : m.getMains()) {
        List<Element> sources = new ArrayList<Element>();
        sources.add(main.getElement());
        sources.addAll(main.getInterceptorElements());

        FileObject o =
            processingEnv
                .getFiler()
                .createResource(
                    StandardLocation.CLASS_OUTPUT,
                    main.getAnnotation().outputPackage(),
                    main.getAnnotation().outputName(),
                    sources.toArray(new Element[0]));
        BufferedWriter bw = new BufferedWriter(o.openWriter());
        try {
          assembleXSD(bw, m, main);
        } finally {
          bw.close();
        }
      }
    } catch (FilerException e) {
      if (e.getMessage().contains("Source file already created")) return;
      throw e;
    }
  }
Exemplo n.º 5
0
 @Override
 public synchronized void init(ProcessingEnvironment env) {
   super.init(env);
   elementUtils = env.getElementUtils();
   typeUtils = env.getTypeUtils();
   filer = env.getFiler();
 }
Exemplo n.º 6
0
 @Override
 public synchronized void init(ProcessingEnvironment env) {
   super.init(env);
   mLogger = new Logger(env);
   mElements = env.getElementUtils();
   mTypes = env.getTypeUtils();
   mFiler = env.getFiler();
 }
Exemplo n.º 7
0
  @Override
  public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    Elements elementUtils = processingEnv.getElementUtils();
    Types typeUtils = processingEnv.getTypeUtils();
    Filer filer = processingEnv.getFiler();
    Messager messager = processingEnv.getMessager();
  }
 @Override
 public synchronized void init(ProcessingEnvironment processingEnv) {
   super.init(processingEnv);
   elements = processingEnv.getElementUtils();
   types = processingEnv.getTypeUtils();
   messager = processingEnv.getMessager();
   factoryWriter = new FactoryWriter(processingEnv.getFiler());
   providedChecker = new ProvidedChecker(messager);
   declarationFactory = new AutoFactoryDeclaration.Factory(elements, messager);
   factoryDescriptorGenerator =
       new FactoryDescriptorGenerator(messager, elements, declarationFactory);
 }
  @Override
  public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    filer = processingEnv.getFiler();
    messager = processingEnv.getMessager();
    eltUtils = processingEnv.getElementUtils();

    outputDir = processingEnv.getOptions().get("structoutputdir");
    outputDir = outputDir == null ? "gensrc" : outputDir;

    basedir = processingEnv.getOptions().get("basedir");
  }
Exemplo n.º 10
0
  /**
   * Velocity の実行(Javaソース用)。出力先はパッケージ名とクラス名から自動生成。
   *
   * @param context VelocityContext
   * @param pkgName パッケージ名
   * @param clsName クラス名
   * @param templ Velocityテンプレート名。
   * @throws Exception
   */
  protected void applyTemplate(
      VelocityContext context, String pkgName, String clsName, String templ) throws Exception {
    context.put("packageName", pkgName);
    context.put("className", clsName);
    context.put("environment", environment);

    Template template = getVelocityTemplate(templ);
    Filer filer = environment.getFiler();
    JavaFileObject file = filer.createSourceFile(pkgName + '.' + clsName);
    PrintWriter writer = new PrintWriter(file.openWriter());
    template.merge(context, writer);
    writer.close();
  }
Exemplo n.º 11
0
  /**
   * Velocity の実行(リソース用)。出力先はパッケージ名とリソース名から自動生成。
   *
   * @param context VelocityContext
   * @param pkgName パッケージ名
   * @param resName リソース名
   * @param templ Velocityテンプレート名。
   * @throws Exception
   */
  public void applyTemplateText(
      VelocityContext context, String pkgName, String resName, String templ) throws Exception {
    context.put("packageName", pkgName);
    context.put("resourceName", resName);
    context.put("environment", environment);

    Template template = getVelocityTemplate(templ);

    String resFullPath = pkgName.replace('.', '/') + "/" + resName;
    Filer filer = environment.getFiler();
    FileObject file =
        filer.createResource(StandardLocation.SOURCE_OUTPUT, "", resFullPath, (Element[]) null);
    PrintWriter writer = new PrintWriter(file.openWriter());
    template.merge(context, writer);
    writer.close();
  }
Exemplo n.º 12
0
  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();
  }
Exemplo n.º 13
0
 /**
  * Init processor<br>
  * get filer, messager<br>
  * get options
  */
 @Override
 public void init(ProcessingEnvironment processingEnv) {
   super.init(processingEnv);
   messager = processingEnv.getMessager();
   filer = processingEnv.getFiler();
 }
Exemplo n.º 14
0
  @Override
  public synchronized void init(ProcessingEnvironment env) {
    super.init(env);

    filer = env.getFiler();
  }
Exemplo n.º 15
0
 @Override
 public void init(ProcessingEnvironment env) {
   filer = env.getFiler();
   messager = env.getMessager();
   elements = env.getElementUtils();
 }
Exemplo n.º 16
0
 @Override
 public Writer newClass(String className) throws IOException {
   return processingEnv.getFiler().createSourceFile(className).openWriter();
 }