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.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
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;
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()));
}
@Override
protected String body() {
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("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()));
+ } else {
+ //TODO implement - get module as type
+ }
+ 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));
@generateEquals()
@generateToString()
+
+ @generateImplementedMethods()
}
}
}
}
@implementedInterfaceGetter() = {
- public @{importedNames.get("class")}<@{importedNames.get("genType")}> getImplementedInterface() {
+ @@Override
+ public @{importedNames.get("class")}<@{importedNames.get("genType")}> implementedInterface() {
return @{importedNames.get("genType")}.class;
}
}
}
}
+@generateImplType() = {
+@defining(genType.getName + "Impl") {typeImpl => @typeImpl}
+}
+
+@generateBuilderType() = {
+@defining(genType.getName + "Builder") {typeBuilder => @typeBuilder}
+}
+
+@generateInnerBuilderType() = {
+@defining("(" + genType.getName + "Builder base)") {typeInnerBuilder => @typeInnerBuilder}
+}
+
+@generateInnerType() = {
+@defining("(" + genType.getName + " base)") {innerType => @innerType}
+}
+
@generateCopyConstructor(impl: Boolean) = {
@if(impl) {private} else {public}
- @{genType.getName}
- @if(impl) {Impl} else {Builder}
- (@{genType.getName}
- @if(impl) {Builder} base) {
+ @if(impl) {@generateImplType()} else {@generateBuilderType()}
+ @if(impl) {@generateInnerBuilderType()} else {@generateInnerType()}
+ {
@{copyConstructorHelper}
@if(augmentField != null) {
@if(impl) {
@if(augmentField != null) {
@@SuppressWarnings("unchecked")
@if(addOverride) {@@Override}
- public <E extends @{importedNames.get("augmentFieldReturnType")}> E get@{toFirstUpper(augmentField.getName)}
+ public <E extends @{importedNames.get("augmentation")}<? super @{genType.getName}>> E get@{toFirstUpper(augmentField.getName)}
(@{importedNames.get("class")}<E> augmentationType) {
if (augmentationType == null) {
throw new IllegalArgumentException("Augmentation Type reference cannot be NULL!");
}
}
+@generateImplementedMethods() = {
+ @@Override
+ public @{importedNames.get("item")}<@{genType.getParentType.getName}> treeIdentifier() {
+ //TODO implement
+ return null;
+ }
+
+ @@Override
+ public @{importedNames.get("classInstMap")}<@{importedNames.get("augmentation")}<? super @{genType.getName}>>
+ augments() {
+ //TODO implement
+ return null;
+ }
+}
+
@generateEquals() = {
@if(!properties.isEmpty || augmentField != null) {
@@Override
if (!(obj instanceof @{importedNames.get("treeNode")})) {
return false;
}
- if (!@{importedNames.get("genType")}.class.equals(((@{importedNames.get("treeNode")})obj).getImplementedInterface)) {
+ if (!(obj instanceof @{importedNames.get("instantiable")})) {
+ return false;
+ }
+ if (!@{importedNames.get("genType")}.class.equals(((@{importedNames.get("instantiable")})obj)
+ .implementedInterface())) {
return false;
}
@{importedNames.get("genType")} other = (@{importedNames.get("genType")})obj;
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.binding.javav2.spec.structural;
+
+import java.util.Map;
+
+/**
+ *
+ * Augmentable (extensible) object which could carry additional data defined by
+ * third-party extensions, without introducing conflict between various
+ * extensions.
+ *
+ * @param <T>
+ * Base class which should be target
+ * for augmentations.
+ */
+public interface AugmentationHolder<T> {
+
+ /**
+ * Returns map of all augmentations.
+ *
+ * @return map of all augmentations.
+ */
+ Map<Class<? extends Augmentation<T>>,Augmentation<T>> augmentations();
+}
\ No newline at end of file