javax.annotation.processing.RoundEnvironment Java Examples
The following examples show how to use
javax.annotation.processing.RoundEnvironment.
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: ControllerAnnotationScanner.java From nalu with Apache License 2.0 | 6 votes |
private void handleAcceptParameters(RoundEnvironment roundEnvironment, Element element, ControllerModel controllerModel) throws ProcessorException { TypeElement typeElement = (TypeElement) element; List<Element> annotatedElements = this.processorUtils.getMethodFromTypeElementAnnotatedWith(this.processingEnvironment, typeElement, AcceptParameter.class); // validate AcceptParameterAnnotationValidator.builder() .roundEnvironment(roundEnvironment) .processingEnvironment(processingEnvironment) .controllerModel(controllerModel) .listOfAnnotatedElements(annotatedElements) .build() .validate(); // add to ControllerModel ... for (Element annotatedElement : annotatedElements) { ExecutableElement executableElement = (ExecutableElement) annotatedElement; AcceptParameter annotation = executableElement.getAnnotation(AcceptParameter.class); controllerModel.getParameterAcceptors() .add(new ParameterAcceptor(annotation.value(), executableElement.getSimpleName() .toString())); } }
Example #2
Source File: DocumentationProcessor.java From armeria with Apache License 2.0 | 6 votes |
private void processAnnotation(TypeElement annotationElement, RoundEnvironment roundEnv) { roundEnv.getElementsAnnotatedWith(annotationElement) .stream() .filter(element -> element.getKind() == ElementKind.METHOD) // Element is always ExecutableElement because it is a method. .forEachOrdered(element -> { try { processMethod((ExecutableElement) element); } catch (IOException e) { final StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); processingEnv.getMessager().printMessage( Kind.ERROR, "Could not process all elements" + System.lineSeparator() + writer, element); } }); }
Example #3
Source File: JibProcessor.java From dekorate with Apache License 2.0 | 6 votes |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { getSession().close(); return true; } for (TypeElement typeElement : annotations) { for (Element mainClass : roundEnv.getElementsAnnotatedWith(typeElement)) { JibBuild jib = mainClass.getAnnotation(JibBuild.class); if (jib == null) { continue; } process("jib", mainClass, JibBuild.class); } } return false; }
Example #4
Source File: TransportProcessor.java From transport with BSD 2-Clause "Simplified" License | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { try { processImpl(roundEnv); } catch (Exception e) { // We don't allow exceptions of any kind to propagate to the compiler try (StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter)) { e.printStackTrace(printWriter); fatalError(stringWriter.toString()); } catch (IOException ioe) { fatalError("Could not close resources " + ioe); } } // Universal processors should return false since other processor can be potentially acting on the same element return false; }
Example #5
Source File: ManagedAttributeValueTypeValidator.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Override public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) { Elements elementUtils = processingEnv.getElementUtils(); TypeElement annotationElement = elementUtils.getTypeElement(MANAGED_ATTRIBUTE_VALUE_TYPE_CLASS_NAME); for (Element e : roundEnv.getElementsAnnotatedWith(annotationElement)) { boolean isAbstract = isAbstract(annotationElement, e); if(!isAbstract) { checkAnnotationIsOnInterface(annotationElement, e); } if(!isContent(e)) { checkAllMethodsAreAccessors(e, isAbstract); } } return false; }
Example #6
Source File: AbstractCommandSpecProcessor.java From picocli with Apache License 2.0 | 6 votes |
private void buildMixin(Element element, RoundEnvironment roundEnv, Context context) { debugElement(element, "@Mixin"); if (element.asType().getKind() != TypeKind.DECLARED) { error(element, "@Mixin must have a declared type, not %s", element.asType()); return; } TypeElement type = (TypeElement) ((DeclaredType) element.asType()).asElement(); CommandSpec mixin = buildCommand(type, context, roundEnv); logger.fine("Built mixin: " + mixin + " from " + element); if (EnumSet.of(ElementKind.FIELD, ElementKind.PARAMETER).contains(element.getKind())) { VariableElement variableElement = (VariableElement) element; MixinInfo mixinInfo = new MixinInfo(variableElement, mixin); CommandSpec mixee = buildCommand(mixinInfo.enclosingElement(), context, roundEnv); Set<MixinInfo> mixinInfos = context.mixinInfoMap.get(mixee); if (mixinInfos == null) { mixinInfos = new HashSet<MixinInfo>(2); context.mixinInfoMap.put(mixee, mixinInfos); } mixinInfos.add(mixinInfo); logger.fine("Mixin name=" + mixinInfo.mixinName() + ", target command=" + mixee.userObject()); } }
Example #7
Source File: FactoryProcessor.java From toothpick with Apache License 2.0 | 6 votes |
private void createFactoriesForClassesAnnotatedWithInjectConstructor(RoundEnvironment roundEnv) { for (Element annotatedElement : ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(InjectConstructor.class))) { TypeElement annotatedTypeElement = (TypeElement) annotatedElement; List<ExecutableElement> constructorElements = ElementFilter.constructorsIn(annotatedTypeElement.getEnclosedElements()); if (constructorElements.size() != 1 || constructorElements.get(0).getAnnotation(Inject.class) != null) { error( constructorElements.get(0), "Class %s is annotated with @InjectInjectConstructor. Therefore, It must have one unique constructor and it should not be annotated with @Inject.", annotatedTypeElement.getQualifiedName()); } processInjectAnnotatedConstructor( constructorElements.get(0), mapTypeElementToConstructorInjectionTarget); } }
Example #8
Source File: MementoProcessor.java From memento with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) { Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(Retain.class); if (elements.isEmpty()) { return true; } //TODO: verify activity implements onFirstCreate verifyFieldsAccessible(elements); log("processing " + elements.size() + " fields"); Element hostActivity = elements.iterator().next().getEnclosingElement(); TypeElement activityType = findAndroidActivitySuperType((TypeElement) hostActivity); if (activityType == null) { throw new IllegalStateException("Annotated type does not seem to be an Activity"); } try { generateMemento(elements, hostActivity, activityType); } catch (IOException e) { throw new RuntimeException("Failed writing class file", e); } return true; }
Example #9
Source File: LVTHarness.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) return true; TypeElement aliveRangeAnno = elements.getTypeElement("AliveRanges"); if (!annotations.contains(aliveRangeAnno)) { error("no @AliveRanges annotation found in test class"); } for (Element elem: roundEnv.getElementsAnnotatedWith(aliveRangeAnno)) { Annotation annotation = elem.getAnnotation(AliveRanges.class); aliveRangeMap.put(new ElementKey(elem), (AliveRanges)annotation); } return true; }
Example #10
Source File: BuckModuleAnnotationProcessor.java From buck with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { return false; } List<BuckModuleDescriptor> buckModuleDescriptors = collectBuckModuleDescriptors(annotations, roundEnv); if (buckModuleDescriptors.isEmpty()) { return false; } assertOneBuckModuleDescriptor(buckModuleDescriptors); return generateBuckModuleAdapterPlugin(buckModuleDescriptors.get(0)); }
Example #11
Source File: AutowiredProcessor.java From DDComponentForAndroid with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) { if (CollectionUtils.isNotEmpty(set)) { try { logger.info(">>> Found autowired field, start... <<<"); categories(roundEnvironment.getElementsAnnotatedWith(Autowired.class)); generateHelper(); } catch (Exception e) { logger.error(e); } return true; } return false; }
Example #12
Source File: T6413690.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) { TypeElement testMe = elements.getTypeElement(TestMe.class.getName()); Set<? extends Element> supers = roundEnvironment.getElementsAnnotatedWith(testMe); try { for (Element sup : supers) { Writer sub = filer.createSourceFile(sup.getSimpleName() + "_GENERATED").openWriter(); sub.write(String.format("class %s_GENERATED extends %s {}", sup.getSimpleName(), ((TypeElement)sup).getQualifiedName())); sub.close(); } } catch (IOException ex) { throw new RuntimeException(ex); } return true; }
Example #13
Source File: T6468404.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!ran) { ran = true; ExecutableElement m = getFirstMethodIn("C"); System.err.println("method: " + m); TypeMirror type = (DeclaredType)m.getParameters().get(0).asType(); System.err.println("parameters[0]: " + type); if (!isParameterized(type)) throw new AssertionError(type); type = ((ExecutableType)m.asType()).getParameterTypes().get(0); System.err.println("parameterTypes[0]: " + type); if (!isParameterized(type)) throw new AssertionError(type); System.err.println(); } return true; }
Example #14
Source File: ShellProcessor.java From karaf-boot with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Set<String> packages = new TreeSet<>(); for (Element elem : roundEnv.getElementsAnnotatedWith(Service.class)) { packages.add(elem.getEnclosingElement().toString()); } if (!packages.isEmpty()) { if (!hasRun) { hasRun = true; // Add the Karaf embedded package try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { w.println("Karaf-Commands: " + String.join(",", packages)); } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd: " + e.getMessage()); } } } return true; }
Example #15
Source File: ApiImplProcessor.java From ApiManager with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) { if (CollectionUtils.isEmpty(set)) { return false; } for (TypeElement typeElement : set) { Set<? extends Element> annotated = roundEnvironment.getElementsAnnotatedWith(typeElement); for (Element apiImplElement : annotated) { ApiImpl annotation = apiImplElement.getAnnotation(ApiImpl.class); if (annotation == null || !(apiImplElement instanceof TypeElement)) { continue; } ApiContract<ClassName> apiNameContract = getApiClassNameContract((TypeElement) apiImplElement); try { JavaFile.builder(ApiConstants.PACKAGE_NAME_CONTRACT, buildClass(apiNameContract)) .build() .writeTo(filer); } catch (IOException e) { e.printStackTrace(); } } } return true; }
Example #16
Source File: T7018098.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); FSInfo fsInfo = context.get(FSInfo.class); round++; if (round == 1) { boolean expect = Boolean.valueOf(options.get("expect")); checkEqual("cache result", fsInfo.isDirectory(testDir), expect); initialFSInfo = fsInfo; } else { checkEqual("fsInfo", fsInfo, initialFSInfo); } return true; }
Example #17
Source File: ConvertingProcessor.java From vertx-codetrans with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element annotatedElt : roundEnv.getElementsAnnotatedWith(CodeTranslate.class)) { ExecutableElement methodElt = (ExecutableElement) annotatedElt; TypeElement typeElt = (TypeElement) methodElt.getEnclosingElement(); if (typeElt.getQualifiedName().toString().equals(fqn) && methodElt.getSimpleName().toString().equals(method)) { for (Lang lang : langs) { Result result; try { String translation = translator.translate(methodElt, false, lang, RenderMode.SNIPPET); result = new Result.Source(translation); } catch (Exception e) { result = new Result.Failure(e); } results.put(lang, result); } } } return false; }
Example #18
Source File: Processor.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (round++ == 0) { try (Writer out = processingEnv.getFiler() .createSourceFile("Anno.java") .openWriter()) { String target = processingEnv.getOptions().get("target"); String code = "import java.lang.annotation.ElementType;\n" + "import java.lang.annotation.Target;\n" + "@Target(ElementType." + target + ")\n" + "@interface Anno { public String value(); }\n"; out.write(code); } catch (IOException exc) { throw new IllegalStateException(exc); } } return true; }
Example #19
Source File: ProcessingIntegrationTest.java From turbine with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (first) { processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "proc warning"); try { JavaFileObject file = processingEnv.getFiler().createSourceFile("Gen.java"); try (Writer writer = file.openWriter()) { writer.write("class Gen {}"); } } catch (IOException e) { throw new UncheckedIOException(e); } first = false; } if (roundEnv.processingOver()) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "proc error"); } return false; }
Example #20
Source File: RetroWeiboBuilderProcessor.java From SimpleWeibo with Apache License 2.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Set<? extends Element> builderTypes = roundEnv.getElementsAnnotatedWith(RetroWeibo.Builder.class); if (!SuperficialValidation.validateElements(builderTypes)) { return false; } for (Element annotatedType : builderTypes) { // Double-check that the annotation is there. Sometimes the compiler gets confused in case of // erroneous source code. SuperficialValidation should protect us against this but it doesn't // cost anything to check again. if (isAnnotationPresent(annotatedType, RetroWeibo.Builder.class)) { validate( annotatedType, "@RetroWeibo.Builder can only be applied to a class or interface inside an" + " @RetroWeibo class"); } } Set<? extends Element> validateMethods = roundEnv.getElementsAnnotatedWith(RetroWeibo.Validate.class); if (!SuperficialValidation.validateElements(validateMethods)) { return false; } for (Element annotatedMethod : validateMethods) { if (isAnnotationPresent(annotatedMethod, RetroWeibo.Validate.class)) { validate( annotatedMethod, "@RetroWeibo.Validate can only be applied to a method inside an @RetroWeibo class"); } } return false; }
Example #21
Source File: BaseProcessor.java From kripton with Apache License 2.0 | 5 votes |
/** * Checks for work in this round. * * @param roundEnv the round env * @return true, if successful */ public boolean hasWorkInThisRound(RoundEnvironment roundEnv) { if (this.filter(roundEnv).size()>0) { return true; } return false; }
Example #22
Source File: Processor.java From RxAndroidOrm with Apache License 2.0 | 5 votes |
private void getDatabaseName(RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(DatabaseName.class)) { String name = element.getAnnotation(DatabaseName.class).value(); if (name != null && name.trim().length() > 0) { if (!name.endsWith(".db")) { name = name + ".db"; } dbFile = name; return; } } }
Example #23
Source File: T6350057.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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 #24
Source File: DocProcessor.java From gama with GNU General Public License v3.0 | 5 votes |
private org.w3c.dom.Element processDocXMLTypes(final Set<? extends Element> setTypes, final RoundEnvironment env) { final org.w3c.dom.Element types = document.createElement(XMLElements.TYPES); for (final Element t : setTypes) { if (!t.getAnnotation(type.class).internal()) { final org.w3c.dom.Element typeElt = document.createElement(XMLElements.TYPE); typeElt.setAttribute(XMLElements.ATT_TYPE_NAME, t.getAnnotation(type.class).name()); typeElt.setAttribute(XMLElements.ATT_TYPE_ID, "" + t.getAnnotation(type.class).id()); typeElt.setAttribute(XMLElements.ATT_TYPE_KIND, "" + t.getAnnotation(type.class).kind()); // ///////////////////////////////////////////////////// // Parsing of the documentation if (t.getAnnotation(type.class).doc().length != 0) { final org.w3c.dom.Element docElt = getDocElt(t.getAnnotation(type.class).doc()[0], document, mes, t.getAnnotation(type.class).name(), tc, null, typeElt); typeElt.appendChild(docElt); } // Parsing of concept org.w3c.dom.Element conceptsElt; if (typeElt.getElementsByTagName(XMLElements.CONCEPTS).getLength() == 0) { conceptsElt = getConcepts(t, document, document.createElement(XMLElements.CONCEPTS), tc); } else { conceptsElt = getConcepts(t, document, (org.w3c.dom.Element) typeElt.getElementsByTagName(XMLElements.CONCEPTS).item(0), tc); } typeElt.appendChild(conceptsElt); types.appendChild(typeElt); } } return types; }
Example #25
Source File: ButterKnifeProcessor.java From AndroidAll with Apache License 2.0 | 5 votes |
private void parseRoundEnvironment(RoundEnvironment roundEnv) { Map<TypeElement, BindClass> map = new LinkedHashMap<>(); for (Element element : roundEnv.getElementsAnnotatedWith(BindView.class)) { TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); //所在类名 String className = enclosingElement.getSimpleName().toString(); //所在类全名 String qualifiedName = enclosingElement.getQualifiedName().toString(); //注解的值 int annotationValue = element.getAnnotation(BindView.class).value(); BindClass bindClass = map.get(enclosingElement); if (bindClass == null) { bindClass = BindClass.createBindClass(enclosingElement); map.put(enclosingElement, bindClass); } String name = element.getSimpleName().toString(); TypeName type = TypeName.get(element.asType()); ViewBinding viewBinding = ViewBinding.createViewBind(name, type, annotationValue); bindClass.addAnnotationField(viewBinding); //printElement(element); } for (Map.Entry<TypeElement, BindClass> entry : map.entrySet()) { printValue("==========" + entry.getValue().getBindingClassName()); try { entry.getValue().preJavaFile().writeTo(filer); } catch (IOException e) { e.printStackTrace(); } } }
Example #26
Source File: MyProcessor.java From doma with Apache License 2.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { return true; } for (TypeElement a : annotations) { for (TypeElement t : ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(a))) { handleTypeElement(t, handler); } } return true; }
Example #27
Source File: ProcessorLastRound_typeIndex.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(Annotation.class)) { TypeElement cls = (TypeElement) element; types.add(cls.getSimpleName().toString()); } if (roundEnv.processingOver()) { try { FileObject resource = processingEnv.getFiler().createSourceFile("generated.TypeIndex"); try (BufferedWriter w = new BufferedWriter(resource.openWriter())) { w.append("package generated;"); w.newLine(); w.append("public interface TypeIndex {"); w.newLine(); for (String type : types) { w.append("public static final String ").append(type.toUpperCase()).append(" = null;"); w.newLine(); } w.append("}"); w.newLine(); } FileObject resource2 = processingEnv.getFiler().createSourceFile("generated.TypeIndex2"); try (BufferedWriter w = new BufferedWriter(resource2.openWriter())) { w.append("package generated;"); w.newLine(); w.append("public interface TypeIndex2 extends generated.TypeIndex {}"); w.newLine(); } } catch (IOException e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Could not create output " + e.getMessage()); } } return false; // not "claimed" so multiple processors can be tested }
Example #28
Source File: AbstractServiceProviderProcessor.java From netbeans with Apache License 2.0 | 5 votes |
public @Override final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.errorRaised()) { return false; } if (roundEnv.processingOver()) { writeServices(); outputFilesByProcessor.clear(); originatingElementsByProcessor.clear(); return true; } else { return handleProcess(annotations, roundEnv); } }
Example #29
Source File: OnActivityResultProcessor.java From OnActivityResult with Apache License 2.0 | 5 votes |
private void handleOnActivityResultAnnotation(final Map<String, ActivityResultClass> activityResultClasses, final RoundEnvironment environment, final AnnotatedMethodParameters annotatedParameters) { final Class<OnActivityResult> annotation = OnActivityResult.class; final Set<? extends Element> elements = environment.getElementsAnnotatedWith(annotation); for (final Element element : elements) { try { if (!Utils.isMethod(element)) { throw new OnActivityResultProcessingException(element, "@%s annotation must be on a method", annotation.getSimpleName()); } final ExecutableElement executableElement = (ExecutableElement) element; this.checkModifiers(executableElement.getEnclosingElement(), annotation, "classes", Modifier.PRIVATE); this.checkModifiers(executableElement, annotation, "methods", Modifier.PRIVATE, Modifier.STATIC); this.checkAnnotationMethods(executableElement); final ParameterList parameters = this.getParametersForMethod(executableElement, annotation, annotatedParameters); final ActivityResultClass activityResultClass = this.getOrCreateActivityResultClassInstance(activityResultClasses, element); final OnActivityResult onActivityResult = executableElement.getAnnotation(annotation); final RequestCode requestCode = new RequestCode(onActivityResult.requestCode()); final ResultCodes resultCodes = new ResultCodes(onActivityResult.resultCodes()); activityResultClass.add(new MethodCall(executableElement, parameters, resultCodes), requestCode); } catch (final OnActivityResultProcessingException error) { error.printError(processingEnv); } } }
Example #30
Source File: MessagerDiags.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Messager messager = processingEnv.getMessager(); for (Element e : roundEnv.getRootElements()) { messager.printMessage(WARNING, WRN_NO_SOURCE); messager.printMessage(WARNING, WRN_WITH_SOURCE, e); messager.printMessage(WARNING, WRN_NO_SOURCE); } return false; }