public MetaAnnotation buildGroupSequenceAnnot() { if ( this.groups.isEmpty() ) { return null; // No group sequence needed } else { // Build the array of groups JDefinedClass[] gs = new JDefinedClass[groups.size()+1]; int i=0; for ( MetaGroup group : groups ) { gs[i++] = group.getGeneratedClass(); } gs[i] = getGeneratedClass(); // Add the class itself (acts as Default) HashMap<String,Object> gsParams = Maps.newHashMap(); gsParams.put("value", gs); MetaAnnotation gsAnnot = new MetaAnnotation(getGeneratedClass().owner(), GroupSequence.class, AnnotationType.OTHER, gsParams); return gsAnnot; } }
private void writeBeanMetadata(final SourceWriter sw) throws UnableToCompleteException { // private final BeanMetadata beanMetadata = sw.println("private final BeanMetadata beanMetadata ="); sw.indent(); sw.indent(); // new BeanMetadata( sw.println("new " + BeanMetadata.class.getSimpleName() + "("); sw.indent(); sw.indent(); // <<bean class>>, <<default group seq class 1>>, <<default group seq class 2>>, ... final Class<?> beanClazz = this.beanHelper.getClazz(); sw.print(asLiteral(beanClazz)); final GroupSequence groupSeqAnnotation = beanClazz.getAnnotation(GroupSequence.class); final List<Class<?>> groupSequence = new ArrayList<>(); if (groupSeqAnnotation == null) { groupSequence.add(beanClazz); } else { groupSequence.addAll(Arrays.asList(groupSeqAnnotation.value())); } boolean groupSequenceContainsDefault = false; for (final Class<?> group : groupSequence) { sw.println(","); if (group.getName().equals(beanClazz.getName())) { sw.print(asLiteral(Default.class)); groupSequenceContainsDefault = true; } else if (group.getName().equals(Default.class.getName())) { throw error(this.logger, "'Default.class' cannot appear in default group sequence list."); } else { sw.print(asLiteral(group)); } } if (!groupSequenceContainsDefault) { throw error(this.logger, beanClazz.getName() + " must be part of the redefined default group " + "sequence."); } sw.println(");"); sw.outdent(); sw.outdent(); sw.outdent(); sw.outdent(); }