List of usage examples for javax.annotation.processing RoundEnvironment processingOver
boolean processingOver();
From source file:com.webguys.djinn.marid.util.BuiltinAnnotationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { try {/*w w w. ja v a 2 s. com*/ for (TypeElement annotation : annotations) { this.elements.addAll(roundEnv.getElementsAnnotatedWith(annotation)); } if (roundEnv.processingOver()) { if (this.shouldGenerate()) { if (null == this.sourceFile) { this.sourceFile = this.processingEnv.getFiler().createSourceFile(CLASSNAME); } this.processingEnv.getMessager().printMessage(Kind.NOTE, "generating builtin repository."); this.generate(); } else { this.processingEnv.getMessager().printMessage(Kind.NOTE, "NOT generating builtin repository."); } } } catch (Exception e) { String message = String.format("Unable to generate the code (%s).", e.getMessage()); this.processingEnv.getMessager().printMessage(Kind.ERROR, message); } return true; }
From source file:org.jannocessor.processor.JannocessorProcessorBase.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) { logger.info("Entering annotation processor..."); if (valid) {// w ww .ja va 2 s . c om if (!env.processingOver()) { logger.info("Processing resources..."); try { processAnnotations(annotations, env); logger.info("Successfully finished processing."); } catch (JannocessorException e) { logException(e); } catch (Exception e) { throw new RuntimeException("Unexpected error occured", e); } processProblems(env); } else { logger.info("Last round, processing is done."); } return true; } else { logger.error("Canceled processing, due to error."); return false; } }
From source file:ch.rasc.extclassgenerator.ModelAnnotationProcessor.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 . ja v a2 s . co 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; } OutputConfig outputConfig = new OutputConfig(); outputConfig.setDebug(!"false".equals(this.processingEnv.getOptions().get(OPTION_DEBUG))); boolean createBaseAndSubclass = "true" .equals(this.processingEnv.getOptions().get(OPTION_CREATEBASEANDSUBCLASS)); String outputFormatString = this.processingEnv.getOptions().get(OPTION_OUTPUTFORMAT); outputConfig.setOutputFormat(OutputFormat.EXTJS4); if (StringUtils.hasText(outputFormatString)) { if (OutputFormat.TOUCH2.name().equalsIgnoreCase(outputFormatString)) { outputConfig.setOutputFormat(OutputFormat.TOUCH2); } else if (OutputFormat.EXTJS5.name().equalsIgnoreCase(outputFormatString)) { outputConfig.setOutputFormat(OutputFormat.EXTJS5); } } String includeValidationString = this.processingEnv.getOptions().get(OPTION_INCLUDEVALIDATION); outputConfig.setIncludeValidation(IncludeValidation.NONE); if (StringUtils.hasText(includeValidationString)) { if (IncludeValidation.ALL.name().equalsIgnoreCase(includeValidationString)) { outputConfig.setIncludeValidation(IncludeValidation.ALL); } else if (IncludeValidation.BUILTIN.name().equalsIgnoreCase(includeValidationString)) { outputConfig.setIncludeValidation(IncludeValidation.BUILTIN); } } outputConfig.setUseSingleQuotes("true".equals(this.processingEnv.getOptions().get(OPTION_USESINGLEQUOTES))); outputConfig.setSurroundApiWithQuotes( "true".equals(this.processingEnv.getOptions().get(OPTION_SURROUNDAPIWITHQUOTES))); for (TypeElement annotation : annotations) { Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation); for (Element element : elements) { try { TypeElement typeElement = (TypeElement) element; String qualifiedName = typeElement.getQualifiedName().toString(); Class<?> modelClass = Class.forName(qualifiedName); String code = ModelGenerator.generateJavascript(modelClass, outputConfig); Model modelAnnotation = element.getAnnotation(Model.class); String modelName = modelAnnotation.value(); String fileName; String packageName = ""; if (StringUtils.hasText(modelName)) { int lastDot = modelName.lastIndexOf('.'); if (lastDot != -1) { fileName = modelName.substring(lastDot + 1); int firstDot = modelName.indexOf('.'); if (firstDot < lastDot) { packageName = modelName.substring(firstDot + 1, lastDot); } } else { fileName = modelName; } } else { fileName = typeElement.getSimpleName().toString(); } if (createBaseAndSubclass) { code = code.replaceFirst("(Ext.define\\([\"'].+?)([\"'],)", "$1Base$2"); FileObject fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName + "Base.js"); OutputStream os = fo.openOutputStream(); os.write(code.getBytes(ModelGenerator.UTF8_CHARSET)); os.close(); try { fo = this.processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName + ".js"); InputStream is = fo.openInputStream(); is.close(); } catch (FileNotFoundException e) { String subClassCode = generateSubclassCode(modelClass, outputConfig); fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName + ".js"); os = fo.openOutputStream(); os.write(subClassCode.getBytes(ModelGenerator.UTF8_CHARSET)); os.close(); } } else { FileObject fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName + ".js"); OutputStream os = fo.openOutputStream(); os.write(code.getBytes(ModelGenerator.UTF8_CHARSET)); os.close(); } } catch (ClassNotFoundException e) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage()); } catch (IOException e) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage()); } } } return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS; }
From source file:com.thoratou.exact.processors.ExactProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.processingOver()) { try {/*from w ww . j a va 2 s . c o m*/ HashMap<String, ArrayList<Item>> itemMap = new HashMap<String, ArrayList<Item>>(); HashMap<String, ArrayList<ExtensionItem>> extItemMap = new HashMap<String, ArrayList<ExtensionItem>>(); readAnnotations(roundEnv, itemMap, extItemMap); HashMap<String, List<PathStep>> mergedMap = new HashMap<String, List<PathStep>>(); mergeClassPaths(itemMap, extItemMap, mergedMap); writeSources(mergedMap); } catch (Exception e) { e.printStackTrace(); } } return false; }
From source file:therian.buildweaver.StandardOperatorsProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { try {// w w w . j a v a 2 s.c om final FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, StringUtils.substringBeforeLast(TARGET_CLASSNAME, ".").replace('.', '/'), StringUtils.substringAfterLast(TARGET_CLASSNAME, ".") + ".class"); if (resource.getLastModified() > 0L) { processingEnv.getMessager().printMessage(Kind.NOTE, String.format("%s already generated", TARGET_CLASSNAME)); return false; } } catch (IOException e1) { // expected, swallow } try { ClassUtils.getClass(TARGET_CLASSNAME); processingEnv.getMessager().printMessage(Kind.ERROR, String.format("%s exists on classpath", TARGET_CLASSNAME)); return false; } catch (ClassNotFoundException e) { // expected, swallow } if (roundEnv.processingOver()) { write(); return true; } for (TypeElement ann : annotations) { final Set<? extends Element> standardOperatorElements = roundEnv.getElementsAnnotatedWith(ann); originatingElements.addAll(standardOperatorElements); for (Element element : standardOperatorElements) { Validate.validState(isValidStandardOperator(element), "%s is not a valid @StandardOperator", appendTo(new StringBuilder(), element).toString()); if (element.getKind() == ElementKind.CLASS) { operators.add(appendTo(new StringBuilder("new "), element).append("()").toString()); } if (element.getKind() == ElementKind.METHOD) { operators.add(appendTo(new StringBuilder(), element).append("()").toString()); } if (element.getKind() == ElementKind.FIELD) { operators.add(appendTo(new StringBuilder(), element).toString()); } } } return true; }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
@Override protected boolean processWithExceptions(final Set<? extends TypeElement> set, final RoundEnvironment roundEnv) throws Exception { if (roundEnv.processingOver()) { return processLastRound(set, roundEnv); }/*from ww w. jav a 2s. co m*/ //If prior processing threw an error exit if (roundEnv.errorRaised()) { return false; } final Elements elementUtils = processingEnv.getElementUtils(); // Process Definition Sets types found on the processing environment. for (Element e : roundEnv .getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_DEFINITION_SET))) { processDefinitionSets(set, e, roundEnv); } // Process Definition types found on the processing environment. for (Element e : roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_DEFINITION))) { processDefinitions(set, e, roundEnv); } // Process Property Sets types found on the processing environment // AND // Process Property Sets types identified as dependant types for the annotated Defininitions. Note that // those types cannot be directly found on the processing environment if the classes are in a third party // dependency and not directly on the module sources. final Set<? extends Element> propertySetElements = new LinkedHashSet<Element>() { { addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_PROPERTY_SET))); addAll(processingContext.getPropertySetElements()); } }; for (Element e : propertySetElements) { processPropertySets(set, e, roundEnv); } // Process Property types found on the processing environment // AND // Process PropertySets types identified as dependant types for the annotated Defininitions or Property Sets. // Note that // those types cannot be directly found on the processing environment if the classes are in a // third party dependency and not directly on the module sources. final Set<? extends Element> propertyElements = new LinkedHashSet<Element>() { { addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_PROPERTY))); addAll(processingContext.getPropertyElements()); } }; for (Element e : propertyElements) { processProperties(set, e, roundEnv); } final Set<? extends Element> containRules = new LinkedHashSet<Element>() { { addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_CAN_CONTAIN))); addAll(processingContext.getDefinitionElements()); removeAll(processingContext.getContainmentRuleElementsProcessed()); } }; for (Element e : containRules) { processContainmentRules(e); } final Set<? extends Element> dockRules = new LinkedHashSet<Element>() { { addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_CAN_DOCK))); addAll(processingContext.getDefinitionElements()); removeAll(processingContext.getDockingRuleElementsProcessed()); } }; for (Element e : dockRules) { processDockingRules(e); } final Set<? extends Element> extRules = new LinkedHashSet<Element>() { { addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_EXTENSIONS))); addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_EXTENSION))); } }; for (Element e : extRules) { processRuleExtension(e); } final Set<? extends Element> occRules = new LinkedHashSet<Element>() { { addAll(roundEnv .getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_ALLOWED_OCCS))); addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_OCCS))); } }; for (Element e : occRules) { processCardinalityRules(e); } final Set<? extends Element> edgeOccRules = new LinkedHashSet<Element>() { { addAll(roundEnv.getElementsAnnotatedWith( elementUtils.getTypeElement(ANNOTATION_RULE_ALLOWED_EDGE_OCCURRS))); addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_EDGE_OCCS))); } }; for (Element e : edgeOccRules) { processEdgeCardinalityRules(e); } final Set<? extends Element> cRules = new LinkedHashSet<Element>() { { addAll(roundEnv .getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_ALLOWED_CONNECTION))); addAll(roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_RULE_CAN_CONNECT))); } }; for (Element e : cRules) { processConnectionRules(e); } return true; }
From source file:com.predic8.membrane.annot.SpringConfigurationXSDGeneratingAnnotationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // An instance is create per compiler call and not kept for the next incremental compilation. ///*from www . ja v a 2 s . com*/ // Use "roundEnv.getRootElements()" to get root elements (=classes) changed since last round. // Use "processingEnv.getElementUtils().getTypeElement(className)" to get the TypeElement of any class (changed or not). // "annotations.size()" equals the number of our annotations found in the "roundEnv.getRootElement()" classes. // // * rounds are repeated until nothing is filed (=created) any more // * resources (and java files?) may only be filed in one round // * in the last round, "roundEnv.processingOver()" is true try { String status = "process() a=" + annotations.size() + " r=" + roundEnv.getRootElements().size() + " h=" + hashCode() + (roundEnv.processingOver() ? " processing-over" : " "); log(status); read(); if (roundEnv.processingOver()) write(); if (annotations.size() > 0) { // a class with one of our annotation needs to be compiled status = "working with " + getCachedElementsAnnotatedWith(roundEnv, MCMain.class).size() + " and " + getCachedElementsAnnotatedWith(roundEnv, MCElement.class).size(); log(status); Model m = new Model(); Set<? extends Element> mcmains = getCachedElementsAnnotatedWith(roundEnv, MCMain.class); if (mcmains.isEmpty()) { processingEnv.getMessager().printMessage(Kind.WARNING, "@MCMain was nowhere found."); return true; } for (Element element : mcmains) { MainInfo main = new MainInfo(); main.setElement((TypeElement) element); main.setAnnotation(element.getAnnotation(MCMain.class)); m.getMains().add(main); } for (Element e : getCachedElementsAnnotatedWith(roundEnv, MCElement.class)) { ElementInfo ii = new ElementInfo(); ii.setElement((TypeElement) e); ii.setAnnotation(e.getAnnotation(MCElement.class)); MainInfo main = ii.getMain(m); main.getIis().add(ii); main.getElements().put(ii.getElement(), ii); if (main.getGlobals().containsKey(ii.getAnnotation().name())) throw new ProcessingException("Duplicate global @MCElement name.", main.getGlobals().get(ii.getAnnotation().name()).getElement(), ii.getElement()); if (main.getIds().containsKey(ii.getId())) throw new ProcessingException( "Duplicate element id \"" + ii.getId() + "\". Please assign one using @MCElement(id=\"...\").", e, main.getIds().get(ii.getId()).getElement()); main.getIds().put(ii.getId(), ii); scan(m, main, ii); if (ii.getTci() != null && !ii.getAnnotation().mixed()) throw new ProcessingException( "@MCTextContent requires @MCElement(..., mixed=true) on the class.", ii.getElement()); if (ii.getTci() == null && ii.getAnnotation().mixed()) throw new ProcessingException( "@MCElement(..., mixed=true) requires @MCTextContent on a property.", ii.getElement()); } for (MainInfo main : m.getMains()) { for (Map.Entry<TypeElement, ChildElementDeclarationInfo> f : main.getChildElementDeclarations() .entrySet()) { ChildElementDeclarationInfo cedi = f.getValue(); ElementInfo ei = main.getElements().get(f.getKey()); if (ei != null) cedi.getElementInfo().add(ei); else { for (Map.Entry<TypeElement, ElementInfo> e : main.getElements().entrySet()) if (processingEnv.getTypeUtils().isAssignable(e.getKey().asType(), f.getKey().asType())) cedi.getElementInfo().add(e.getValue()); } for (ElementInfo ei2 : cedi.getElementInfo()) ei2.addUsedBy(f.getValue()); if (cedi.getElementInfo().isEmpty() && cedi.isRaiseErrorWhenNoSpecimen()) { processingEnv.getMessager().printMessage(Kind.ERROR, "@MCChildElement references " + f.getKey().getQualifiedName() + ", but there is no @MCElement among it and its subclasses.", f.getKey()); return true; } } } if (mcmains.isEmpty()) { processingEnv.getMessager().printMessage(Kind.ERROR, "@MCMain but no @MCElement found.", mcmains.iterator().next()); return true; } process(m); } return true; } catch (IOException e) { throw new RuntimeException(e); } catch (ProcessingException e1) { for (int i = 0; i < e1.getElements().length; i++) processingEnv.getMessager().printMessage(Kind.ERROR, i == 0 ? e1.getMessage() : "also here", e1.getElements()[i]); return true; } }
From source file:com.mastfrog.parameters.processor.Processor.java
@Override public boolean process(Set<? extends TypeElement> set, RoundEnvironment re) { SourceVersion sv = processingEnv.getSourceVersion(); if (sv.ordinal() > SourceVersion.RELEASE_7.ordinal()) { optionalType = "java.util.Optional"; } else {//w w w. j a v a 2s . c o m TypeElement el = processingEnv.getElementUtils().getTypeElement(optionalType); if (el == null) { optionalType = "com.mastfrog.util.Optional"; } else { optionalType = "com.google.common.base.Optional"; fromNullable = "fromNullable"; } } Set<? extends Element> all = re.getElementsAnnotatedWith(Params.class); List<GeneratedParamsClass> interfaces = new LinkedList<>(); outer: for (Element e : all) { TypeElement te = (TypeElement) e; if (te.getSimpleName().toString().endsWith("__GenPage")) { continue; } PackageElement pkg = findPackage(e); if (pkg == null) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@Params may not be used in the default package", e); continue; } if (!isPageSubtype(te)) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@Params must be used on a subclass of org.apache.wicket.Page", e); continue; } String className = te.getQualifiedName().toString(); Params params = te.getAnnotation(Params.class); Map<String, List<String>> validators = validatorsForParam(e); GeneratedParamsClass inf = new GeneratedParamsClass(className, te, pkg, params, validators); if (!params.useRequestBody()) { checkConstructor(te, inf); } interfaces.add(inf); Set<String> names = new HashSet<>(); for (Param param : params.value()) { // if (param.required() && !param.defaultValue().isEmpty()) { // processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Don't set required to " // + "true if you are providing a default value - required makes it an error not " // + "to have a value, and if there is a default value, that error is an impossibility " // + "because it will always have a value.", e); // continue outer; // } if (param.value().trim().isEmpty()) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Empty parameter name", e); continue outer; } if (!isJavaIdentifier(param.value())) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Not a valid Java identifier: " + param.value(), e); continue outer; } if (!names.add(param.value())) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Duplicate parameter name '" + param.value() + "'", e); continue outer; } for (char c : ";,./*!@&^/\\<>?'\"[]{}-=+)(".toCharArray()) { if (param.value().contains("" + c)) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Param name may not contain the character '" + c + "'", e); } } inf.add(param); } } Filer filer = processingEnv.getFiler(); StringBuilder listBuilder = new StringBuilder(); for (GeneratedParamsClass inf : interfaces) { try { String pth = inf.packageAsPath() + '/' + inf.className; pth = pth.replace('/', '.'); JavaFileObject obj = filer.createSourceFile(pth, inf.el); try (OutputStream out = obj.openOutputStream()) { out.write(inf.toString().getBytes("UTF-8")); } listBuilder.append(inf.className).append('\n'); } catch (Exception ex) { ex.printStackTrace(); processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Error processing annotation: " + ex.getMessage(), inf.el); Logger.getLogger(Processor.class.getName()).log(Level.SEVERE, null, ex); } } if (re.processingOver()) { try { FileObject list = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/paramanos/bind.list", all.toArray(new Element[0])); try (OutputStream out = list.openOutputStream()) { out.write(listBuilder.toString().getBytes("UTF-8")); } } catch (FilerException ex) { Logger.getLogger(Processor.class.getName()).log(Level.INFO, null, ex); } catch (IOException ex) { Logger.getLogger(Processor.class.getName()).log(Level.SEVERE, null, ex); } } return true; }