import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
+import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableSortedSet;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes;
import org.opendaylight.mdsal.binding.javav2.generator.util.ReferencedTypeImpl;
import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedProperty;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedTypeForBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.MethodSignature;
import org.opendaylight.mdsal.binding.javav2.model.api.ParameterizedType;
import org.opendaylight.mdsal.binding.javav2.model.api.Type;
+import org.opendaylight.mdsal.binding.javav2.spec.base.Instantiable;
+import org.opendaylight.mdsal.binding.javav2.spec.base.Item;
import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
+import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
+import org.opendaylight.mdsal.binding.javav2.spec.structural.AugmentationHolder;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.concepts.Identifiable;
*/
private GeneratedProperty augmentField;
+ boolean instantiable = false;
+
public BuilderRenderer(final GeneratedType type) {
super(type);
this.properties = propertiesFromMethods(createMethods());
putToImportMap(Builder.class.getSimpleName(), Builder.class.getPackage().getName());
+ putToImportMap(type.getName(), type.getPackageName());
+ }
+
+ @Override
+ protected String packageDefinition() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("package ")
+ .append(((GeneratedTypeForBuilder)getType()).getPackageNameForBuilder())
+ .append(";\n\n");
+ return sb.toString();
+ }
+
+ @Override
+ protected boolean hasSamePackage(final String importedTypePackageName) {
+ return ((GeneratedTypeForBuilder)getType()).getPackageNameForBuilder()
+ .equals(importedTypePackageName);
}
/**
for (Type implementedIfc : implementedIfcs) {
if ((implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))) {
final GeneratedType ifc = (GeneratedType) implementedIfc;
- methods.addAll(ifc.getMethodDefinitions());
- collectImplementedMethods(methods, ifc.getImplements());
+ //TODO:temporarily eliminated for through compiling, to be restored in "support choice" patch.
+ // if (implementedIfc instanceof GeneratedTypeForBuilder) {
+ methods.addAll(ifc.getMethodDefinitions());
+ collectImplementedMethods(methods, ifc.getImplements());
+ // }
} else if (Augmentable.class.getName().equals(implementedIfc.getFullyQualifiedName())) {
for (Method method : Augmentable.class.getMethods()) {
if ("getAugmentation".equals(method.getName())) {
importedNames.put("hashMap", importedName(HashMap.class));
importedNames.put("class", importedName(Class.class));
// To do This is for third party, is it needed ?
-// importedNames.put("augmentationHolder", importedName(AugmentationHolder.class));
+ importedNames.put("augmentationHolder", importedName(AugmentationHolder.class));
importedNames.put("collections", importedName(Collections.class));
importedNames.put("augmentFieldReturnType", importedName(augmentField.getReturnType()));
}
}
+ } else if (Instantiable.class.getName().equals(implementedIfc.getFullyQualifiedName())) {
+ importedNames.put("class", importedName(Class.class));
+ instantiable = true;
}
}
}
@Override
protected String body() {
+ final String parentTypeForBuilderName;
importedNames.put("genType", importedName(getType()));
- importedNames.put("arrays", importedName(Arrays.class));
importedNames.put("objects", importedName(Objects.class));
importedNames.put("object", importedName(Object.class));
importedNames.put("string", importedName(String.class));
+ importedNames.put("arrays", importedName(Arrays.class));
importedNames.put("stringBuilder", importedName(StringBuilder.class));
importedNames.put("treeNode", importedName(TreeNode.class));
+ importedNames.put("instantiable", importedName(Instantiable.class));
+ importedNames.put("item", importedName(Item.class));
+ if (getType().getParentType() != null) {
+ importedNames.put("parent", importedName(getType().getParentType()));
+ parentTypeForBuilderName = getType().getParentType().getFullyQualifiedName();
+ } else if (getType().getParentTypeForBuilder() != null) {
+ importedNames.put("parentTypeForBuilder", importedName(getType().getParentTypeForBuilder()));
+ parentTypeForBuilderName = getType().getParentTypeForBuilder().getFullyQualifiedName();
+ } else {
+ parentTypeForBuilderName = null;
+ }
+
+ boolean childTreeNode = false;
+ if (getType().getImplements().contains(BindingTypes.TREE_CHILD_NODE)) {
+ childTreeNode = true;
+ }
+
+ importedNames.put("augmentation", importedName(Augmentation.class));
+ importedNames.put("classInstMap", importedName(ClassToInstanceMap.class));
+
// list for generate copy constructor
final String copyConstructorHelper = generateListForCopyConstructor();
List<String> getterMethods = new ArrayList<>(Collections2.transform(properties, this::getterMethod));
return builderTemplate.render(getType(), properties, importedNames, importedNamesForProperties, augmentField,
- copyConstructorHelper, getterMethods)
+ copyConstructorHelper, getterMethods, parentTypeForBuilderName, childTreeNode, instantiable)
.body();
}