package org.opendaylight.mdsal.binding.java.api.generator
import static extension org.apache.commons.text.StringEscapeUtils.escapeJava
-import static org.opendaylight.mdsal.binding.model.util.BindingTypes.DATA_OBJECT
+import static org.opendaylight.mdsal.binding.model.ri.BindingTypes.DATA_OBJECT
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTABLE_AUGMENTATION_NAME
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME
import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.mdsal.binding.model.api.ParameterizedType
import org.opendaylight.mdsal.binding.model.api.Type
-import org.opendaylight.mdsal.binding.model.util.TypeConstants
-import org.opendaylight.mdsal.binding.model.util.Types
+import org.opendaylight.mdsal.binding.model.ri.TypeConstants
+import org.opendaylight.mdsal.binding.model.ri.Types
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping
import org.opendaylight.yangtools.concepts.Builder
* Template for generating JAVA builder classes.
*/
class BuilderTemplate extends AbstractBuilderTemplate {
- /**
- * Constant used as suffix for builder name.
- */
- package static val BUILDER_STR = "Builder";
-
static val BUILDER = JavaTypeName.create(Builder)
val BuilderImplTemplate implTemplate
def private Object generateConstructorFromIfc(Type impl) '''
«IF (impl instanceof GeneratedType)»
«IF impl.hasNonDefaultMethods»
- public «type.name»(«impl.fullyQualifiedName» arg) {
+ public «type.name»(«impl.importedName» arg) {
«printConstructorPropertySetter(impl)»
}
«ENDIF»
* Set fields from given grouping argument. Valid argument is instance of one of following types:
* <ul>
«FOR impl : type.getAllIfcs»
- * <li>«impl.fullyQualifiedName»</li>
+ * <li>«impl.importedName»</li>
«ENDFOR»
* </ul>
*
def private generateIfCheck(Type impl, List<Type> done) '''
«IF (impl instanceof GeneratedType && (impl as GeneratedType).hasNonDefaultMethods)»
«val implType = impl as GeneratedType»
- if (arg instanceof «implType.fullyQualifiedName») {
+ if (arg instanceof «implType.importedName») {
«printPropertySetter(implType)»
isValidArg = true;
}
«val ifc = implementedIfc as GeneratedType»
«FOR getter : ifc.nonDefaultMethods»
«IF BindingMapping.isGetterMethodName(getter.name) && !hasOverrideAnnotation(getter)»
- «printPropertySetter(getter, '''((«ifc.fullyQualifiedName»)arg).«getter.name»()''', getter.propertyNameFromGetter)»;
+ «printPropertySetter(getter, '''((«ifc.importedName»)arg).«getter.name»()''', getter.propertyNameFromGetter)»;
«ENDIF»
«ENDFOR»
«ENDIF»
if (Types.isListType(ownGetterType)) {
val itemType = (ownGetterType as ParameterizedType).actualTypeArguments.get(0)
return '''
- this._«propertyName» = «CODEHELPERS.importedName».checkListFieldCast(«itemType.fullyQualifiedName».class, "«propertyName»", «retrieveProperty»)'''
+ this._«propertyName» = «CODEHELPERS.importedName».checkListFieldCast(«itemType.importedName».class, "«propertyName»", «retrieveProperty»)'''
}
return '''
- this._«propertyName» = «CODEHELPERS.importedName».checkFieldCast(«ownGetter.returnType.fullyQualifiedName».class, "«propertyName»", «retrieveProperty»)'''
+ this._«propertyName» = «CODEHELPERS.importedName».checkFieldCast(«ownGetter.returnType.importedName».class, "«propertyName»", «retrieveProperty»)'''
}
private def List<Type> getBaseIfcs(GeneratedType type) {
private def List<String> toListOfNames(Collection<Type> types) {
val List<String> names = new ArrayList
for (type : types) {
- names.add(type.fullyQualifiedName)
+ names.add(type.importedName)
}
return names
}
'''
private def createDescription(GeneratedType targetType) {
- val target = type.importedName
+ val target = targetType.importedName
return '''
Class that builds {@link «target»} instances. Overall design of the class is that of a
<a href="https://en.wikipedia.org/wiki/Fluent_interface">fluent interface</a>, where method chaining is used.
In general, this class is supposed to be used like this template:
<pre>
<code>
- «target» createTarget(int fooXyzzy, int barBaz) {
+ «target» create«target»(int fooXyzzy, int barBaz) {
return new «target»Builder()
.setFoo(new FooBuilder().setXyzzy(fooXyzzy).build())
.setBar(new BarBuilder().setBaz(barBaz).build())
invocation, which is terminated by {@link #build()}, which is then returned from the method</li>
<li>better understanding by humans, as the scope of mutable state (the builder) is kept to a minimum and is
very localized</li>
- <li>better optimization oportunities, as the object scope is minimized in terms of invocation (rather than
+ <li>better optimization opportunities, as the object scope is minimized in terms of invocation (rather than
method) stack, making <a href="https://en.wikipedia.org/wiki/Escape_analysis">escape analysis</a> a lot
easier. Given enough compiler (JIT/AOT) prowess, the cost of th builder object can be completely
eliminated</li>