Java Code Examples for javax.annotation.processing.RoundEnvironment#processingOver()

The following examples show how to use javax.annotation.processing.RoundEnvironment#processingOver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationProcessor.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  if (roundEnv.processingOver()) {
    Filer filer = processingEnv.getFiler();
    try {
      JavaFileObject sourceFile = filer.createSourceFile("com.example.buck.Test");
      try (OutputStream out = sourceFile.openOutputStream()) {
        out.write("package com.example.buck; class Test { }".getBytes());
      }
    } catch (IOException e) {
      throw new AssertionError(e);
    }
  }

  return false;
}
 
Example 2
Source File: MojoDescriptorGleaner.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  for (TypeElement element : getAnnotatedTypes(roundEnv)) {
    MojoDescriptor descriptor = processType(element);
    descriptors.put(descriptor.getImplementation(), descriptor);
  }

  if (roundEnv.processingOver() && !descriptors.isEmpty()) {
    try {
      writeMojosXml(descriptors);
    } catch (IOException e) {
      // TODO it'd be nice to capture IOException somewhere too
      processingEnv.getMessager().printMessage(Kind.ERROR, "Could not create aggregate output " + e.getMessage());
    }
  }

  return false; // don't claim the annotations, other processors are welcome to use them
}
 
Example 3
Source File: TestSimpleAddRemove.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
//            System.err.println("TestProcessor.process " + roundEnv);
            JavacTask task = JavacTask.instance(processingEnv);
            if (++round == 1) {
                switch (ak) {
                    case ADD_IN_PROCESSOR:
                        task.addTaskListener(listener);
                        break;
                    case ADD_IN_LISTENER:
                        addInListener(task, TaskEvent.Kind.ANALYZE, listener);
                        break;
                }
            } else if (roundEnv.processingOver()) {
                switch (rk) {
                    case REMOVE_IN_PROCESSOR:
                        task.removeTaskListener(listener);
                        break;
                    case REMOVE_IN_LISTENER:
                        removeInListener(task, TaskEvent.Kind.GENERATE, listener);
                        break;
                }
            }
            return true;
        }
 
Example 4
Source File: CreateSymbols.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    try {
        if (renv.processingOver())
            createSymbols();
    } catch (IOException e) {
        processingEnv.getMessager()
                .printMessage(Diagnostic.Kind.ERROR, e.getLocalizedMessage());
    } catch (Throwable t) {
        Throwable cause = t.getCause();
        if (cause == null)
            cause = t;
        processingEnv.getMessager()
                .printMessage(Diagnostic.Kind.ERROR, cause.getLocalizedMessage());
    }
    return true;
}
 
Example 5
Source File: T7159016.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver() || written++ > 0) {
        return false;
    }
    messager.printMessage(Diagnostic.Kind.NOTE, "writing Generated.java");
    try {
        Writer w = processingEnv.getFiler().createSourceFile("p.Generated").openWriter();
        try {
            w.write("package p; public class Generated { public static void m() { } }");
        } finally {
            w.close();
        }
    } catch (IOException x) {
        messager.printMessage(Diagnostic.Kind.ERROR, x.toString());
    }
    return true;
}
 
Example 6
Source File: AbstractGeneratingProcessor.java    From doma with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  if (roundEnv.processingOver()) {
    return true;
  }
  for (TypeElement a : annotations) {
    final TypeElementMetaFactory<M> factory = createTypeElementMetaFactory();
    for (TypeElement typeElement : ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(a))) {
      handleTypeElement(
          typeElement,
          t -> {
            M meta = factory.createTypeElementMeta(typeElement);
            if (!meta.isError()) {
              generate(typeElement, meta);
            }
          });
    }
  }
  return true;
}
 
Example 7
Source File: T6350057.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment) {
    if (!roundEnvironment.processingOver())
        for(Element element : roundEnvironment.getRootElements())
            element.accept(new LocalVarAllergy(), null);
    return true;
}
 
Example 8
Source File: ModelChecker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver())
        return true;

    Trees trees = Trees.instance(processingEnv);

    TypeElement testAnno = elements.getTypeElement("Check");
    for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) {
        TreePath p = trees.getPath(elem);
        new IntersectionCastTester(trees).scan(p, null);
    }
    return true;
}
 
Example 9
Source File: ModelChecker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver())
        return true;

    Trees trees = Trees.instance(processingEnv);

    TypeElement testAnno = elements.getTypeElement("Check");
    for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) {
        TreePath p = trees.getPath(elem);
        new MulticatchParamTester(trees).scan(p, null);
    }
    return true;
}
 
Example 10
Source File: SmartEventProcessor.java    From SmartEventBus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
    System.out.println(TAG + "roundEnvironment: " + roundEnvironment);
    if (!roundEnvironment.processingOver() && !isGenerateTargetClass) {
        processAnnotations(roundEnvironment);
        generateBusCode();
    }
    return true;
}
 
Example 11
Source File: SpringBootWebProcessor.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  if  (roundEnv.processingOver()) {
    getSession().close();
    return true;
  }
  Set<String> paths = new HashSet<>();

  for (TypeElement typeElement : annotations) {

    if (typeElement.getSimpleName().toString().endsWith("RestController")) {
      for (Element element : roundEnv.getElementsAnnotatedWith(typeElement)) {
        if (element instanceof TypeElement) {
          Set<String> detectedPaths = element.getAnnotationMirrors()
            .stream()
            .filter(a -> a.getAnnotationType().toString().contains(REQUESTMAPPING))
            .flatMap(a -> a.getElementValues().entrySet().stream())
            .filter(e -> PATH_METHODS.contains(e.getKey().getSimpleName().toString()))
            .map(p -> p.getValue().getValue().toString().replace('"', ' ').trim())
            .collect(Collectors.toSet());

          if (detectedPaths.isEmpty()) {
            paths.add("/");
          } else {
            paths.addAll(detectedPaths);
          }
        }
      }
    }
  }
  
  LOGGER.info("Found Spring web annotation!");
  Map<String, Object> config = new HashMap<String, Object>();
  config.put(DEKORATE_SPRING_WEB_PATH, findShortedCommonPath(paths));
  addAnnotationConfiguration(config);
  return false;
}
 
Example 12
Source File: ByteCodePatchingAnnotationProcessor.java    From arvo2parquet with MIT License 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  if (roundEnv.processingOver()) return true;

  // looking for at least one class annotated with @InvokeByteCodePatching
  final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(InvokeByteCodePatching.class);
  if (elements.size() <= 0) return false;

  //noinspection LoopStatementThatDoesntLoop
  for (final Element elem : elements) {
    // is invalid to apply this annotation to anything other than a class type
    if (!elem.getKind().isClass() || !(elem instanceof QualifiedNameable)) {
      throw new AnnotationFormatError(elem.toString() + " Java type not supported by " + InvokeByteCodePatching.class);
    }

    InvokeByteCodePatching annotation = elem.getAnnotation(InvokeByteCodePatching.class);
    if (annotation == null) {
      throw new AnnotationFormatError("invalid annotation " + InvokeByteCodePatching.class);
    }

    break; // found a class marked by the @InvokeByteCodePatching annotation
  }

  try {
    final String classesBldDir = System.getProperty("maven.build.classes.dir", "target/classes");
    ValidateAvroSchema.bytecodePatchAvroSchemaClass(new File(classesBldDir));
  } catch (ClassNotFoundException|IOException e) {
    uncheckedExceptionThrow(e);
  }

  return true; // no further processing of this annotation type
}
 
Example 13
Source File: ModelChecker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver())
        return true;

    Trees trees = Trees.instance(processingEnv);

    TypeElement testAnno = elements.getTypeElement("Check");
    for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) {
        TreePath p = trees.getPath(elem);
        new IntersectionCastTester(trees).scan(p, null);
    }
    return true;
}
 
Example 14
Source File: Test.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) {
            messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt);
        }
    }
    return true;
}
 
Example 15
Source File: ModelChecker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver())
        return true;

    Trees trees = Trees.instance(processingEnv);

    TypeElement testAnno = elements.getTypeElement("Check");
    for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) {
        TreePath p = trees.getPath(elem);
        new IntersectionCastTester(trees).scan(p, null);
    }
    return true;
}
 
Example 16
Source File: DockerAnnotationProcessor.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  Session session = getSession();
  if  (roundEnv.processingOver()) {
    session.close();
    return true;
  }
  for (TypeElement typeElement : annotations) {
    for (Element mainClass : roundEnv.getElementsAnnotatedWith(typeElement)) {
      process("docker", mainClass, DockerBuild.class);
    }
  }
  return false;
}
 
Example 17
Source File: AbstractElementsListProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
protected void writeElements(RoundEnvironment roundEnv) {
  if (roundEnv.processingOver()) {
    Filer filer = processingEnv.getFiler();
    try (Writer w = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "elements.lst").openWriter()) {
      for (Map.Entry<String, Element> entry : elements.entrySet()) {
        w.write(entry.getKey() + " " + entry.getValue().getKind() + "\n");
      }
    } catch (IOException e) {
      e.printStackTrace();
      processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
    }
  }
}
 
Example 18
Source File: T6350057.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment) {
    if (!roundEnvironment.processingOver())
        for(Element element : roundEnvironment.getRootElements())
            element.accept(new LocalVarAllergy(), null);
    return true;
}
 
Example 19
Source File: T6350057.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment) {
    if (!roundEnvironment.processingOver())
        for(Element element : roundEnvironment.getRootElements())
            element.accept(new LocalVarAllergy(), null);
    return true;
}
 
Example 20
Source File: NaluProcessor.java    From nalu with Apache License 2.0 4 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
  try {
    if (roundEnv.processingOver()) {
      if (!roundEnv.errorRaised()) {
        this.validate(roundEnv);
        this.generateLastRound();
        this.store(metaModel);
      }
      this.processorUtils.createNoteMessage("Nalu-Processor finished ... processing takes: " +
                                                this.stopwatch.stop()
                                                              .toString());
    } else {
      if (annotations.size() > 0) {
        for (TypeElement annotation : annotations) {
          if (Application.class.getCanonicalName()
                               .equals(annotation.toString())) {
            handleApplicationAnnotation(roundEnv);
          } else if (BlockController.class.getCanonicalName()
                                          .equals(annotation.toString())) {
            handleBlockControllerAnnotation(roundEnv);
          } else if (CompositeController.class.getCanonicalName()
                                              .equals(annotation.toString())) {
            handleCompositeControllerAnnotation(roundEnv);
          } else if (Controller.class.getCanonicalName()
                                     .equals(annotation.toString())) {
            handleControllerAnnotation(roundEnv);
          } else if (Debug.class.getCanonicalName()
                                .equals(annotation.toString())) {
            handleDebugAnnotation(roundEnv);
          } else if (ErrorPopUpController.class.getCanonicalName()
                                               .equals(annotation.toString())) {
            handleErrorPopUpControllerAnnotation(roundEnv);
          } else if (Filters.class.getCanonicalName()
                                  .equals(annotation.toString())) {
            handleFiltersAnnotation(roundEnv);
          } else if (Handler.class.getCanonicalName()
                                  .equals(annotation.toString())) {
            handleHandlerAnnotation(roundEnv);
          } else if (Module.class.getCanonicalName()
                                 .equals(annotation.toString())) {
            handleModuleAnnotation(roundEnv);
          } else if (Modules.class.getCanonicalName()
                                  .equals(annotation.toString())) {
            handleModulesAnnotation(roundEnv);
          } else if (PopUpController.class.getCanonicalName()
                                          .equals(annotation.toString())) {
            handlePopUpControllerAnnotation(roundEnv);
          } else if (Shell.class.getCanonicalName()
                                .equals(annotation.toString())) {
            handleShellAnnotation(roundEnv);
          } else if (Tracker.class.getCanonicalName()
                                  .equals(annotation.toString())) {
            handleTrackerAnnotation(roundEnv);
          }
        }
      }
    }
  } catch (ProcessorException e) {
    this.processorUtils.createErrorMessage(e.getMessage());
    //    }/
    return true;
  }
  return true;
}