@Override public void process() { EclipseMessager messager = (EclipseMessager) _env.getMessager(); // obtain the declaration of the annotation we want to process AnnotationTypeDeclaration annoDecl = (AnnotationTypeDeclaration) _env.getTypeDeclaration(JSFillChildrenMethod.class.getName()); // get the annotated types Collection<Declaration> annotatedTypes = _env.getDeclarationsAnnotatedWith(annoDecl); for (Declaration decl : annotatedTypes) { Collection<AnnotationMirror> mirrors = decl.getAnnotationMirrors(); // for each annotation found, get a map of element name/value pairs for (AnnotationMirror mirror : mirrors) { if (!"JSFillChildrenMethod" .equals(mirror.getAnnotationType().getDeclaration().getSimpleName())) { continue; } MethodDeclaration methodDeclaration = (MethodDeclaration) decl; JSJPQLMethodProcessor.checkReturnType(mirror, methodDeclaration, messager); JSJPQLMethodProcessor.checkTransferInfo(mirror, methodDeclaration, true, messager); JSJPQLMethodProcessor.checkIfAnnotationValueAttributeIsEntity(mirror, "parent", messager); } } }
@Override public void process() { final AnnotationTypeDeclaration beanAnn = (AnnotationTypeDeclaration) env_.getTypeDeclaration(Bean.class.getName()); for (Declaration declaration : env_.getDeclarationsAnnotatedWith(beanAnn)) { try { if (!(declaration instanceof ClassDeclaration)) { error(declaration, "You can only annotate class declarations with @Bean"); return; } Thing data = new Thing("data"); ClassDeclaration classDeclaration = (ClassDeclaration) declaration; PackageDeclaration packageDeclaration = classDeclaration.getPackage(); Map<String, AnnotationValue> beanValues = getAnnotationValues(classDeclaration, "com.javadude.annotation.Bean"); checkExtends(classDeclaration, packageDeclaration); // check that the class extends XXXGen processSuperclass(data, beanValues); // process the superclass attribute processProperties(data, beanValues); processObservers(data, beanValues); processNullObjects(data, beanValues); processDelegates(data, beanValues); processDefaultMethods(data, classDeclaration); setValue(data, beanValues, "cloneable", false); setValue(data, beanValues, "defineEqualsAndHashCode", false); setValue(data, beanValues, "equalsAndHashCodeCallSuper", false); setValue(data, beanValues, "definePropertyNameConstants", false); setValue(data, beanValues, "defineCreatePropertyMap", false); data.put("date", new Date()); data.put("year", Calendar.getInstance().get(Calendar.YEAR)); data.put("className", classDeclaration.getSimpleName()); data.put("packageName", packageDeclaration.getQualifiedName()); data.checkAllValuesSet(declaration, this); Filer f = env_.getFiler(); PrintWriter pw = f.createSourceFile(classDeclaration.getQualifiedName() + "Gen"); if (nestedEclipse) { // debugging in eclipse -- reread the template each time FileReader fileReader = new FileReader( workspace + "/com.javadude.annotation/template/$packageName$/$className$Gen.java"); template = new TemplateReader().readTemplate(fileReader); } int spacesForLeadingTabs = i(beanValues, "spacesForLeadingTabs", -1); String padding = null; if (spacesForLeadingTabs != -1) { padding = ""; for (int i = 0; i < spacesForLeadingTabs; i++) { padding += ' '; } } template.process(new Symbols(data), pw, -1, padding); pw.close(); } catch (ThreadDeath e) { throw e; } catch (ExpressionException e) { error(declaration, "@Bean generator error: " + e.getMessage()); } catch (Throwable t) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); t.printStackTrace(printWriter); printWriter.close(); error(declaration, "Unexpected exception: " + stringWriter.toString()); } } }