2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.Lists;
12 import com.google.common.collect.Maps;
13 import org.opendaylight.controller.config.api.DependencyResolver;
14 import org.opendaylight.controller.config.api.IdentityAttributeRef;
15 import org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule;
16 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
17 import org.opendaylight.controller.config.api.runtime.RuntimeBean;
18 import org.opendaylight.controller.config.spi.Module;
19 import org.opendaylight.controller.config.yangjmxgenerator.AbstractEntry;
20 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
21 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
22 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
23 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
24 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AbstractDependencyAttribute;
25 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
26 import org.opendaylight.controller.config.yangjmxgenerator.attribute.Dependency;
27 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
28 import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute;
29 import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute;
30 import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute;
31 import org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute;
32 import org.opendaylight.controller.config.yangjmxgenerator.attribute.VoidAttribute;
33 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
34 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation.Parameter;
35 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
36 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
37 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
38 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField;
39 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration;
40 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition;
41 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField;
42 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper;
43 import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
44 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
45 import org.opendaylight.yangtools.sal.binding.model.api.Type;
47 import javax.management.openmbean.SimpleType;
48 import java.util.ArrayList;
49 import java.util.Arrays;
50 import java.util.Collections;
51 import java.util.HashMap;
52 import java.util.List;
54 import java.util.Map.Entry;
56 public class TemplateFactory {
59 * Get map of file name as key, FtlFile instance representing runtime mx
60 * bean as value that should be persisted from this instance.
62 public static Map<String, FtlTemplate> getTOAndMXInterfaceFtlFiles(
63 RuntimeBeanEntry entry) {
64 Map<String, FtlTemplate> result = new HashMap<>();
65 { // create GeneralInterfaceFtlFile for runtime MXBean. Attributes will
66 // be transformed to getter methods
67 String mxBeanTypeName = entry.getJavaNameOfRuntimeMXBean();
68 List<String> extendedInterfaces = Arrays.asList(RuntimeBean.class
70 List<MethodDeclaration> methods = new ArrayList<>();
72 // convert attributes to getters
73 for (AttributeIfc attributeIfc : entry.getAttributes()) {
75 returnType = getReturnType(attributeIfc);
76 String getterName = "get"
77 + attributeIfc.getUpperCaseCammelCase();
78 MethodDeclaration getter = new MethodDeclaration(returnType,
79 getterName, Collections.<Field> emptyList());
84 for (Rpc rpc : entry.getRpcs()) {
85 // convert JavaAttribute parameters into fields
86 List<Field> fields = new ArrayList<>();
87 for (JavaAttribute ja : rpc.getParameters()) {
88 Field field = new Field(Collections.<String> emptyList(),
89 ja.getType().getFullyQualifiedName(),
90 ja.getLowerCaseCammelCase(), ja.getNullableDefaultWrappedForCode());
93 MethodDeclaration operation = new MethodDeclaration(
94 getReturnType(rpc.getReturnType()), rpc.getName(), fields);
95 methods.add(operation);
99 GeneralInterfaceTemplate runtimeMxBeanIfc = new GeneralInterfaceTemplate(
100 null, entry.getPackageName(), mxBeanTypeName,
101 extendedInterfaces, methods);
103 result.put(runtimeMxBeanIfc.getTypeDeclaration().getName()
104 + ".java", runtimeMxBeanIfc);
107 result.putAll(TemplateFactory.tOsFromRbe(entry));
112 // FIXME: put into Type.toString
113 static String serializeType(Type type, boolean addWildcards) {
114 if (type instanceof ParameterizedType){
115 ParameterizedType parameterizedType = (ParameterizedType) type;
116 StringBuilder sb = new StringBuilder();
117 sb.append(parameterizedType.getRawType().getFullyQualifiedName());
118 sb.append(addWildcards ? "<? extends " : "<");
119 boolean first = true;
120 for(Type parameter: parameterizedType.getActualTypeArguments()) {
126 sb.append(serializeType(parameter));
129 return sb.toString();
131 return type.getFullyQualifiedName();
135 static String serializeType(Type type) {
136 return serializeType(type, false);
139 private static String getReturnType(AttributeIfc attributeIfc) {
141 if (attributeIfc instanceof TypedAttribute) {
142 Type type = ((TypedAttribute) attributeIfc).getType();
143 returnType = serializeType(type);
144 } else if (attributeIfc == VoidAttribute.getInstance()) {
147 throw new UnsupportedOperationException(
148 "Attribute not supported: "
149 + attributeIfc.getClass());
154 public static GeneralInterfaceTemplate serviceInterfaceFromSie(
155 ServiceInterfaceEntry sie) {
157 List<String> extendedInterfaces = Lists
158 .newArrayList(AbstractServiceInterface.class.getCanonicalName());
159 if (sie.getBase().isPresent()) {
160 extendedInterfaces.add(sie.getBase().get().getFullyQualifiedName());
164 GeneralInterfaceTemplate sieTemplate = new GeneralInterfaceTemplate(
165 getHeaderFromEntry(sie), sie.getPackageName(),
166 sie.getTypeName(), extendedInterfaces,
167 Lists.<MethodDeclaration> newArrayList());
168 sieTemplate.setJavadoc(sie.getNullableDescription());
170 if (sie.getNullableDescription() != null)
171 sieTemplate.getAnnotations().add(
172 Annotation.createDescriptionAnnotation(sie
173 .getNullableDescription()));
174 sieTemplate.getAnnotations().addAll(Annotation.createSieAnnotations(sie));
179 public static AbstractFactoryTemplate abstractFactoryTemplateFromMbe(
180 ModuleMXBeanEntry mbe) {
181 AbstractFactoryAttributesProcessor attrProcessor = new AbstractFactoryAttributesProcessor();
182 attrProcessor.processAttributes(mbe.getAttributes(),
183 mbe.getPackageName());
187 return new AbstractFactoryTemplate(getHeaderFromEntry(mbe),
188 mbe.getPackageName(), mbe.getAbstractFactoryName(),
189 attrProcessor.getFields()
193 public static AbstractModuleTemplate abstractModuleTemplateFromMbe(
194 ModuleMXBeanEntry mbe) {
195 AbstractModuleAttributesProcessor attrProcessor = new AbstractModuleAttributesProcessor(mbe.getAttributes());
197 List<ModuleField> moduleFields = attrProcessor.getModuleFields();
198 List<String> implementedIfcs = Lists.newArrayList(
199 Module.class.getCanonicalName(),
200 mbe.getFullyQualifiedName(mbe.getMXBeanInterfaceName()));
202 for (String implementedService : mbe.getProvidedServices().keySet()) {
203 implementedIfcs.add(implementedService);
206 boolean generateRuntime = false;
207 String registratorFullyQualifiedName = null;
208 if (mbe.getRuntimeBeans() != null
209 && mbe.getRuntimeBeans().isEmpty() == false) {
210 generateRuntime = true;
211 RuntimeBeanEntry rootEntry = RuntimeRegistratorFtlTemplate
212 .findRoot(mbe.getRuntimeBeans());
213 registratorFullyQualifiedName = rootEntry
216 .concat(RuntimeRegistratorFtlTemplate.getJavaNameOfRuntimeRegistrator(rootEntry));
217 implementedIfcs.add(RuntimeBeanRegistratorAwareModule.class
218 .getCanonicalName());
221 AbstractModuleTemplate abstractModuleTemplate = new AbstractModuleTemplate(
222 getHeaderFromEntry(mbe), mbe.getPackageName(),
223 mbe.getAbstractModuleName(), implementedIfcs, moduleFields,
224 attrProcessor.getMethods(), generateRuntime,
225 registratorFullyQualifiedName);
227 if (mbe.getNullableDescription() != null)
228 abstractModuleTemplate.getAnnotations().add(
229 Annotation.createDescriptionAnnotation(mbe
230 .getNullableDescription()));
231 return abstractModuleTemplate;
234 public static StubFactoryTemplate stubFactoryTemplateFromMbe(
235 ModuleMXBeanEntry mbe) {
236 return new StubFactoryTemplate(getHeaderFromEntry(mbe),
237 mbe.getPackageName(), mbe.getStubFactoryName(),
238 mbe.getFullyQualifiedName(mbe.getAbstractFactoryName())
242 public static GeneralInterfaceTemplate mXBeanInterfaceTemplateFromMbe(
243 ModuleMXBeanEntry mbe) {
244 MXBeanInterfaceAttributesProcessor attrProcessor = new MXBeanInterfaceAttributesProcessor();
245 attrProcessor.processAttributes(mbe.getAttributes());
246 GeneralInterfaceTemplate ifcTemplate = new GeneralInterfaceTemplate(
247 getHeaderFromEntry(mbe), mbe.getPackageName(),
248 mbe.getMXBeanInterfaceName(), Lists.<String> newArrayList(),
249 attrProcessor.getMethods());
250 ifcTemplate.setJavadoc(mbe.getNullableDescription());
254 public static Map<String, GeneralClassTemplate> tOsFromMbe(
255 ModuleMXBeanEntry mbe) {
256 Map<String, GeneralClassTemplate> retVal = Maps.newHashMap();
257 TOAttributesProcessor processor = new TOAttributesProcessor();
258 processor.processAttributes(mbe.getAttributes());
259 for (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory.TOAttributesProcessor.TOInternal to : processor
261 List<Constructor> constructors = Lists.newArrayList();
262 constructors.add(new Constructor(to.getName(), "super();"));
264 Header header = getHeaderFromEntry(mbe);
267 new GeneralClassTemplate(header, mbe.getPackageName(), to
268 .getName(), Collections.<String> emptyList(),
269 Collections.<String> emptyList(), to.getFields(),
270 to.getMethods(), false, false, constructors));
275 public static Map<String, GeneralClassTemplate> tOsFromRbe(
276 RuntimeBeanEntry rbe) {
277 Map<String, GeneralClassTemplate> retVal = Maps.newHashMap();
278 TOAttributesProcessor processor = new TOAttributesProcessor();
279 Map<String, AttributeIfc> yangPropertiesToTypesMap = Maps.newHashMap(rbe.getYangPropertiesToTypesMap());
281 // Add TOs from output parameters
282 for (Rpc rpc : rbe.getRpcs()) {
283 AttributeIfc returnType = rpc.getReturnType();
285 if (returnType == VoidAttribute.getInstance()) {
288 if (returnType instanceof JavaAttribute) {
291 if (returnType instanceof ListAttribute && returnType.getOpenType() instanceof SimpleType) {
295 Preconditions.checkState(yangPropertiesToTypesMap.containsKey(returnType.getAttributeYangName()) == false,
296 "Duplicate TO %s for %s", returnType.getAttributeYangName(), rbe);
297 yangPropertiesToTypesMap.put(returnType.getAttributeYangName(), returnType);
300 processor.processAttributes(yangPropertiesToTypesMap);
301 for (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory.TOAttributesProcessor.TOInternal to : processor
303 List<Constructor> constructors = Lists.newArrayList();
304 constructors.add(new Constructor(to.getName(), "super();"));
309 new GeneralClassTemplate(null, rbe.getPackageName(), to
310 .getName(), Collections.<String> emptyList(),
311 Collections.<String> emptyList(), to.getFields(),
312 to.getMethods(), false, false, constructors));
317 private static Header getHeaderFromEntry(AbstractEntry mbe) {
318 return new Header(mbe.getYangModuleName(), mbe.getYangModuleLocalname());
321 // TODO refactor attribute processors
323 private static class TOAttributesProcessor {
325 private final List<TOInternal> tos = Lists.newArrayList();
327 void processAttributes(Map<String, AttributeIfc> attributes) {
328 for (Entry<String, AttributeIfc> attrEntry : attributes.entrySet()) {
329 AttributeIfc attributeIfc = attrEntry.getValue();
330 if (attributeIfc instanceof TOAttribute) {
331 createTOInternal((TOAttribute) attributeIfc);
333 if (attributeIfc instanceof ListAttribute) {
334 AttributeIfc innerAttr = ((ListAttribute) attributeIfc)
335 .getInnerAttribute();
336 if (innerAttr instanceof TOAttribute) {
337 createTOInternal((TOAttribute) innerAttr);
343 private void createTOInternal(TOAttribute toAttribute) {
345 Map<String, AttributeIfc> attrs = toAttribute.getCapitalizedPropertiesToTypesMap();
346 // recursive processing of TO's attributes
347 processAttributes(attrs);
349 tos.add(new TOInternal(toAttribute.getType(), attrs));
352 List<TOInternal> getTOs() {
356 private static class TOInternal {
357 private final String fullyQualifiedName, name;
358 private List<Field> fields;
359 private List<MethodDefinition> methods;
361 public TOInternal(Type type, Map<String, AttributeIfc> attrs) {
362 this(type.getFullyQualifiedName(), type.getName(), attrs, type.getPackageName());
365 public TOInternal(String fullyQualifiedName, String name,
366 Map<String, AttributeIfc> attrs, String packageName) {
367 this.fullyQualifiedName = fullyQualifiedName;
369 processAttrs(attrs, packageName);
372 private final static String dependencyResolverVarName = "dependencyResolver";
373 private final static String dependencyResolverInjectMethodName = "injectDependencyResolver";
375 private void processAttrs(Map<String, AttributeIfc> attrs, String packageName) {
376 fields = Lists.newArrayList();
377 methods = Lists.newArrayList();
379 // FIXME conflict if "dependencyResolver" field from yang
380 Field depRes = new Field(DependencyResolver.class.getName(), dependencyResolverVarName);
382 methods.add(new MethodDefinition("void", dependencyResolverInjectMethodName, Lists.newArrayList(depRes),
383 "this." + dependencyResolverVarName + " = " + dependencyResolverVarName + ";"));
385 for (Entry<String, AttributeIfc> attrEntry : attrs.entrySet()) {
386 String innerName = attrEntry.getKey();
387 String varName = BindingGeneratorUtil
388 .parseToValidParamName(attrEntry.getKey());
390 String fullyQualifiedName, nullableDefault = null;
391 if (attrEntry.getValue() instanceof TypedAttribute) {
392 Type type = ((TypedAttribute) attrEntry.getValue()).getType();
393 if(attrEntry.getValue() instanceof JavaAttribute) {
394 nullableDefault = ((JavaAttribute)attrEntry.getValue()).getNullableDefaultWrappedForCode();
395 if(((JavaAttribute)attrEntry.getValue()).isIdentityRef()) {
397 String fieldType = serializeType(type, true);
398 String innerType = getInnerTypeFromIdentity(type);
399 methods.add(new MethodDefinition(fieldType, "resolve" + attrEntry.getKey(), Collections.<Field>emptyList(),
400 "return " + varName + ".resolveIdentity(" + dependencyResolverVarName + "," + innerType + ".class);"));
401 type = identityRefType;
404 fullyQualifiedName = serializeType(type);
406 fullyQualifiedName = FullyQualifiedNameHelper
407 .getFullyQualifiedName(packageName, attrEntry.getValue().getUpperCaseCammelCase());
409 fields.add(new Field(fullyQualifiedName, varName, nullableDefault, needsDepResolver(attrEntry.getValue())));
411 String getterName = "get" + innerName;
412 MethodDefinition getter = new MethodDefinition(
413 fullyQualifiedName, getterName,
414 Collections.<Field> emptyList(), "return "
417 String setterName = "set" + innerName;
418 MethodDefinition setter = new MethodDefinition("void",
419 setterName, Lists.newArrayList(new Field(
420 fullyQualifiedName, varName)), "this."
421 + varName + " = " + varName + ";");
429 return fullyQualifiedName;
436 List<Field> getFields() {
440 List<MethodDefinition> getMethods() {
447 private static class MXBeanInterfaceAttributesProcessor {
448 private final List<MethodDeclaration> methods = Lists.newArrayList();
450 void processAttributes(Map<String, AttributeIfc> attributes) {
451 for (Entry<String, AttributeIfc> attrEntry : attributes.entrySet()) {
453 AttributeIfc attributeIfc = attrEntry.getValue();
455 if (attributeIfc instanceof TypedAttribute) {
456 TypedAttribute typedAttribute = (TypedAttribute) attributeIfc;
457 returnType = serializeType(typedAttribute.getType());
459 if (attributeIfc instanceof JavaAttribute && ((JavaAttribute)attrEntry.getValue()).isIdentityRef()) {
460 returnType = serializeType(identityRefType);
464 throw new UnsupportedOperationException(
465 "Attribute not supported: "
466 + attributeIfc.getClass());
469 String getterName = "get"
470 + attributeIfc.getUpperCaseCammelCase();
471 MethodDeclaration getter = new MethodDeclaration(returnType,
472 getterName, Collections.<Field> emptyList());
474 String varName = BindingGeneratorUtil
475 .parseToValidParamName(attrEntry.getKey());
476 String setterName = "set"
477 + attributeIfc.getUpperCaseCammelCase();
478 MethodDeclaration setter = new MethodDeclaration("void",
479 setterName, Lists.newArrayList(new Field(returnType,
485 if (attributeIfc.getNullableDescription() != null) {
486 setter.setJavadoc(attrEntry.getValue()
487 .getNullableDescription());
492 List<MethodDeclaration> getMethods() {
497 private static final Type identityRefType = new Type() {
498 public final Class<IdentityAttributeRef> IDENTITY_ATTRIBUTE_REF_CLASS = IdentityAttributeRef.class;
501 public String getPackageName() {
502 return IDENTITY_ATTRIBUTE_REF_CLASS.getPackage().getName();
506 public String getName() {
507 return IDENTITY_ATTRIBUTE_REF_CLASS.getSimpleName();
511 public String getFullyQualifiedName() {
512 return IDENTITY_ATTRIBUTE_REF_CLASS.getName();
516 private static class AbstractFactoryAttributesProcessor {
518 private final List<Field> fields = Lists.newArrayList();
520 void processAttributes(Map<String, AttributeIfc> attributes,
521 String packageName) {
522 for (Entry<String, AttributeIfc> attrEntry : attributes.entrySet()) {
524 String nullableDefaultWrapped = null;
525 AttributeIfc attributeIfc = attrEntry.getValue();
527 if (attributeIfc instanceof TypedAttribute) {
528 TypedAttribute typedAttribute = (TypedAttribute) attributeIfc;
529 type = serializeType(typedAttribute.getType());
531 throw new UnsupportedOperationException(
532 "Attribute not supported: "
533 + attributeIfc.getClass());
536 fields.add(new Field(type, attributeIfc
537 .getUpperCaseCammelCase(), nullableDefaultWrapped));
541 List<Field> getFields() {
546 private static class AbstractModuleAttributesProcessor {
547 private static class Holder {
548 private final List<ModuleField> moduleFields;
549 private final List<MethodDefinition> methods;
551 private Holder(List<ModuleField> moduleFields, List<MethodDefinition> methods) {
552 this.moduleFields = Collections.unmodifiableList(moduleFields);
553 this.methods = Collections.unmodifiableList(methods);
557 private final Holder holder;
560 private AbstractModuleAttributesProcessor(Map<String, AttributeIfc> attributes) {
561 this.holder = processAttributes(attributes);
564 private static Holder processAttributes(Map<String, AttributeIfc> attributes) {
565 List<ModuleField> moduleFields = new ArrayList<>();
566 List<MethodDefinition> methods = new ArrayList<>();
567 for (Entry<String, AttributeIfc> attrEntry : attributes.entrySet()) {
568 String type, nullableDefaultWrapped = null;
569 AttributeIfc attributeIfc = attrEntry.getValue();
570 boolean isIdentity = false;
571 boolean needsDepResolver = needsDepResolver(attrEntry.getValue());
573 if (attributeIfc instanceof TypedAttribute) {
574 TypedAttribute typedAttribute = (TypedAttribute) attributeIfc;
575 type = serializeType(typedAttribute.getType());
576 if (attributeIfc instanceof JavaAttribute) {
577 nullableDefaultWrapped = ((JavaAttribute) attributeIfc).getNullableDefaultWrappedForCode();
578 if(((JavaAttribute)attrEntry.getValue()).isIdentityRef()) {
580 type = serializeType(typedAttribute.getType(), true);
584 throw new UnsupportedOperationException(
585 "Attribute not supported: "
586 + attributeIfc.getClass());
589 boolean isDependency = false;
590 boolean isListOfDependencies = false;
591 Dependency dependency = null;
592 Annotation overrideAnnotation = new Annotation("Override",
593 Collections.<Parameter> emptyList());
594 List<Annotation> annotations = Lists
595 .newArrayList(overrideAnnotation);
597 if (attributeIfc instanceof AbstractDependencyAttribute) {
599 dependency = ((AbstractDependencyAttribute) attributeIfc)
601 annotations.add(Annotation
602 .createRequireIfcAnnotation(dependency.getSie()));
603 if (attributeIfc instanceof ListDependenciesAttribute) {
604 isListOfDependencies = true;
608 String varName = BindingGeneratorUtil
609 .parseToValidParamName(attrEntry.getKey());
614 String identityBaseClass = getInnerTypeFromIdentity(((TypedAttribute) attributeIfc).getType());
615 IdentityRefModuleField identityField = new IdentityRefModuleField(type, varName,
616 attributeIfc.getUpperCaseCammelCase(), identityBaseClass);
618 String getterName = "get"
619 + attributeIfc.getUpperCaseCammelCase() + "Identity";
620 MethodDefinition additionalGetter = new MethodDefinition(type, getterName, Collections.<Field> emptyList(),
621 Collections.<Annotation> emptyList(), "return " + identityField.getIdentityClassName()
623 methods.add(additionalGetter);
625 String setterName = "set"
626 + attributeIfc.getUpperCaseCammelCase();
628 String setterBody = "this." + identityField.getIdentityClassName() + " = " + identityField.getIdentityClassName() + ";";
629 MethodDefinition additionalSetter = new MethodDefinition("void",
631 Lists.newArrayList(new Field(type, identityField.getIdentityClassName())),
632 Collections.<Annotation> emptyList(), setterBody);
633 additionalSetter.setJavadoc(attributeIfc.getNullableDescription());
635 methods.add(additionalSetter);
637 type = serializeType(identityRefType);
638 field = identityField;
640 field = new ModuleField(type, varName, attributeIfc.getUpperCaseCammelCase(),
641 nullableDefaultWrapped, isDependency, dependency, isListOfDependencies, needsDepResolver);
643 moduleFields.add(field);
645 String getterName = "get"
646 + attributeIfc.getUpperCaseCammelCase();
647 MethodDefinition getter = new MethodDefinition(type,
648 getterName, Collections.<Field> emptyList(),
649 Lists.newArrayList(overrideAnnotation), "return "
654 String setterName = "set"
655 + attributeIfc.getUpperCaseCammelCase();
657 if (attributeIfc.getNullableDescription() != null) {
658 annotations.add(Annotation
659 .createDescriptionAnnotation(attributeIfc.getNullableDescription()));
662 String setterBody = "this." + varName + " = " + varName + ";";
663 if (isListOfDependencies) {
664 String nullCheck = String.format("if (%s == null) throw new IllegalArgumentException(\"Null not supported\");%n",
666 setterBody = nullCheck + setterBody;
668 MethodDefinition setter = new MethodDefinition("void",
670 Lists.newArrayList(new Field(type, varName)),
671 annotations, setterBody);
672 setter.setJavadoc(attributeIfc.getNullableDescription());
676 return new Holder(moduleFields, methods);
679 List<ModuleField> getModuleFields() {
680 return holder.moduleFields;
683 List<MethodDefinition> getMethods() {
684 return holder.methods;
690 private static boolean needsDepResolver(AttributeIfc value) {
691 if(value instanceof TOAttribute)
693 if(value instanceof ListAttribute) {
694 AttributeIfc innerAttribute = ((ListAttribute) value).getInnerAttribute();
695 return needsDepResolver(innerAttribute);
701 private static String getInnerTypeFromIdentity(Type type) {
702 Preconditions.checkArgument(type instanceof ParameterizedType);
703 Type[] args = ((ParameterizedType) type).getActualTypeArguments();
704 Preconditions.checkArgument(args.length ==1);
705 return serializeType(args[0]);