List of usage examples for javax.annotation.processing RoundEnvironment processingOver
boolean processingOver();
From source file:com.github.pellaton.jazoon2012.JazoonProcessor.java
/** * @see AbstractProcessor#process(Set, RoundEnvironment) *//* w w w . j av a2 s . c o m*/ @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.errorRaised() && !roundEnv.processingOver()) { processRound(annotations, roundEnv); } return false; }
From source file:org.ez18n.apt.processor.GwtXmlProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { return true; }/* w ww . j a v a2 s. c om*/ final List<TypeElement> bundleTypes = new ArrayList<TypeElement>(); for (Element element : roundEnv.getElementsAnnotatedWith(MessageBundle.class)) { if (element.getKind() != ElementKind.INTERFACE) { continue; } final TypeElement bundleType = (TypeElement) element; bundleTypes.add(bundleType); } if (bundleTypes.isEmpty()) { return true; } String packageName = null; for (TypeElement typeElement : bundleTypes) { String typeElementPackage = typeElement.getEnclosingElement().toString(); if (packageName == null) { packageName = typeElementPackage; } else { packageName = intersectPackage(packageName, typeElementPackage); } } try { final FileObject file = processingEnv.getFiler().createResource(SOURCE_OUTPUT, packageName == null ? "net.courtanet.b2c" : packageName, "Generated.gwt.xml"); final Writer writer = file.openWriter(); writer.write(getCode(bundleTypes)); writer.close(); } catch (FilerException e) { return false; } catch (IOException e) { processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage()); } return false; }
From source file:org.ez18n.apt.processor.LabelBundleProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { return true; }/*from w w w . j a va2 s. c o m*/ final List<LabelTemplateMethod> methods = new ArrayList<LabelTemplateMethod>(); for (Element element : roundEnv.getElementsAnnotatedWith(MessageBundle.class)) { if (element.getKind() != ElementKind.INTERFACE) { continue; } final TypeElement bundleType = (TypeElement) element; processLabels(bundleType, methods); try { FileObject file = null; switch (generationType) { case SOURCE: file = processingEnv.getFiler().createSourceFile(getTargetClassName(bundleType), bundleType); break; case RESSOURCE: file = processingEnv.getFiler().createResource(SOURCE_OUTPUT, bundleType.getEnclosingElement().toString(), getTargetSimpleName(bundleType) + ".properties"); break; } final Writer writer = file.openWriter(); writer.write(getCode(bundleType, methods)); writer.close(); } catch (IOException e) { processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), bundleType); } finally { methods.clear(); } } return false; }
From source file:blue.lapis.pore.ap.event.EventVerifierProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.processingOver()) { for (TypeElement anno : annotations) { for (Element e : roundEnv.getElementsAnnotatedWith(anno)) { if (e.getKind() != ElementKind.CLASS) { processingEnv.getMessager().printMessage(ERROR, "Found @" + anno.getSimpleName() + " annotation on a " + e.getKind().name() + " element instead of a class element", e);/*from w w w . j a v a 2s . co m*/ continue; } TypeElement type = (TypeElement) e; verifySuperClass(type); verifyPackage(type); verifyName(type); verifyEnclosedElements(type); } } } return false; }
From source file:me.oriley.shiv.ShivProcessor.java
@Override public boolean process(@NonNull Set<? extends TypeElement> annotations, @NonNull RoundEnvironment env) { if (env.processingOver()) { return true; }/*from w w w. j a va 2 s .c om*/ try { final Map<TypeElement, BindingManager> bindings = new HashMap<>(); collectBindings(env, bindings, BindView.class); collectBindings(env, bindings, BindExtra.class); collectBindings(env, bindings, BindPreference.class); collectBindings(env, bindings, BindInstance.class); collectBindings(env, bindings, BindNonConfigurationInstance.class); collectBindings(env, bindings, BindService.class); for (BindingManager manager : bindings.values()) { String packageName = getPackageName(manager.hostType); writeToFile(packageName, manager.createBinder(this)); } } catch (ShivException e) { error(e.getMessage()); return true; } return false; }
From source file:ch.rasc.constgen.ConstAnnotationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Running " + getClass().getSimpleName()); if (roundEnv.processingOver() || annotations.size() == 0) { return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS; }//from w w w .j a v a 2 s .c o m if (roundEnv.getRootElements() == null || roundEnv.getRootElements().isEmpty()) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "No sources to process"); return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS; } for (TypeElement annotation : annotations) { Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation); boolean bsoncodecProject = annotation.getQualifiedName() .contentEquals("ch.rasc.bsoncodec.annotation.BsonDocument"); for (Element element : elements) { try { TypeElement typeElement = (TypeElement) element; CodeGenerator codeGen = new CodeGenerator(typeElement, this.processingEnv.getElementUtils(), bsoncodecProject); JavaFileObject jfo = this.processingEnv.getFiler() .createSourceFile(codeGen.getPackageName() + "." + codeGen.getClassName()); try (Writer writer = jfo.openWriter()) { codeGen.generate(writer); } } catch (Exception e) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage()); } } } return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS; }
From source file:com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.errorRaised() && !roundEnv.processingOver()) { processRound(annotations, roundEnv); }/*from w w w. j a va 2 s . c om*/ return false; }
From source file:org.squashtest.tm.tools.annotation.processor.DynamicComponentProcessor.java
/** * @see javax.annotation.processing.AbstractProcessor#process(java.util.Set, * javax.annotation.processing.RoundEnvironment) */// www . j a v a2s . c o m @Override public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) { enqueueComponents(roundEnvironment); if (roundEnvironment.processingOver()) { processComponents(); } return true; }
From source file:net.minecrell.quartz.mappings.processor.MappingsGeneratorProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { return false; }//from w w w . j a v a2 s . c om List<TypeElement> mappingClasses = new ArrayList<>(); for (Element element : roundEnv.getElementsAnnotatedWith(Mapping.class)) { if (element instanceof TypeElement) { mappingClasses.add((TypeElement) element); } } if (mappingClasses.isEmpty()) { return true; } try { FileObject file = this.processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", "mappings.json"); Map<String, MappedClass> mappings; try (Reader reader = file.openReader(false)) { mappings = Mappings.read(reader); } catch (IOException ignored) { mappings = new HashMap<>(); } ClassMapper classMappings = createMapper(mappingClasses); // We need to remap the descriptors of the fields and methods, use ASM for convenience Remapper unmapper = classMappings.createUnmapper(); for (TypeElement mappingClass : mappingClasses) { String internalName = getInternalName(mappingClass); Mapping annotation = mappingClass.getAnnotation(Mapping.class); String mappedName = annotation.value(); if (mappedName.isEmpty()) { mappedName = internalName; } MappedClass mapping = new MappedClass(mappedName); Accessible accessible = mappingClass.getAnnotation(Accessible.class); if (accessible != null) { mapping.getAccess().put("", parseAccessible(accessible)); } for (Element element : mappingClass.getEnclosedElements()) { accessible = element.getAnnotation(Accessible.class); Constructor constructor = element.getAnnotation(Constructor.class); if (constructor != null) { if (accessible != null) { String constructorDesc = getDescriptor((ExecutableElement) element); mapping.getAccess().put("<init>" + constructorDesc, parseAccessible(accessible)); } continue; } annotation = element.getAnnotation(Mapping.class); if (annotation == null) { continue; } mappedName = annotation.value(); checkArgument(!mappedName.isEmpty(), "Mapping detection is not supported yet"); switch (element.getKind()) { case METHOD: ExecutableElement method = (ExecutableElement) element; String methodName = method.getSimpleName().toString(); String methodDesc = getDescriptor(method); mapping.getMethods().put(mappedName + unmapper.mapMethodDesc(methodDesc), methodName); if (accessible != null) { mapping.getAccess().put(methodName + methodDesc, parseAccessible(accessible)); } break; case FIELD: case ENUM_CONSTANT: VariableElement field = (VariableElement) element; String fieldName = field.getSimpleName().toString(); mapping.getFields().put(mappedName + ':' + unmapper.mapDesc(getDescriptor(field)), fieldName); if (accessible != null) { mapping.getAccess().put(fieldName, parseAccessible(accessible)); } break; default: } } mappings.put(internalName, mapping); } // Generate JSON output file = this.processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "mappings.json"); try (Writer writer = file.openWriter()) { Mappings.write(writer, mappings); } return true; } catch (IOException e) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ExceptionUtils.getStackTrace(e)); throw new RuntimeException("Failed to create mappings.json", e); } }
From source file:com.spotify.docgenerator.JacksonJerseyAnnotationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { generateOutput();// w ww . j a va2 s . c om } else { processAnnotations(annotations, roundEnv); } return true; }