*/
package org.opendaylight.mdsal.binding.java.api.generator
-import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTABLE_AUGMENTATION_NAME
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
import com.google.common.base.MoreObjects
«CodeHelpers.importedName».appendValue(helper, "«property.fieldName»", «property.fieldName»);
«ENDFOR»
«IF augmentType !== null»
- «CodeHelpers.importedName».appendValue(helper, "«AUGMENTATION_FIELD»", «AUGMENTATION_FIELD».values());
+ «CodeHelpers.importedName».appendValue(helper, "«AUGMENTATION_FIELD»", augmentations().values());
«ENDIF»
return helper.toString();
}
«field.getterMethod»
«ENDFOR»
«ENDIF»
- «IF augmentType !== null»
-
- @«SuppressWarnings.importedName»({ "unchecked", "checkstyle:methodTypeParameterName"})
- «IF addOverride»@«Override.importedName»«ENDIF»
- public <E$$ extends «augmentType.importedName»> E$$ «AUGMENTABLE_AUGMENTATION_NAME»(«Class.importedName»<E$$> augmentationType) {
- return (E$$) «AUGMENTATION_FIELD».get(«CodeHelpers.importedName».nonNullValue(augmentationType, "augmentationType"));
- }
- «ENDIF»
'''
def protected final CharSequence generateCopyConstructor(Type fromType, Type implType) '''
«type.name»(«fromType.importedName» base) {
+ «IF augmentType !== null»
+ «generateCopyAugmentation(implType)»
+ «ENDIF»
«val allProps = new ArrayList(properties)»
«val isList = implementsIfc(targetType, Types.parameterizedTypeFor(Types.typeForClass(Identifiable), targetType))»
«IF isList && keyType !== null»
«FOR field : allProps»
this.«field.fieldName» = base.«field.getterMethodName»();
«ENDFOR»
- «IF augmentType !== null»
- «generateCopyAugmentation(implType)»
- «ENDIF»
}
'''
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTABLE_AUGMENTATION_NAME
-import com.google.common.collect.ImmutableMap
import java.util.List
import java.util.Map
import java.util.Objects
import org.opendaylight.mdsal.binding.model.api.GeneratedType
import org.opendaylight.mdsal.binding.model.api.Type
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping
+import org.opendaylight.yangtools.yang.binding.AbstractAugmentable
import org.opendaylight.yangtools.yang.binding.DataObject
class BuilderImplTemplate extends AbstractBuilderTemplate {
}
override body() '''
- private static final class «type.name» implements «targetType.importedName» {
-
- «generateFields(true)»
-
+ private static final class «type.name»
+ «val impIface = targetType.importedName»
«IF augmentType !== null»
- private «generateAugmentField()»
+ extends «AbstractAugmentable.importedName»<«impIface»>
«ENDIF»
+ implements «impIface» {
+
+ «generateFields(true)»
«generateCopyConstructor(builderType, type)»
«hashCodeResult(properties)»
«IF augmentType !== null»
- result = prime * result + «Objects.importedName».hashCode(«AUGMENTATION_FIELD»);
+ result = prime * result + «Objects.importedName».hashCode(augmentations());
«ENDIF»
hash = result;
if (getClass() == obj.getClass()) {
// Simple case: we are comparing against self
«type.name» otherImpl = («type.name») obj;
- if (!«Objects.importedName».equals(«AUGMENTATION_FIELD», otherImpl.«AUGMENTATION_FIELD»)) {
+ if (!«Objects.importedName».equals(augmentations(), otherImpl.augmentations())) {
return false;
}
} else {
// Hard case: compare our augments with presence there...
- for («Map.importedName».Entry<«Class.importedName»<? extends «augmentType.importedName»>, «augmentType.importedName»> e : «AUGMENTATION_FIELD».entrySet()) {
+ for («Map.importedName».Entry<«Class.importedName»<? extends «augmentType.importedName»>, «augmentType.importedName»> e : augmentations().entrySet()) {
if (!e.getValue().equals(other.«AUGMENTABLE_AUGMENTATION_NAME»(e.getKey()))) {
return false;
}
'''
override protected generateCopyAugmentation(Type implType) '''
- this.«AUGMENTATION_FIELD» = «ImmutableMap.importedName».copyOf(base.«AUGMENTATION_FIELD»);
+ super(base.«AUGMENTATION_FIELD»);
'''
}
\ No newline at end of file
package org.opendaylight.mdsal.binding.java.api.generator
import static extension org.apache.commons.text.StringEscapeUtils.escapeJava
+import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTABLE_AUGMENTATION_NAME
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
import com.google.common.collect.ImmutableList
«generateMethodFieldsFrom()»
«generateGetters(false)»
+ «IF augmentType !== null»
+
+ «generateAugmentation()»
+ «ENDIF»
«generateSetters»
'''.toString
}
+ private def generateAugmentation() '''
+ @«SuppressWarnings.importedName»({ "unchecked", "checkstyle:methodTypeParameterName"})
+ public <E$$ extends «augmentType.importedName»> E$$ «AUGMENTABLE_AUGMENTATION_NAME»(«Class.importedName»<E$$> augmentationType) {
+ return (E$$) «AUGMENTATION_FIELD».get(«CodeHelpers.importedName».nonNullValue(augmentationType, "augmentationType"));
+ }
+ '''
+
override protected generateCopyKeys(List<GeneratedProperty> keyProps) '''
this.key = base.«BindingMapping.IDENTIFIABLE_KEY_NAME»();
«FOR field : keyProps»
'''
override protected generateCopyAugmentation(Type implType) {
- val implTypeRef = implType.importedName
val augmentationHolderRef = AugmentationHolder.importedName
val typeRef = targetType.importedName
val hashMapRef = HashMap.importedName
val augmentTypeRef = augmentType.importedName
return '''
- if (base instanceof «implTypeRef») {
- «implTypeRef» impl = («implTypeRef») base;
- if (!impl.«AUGMENTATION_FIELD».isEmpty()) {
- this.«AUGMENTATION_FIELD» = new «hashMapRef»<>(impl.«AUGMENTATION_FIELD»);
- }
- } else if (base instanceof «augmentationHolderRef») {
+ if (base instanceof «augmentationHolderRef») {
@SuppressWarnings("unchecked")
«Map.importedName»<«Class.importedName»<? extends «augmentTypeRef»>, «augmentTypeRef»> aug =((«augmentationHolderRef»<«typeRef»>) base).augmentations();
if (!aug.isEmpty()) {
assertEquals("@Override\n"
+ "public String toString() {\n"
+ " final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(\"test\");\n"
- + " CodeHelpers.appendValue(helper, \"augmentation\", augmentation.values());\n"
+ + " CodeHelpers.appendValue(helper, \"augmentation\", augmentations().values());\n"
+ " return helper.toString();\n"
+ "}\n", genToString(mockAugment(mockGenType(TEST))).toString());
}
+ "public String toString() {\n"
+ " final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(\"test\");\n"
+ " CodeHelpers.appendValue(helper, \"_test\", _test);\n"
- + " CodeHelpers.appendValue(helper, \"augmentation\", augmentation.values());\n"
+ + " CodeHelpers.appendValue(helper, \"augmentation\", augmentations().values());\n"
+ " return helper.toString();\n"
+ "}\n", genToString(mockAugment(mockGenType("get" + TEST))).toString());
}
+ " final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(\"test\");\n"
+ " CodeHelpers.appendValue(helper, \"_test1\", _test1);\n"
+ " CodeHelpers.appendValue(helper, \"_test2\", _test2);\n"
- + " CodeHelpers.appendValue(helper, \"augmentation\", augmentation.values());\n"
+ + " CodeHelpers.appendValue(helper, \"augmentation\", augmentations().values());\n"
+ " return helper.toString();\n"
+ "}\n", genToString(mockAugment(mockGenTypeMoreMeth("get" + TEST))).toString());
}
this(other.augmentations);
}
- @SuppressWarnings({ "unchecked", "checkstyle:methodTypeParameterName"})
+ @SuppressWarnings("unchecked")
@Override
- public final <E$$ extends Augmentation<T>> E$$ augmentation(final Class<E$$> augmentationType) {
- return (E$$) augmentations.get(CodeHelpers.nonNullValue(augmentationType, "augmentationType"));
+ public final <A extends Augmentation<T>> A augmentation(final Class<A> augmentationType) {
+ return (A) augmentations.get(CodeHelpers.nonNullValue(augmentationType, "augmentationType"));
}
@Override
* Returns instance of augmentation.
*
* @param augmentationType Type of augmentation to be returned.
- * @param <E$$> Type capture for augmentation type
+ * @param <A> Type capture for augmentation type
* @return instance of augmentation.
*/
- // E$$ is an identifier which cannot be generated from models.
- @SuppressWarnings("checkstyle:methodTypeParameterName")
- <E$$ extends Augmentation<T>> @Nullable E$$ augmentation(Class<E$$> augmentationType);
+ <A extends Augmentation<T>> @Nullable A augmentation(Class<A> augmentationType);
}