import org.opendaylight.yangtools.concepts.Builder
/**
- * Template for generating JAVA builder classes.
+ * Template for generating JAVA builder classes.
*/
class BuilderTemplate extends BaseTemplate {
/**
* Returns set of method signature instances which contains all the methods of the <code>genType</code>
* and all the methods of the implemented interfaces.
- *
+ *
* @returns set of method signature instances
*/
def private Set<MethodSignature> createMethods() {
}
/**
- * Adds to the <code>methods</code> set all the methods of the <code>implementedIfcs</code>
+ * Adds to the <code>methods</code> set all the methods of the <code>implementedIfcs</code>
* and recursively their implemented interfaces.
- *
+ *
* @param methods set of method signatures
* @param implementedIfcs list of implemented interfaces
*/
/**
* Returns the first element of the list <code>elements</code>.
- *
+ *
* @param list of elements
*/
def private <E> first(List<E> elements) {
/**
* Returns the name of the package from <code>fullyQualifiedName</code>.
- *
+ *
* @param fullyQualifiedName string with fully qualified type name (package + type)
* @return string with the package name
*/
/**
* Creates set of generated property instances from getter <code>methods</code>.
- *
- * @param set of method signature instances which should be transformed to list of properties
+ *
+ * @param set of method signature instances which should be transformed to list of properties
* @return set of generated property instances which represents the getter <code>methods</code>
*/
def private propertiesFromMethods(Collection<MethodSignature> methods) {
/**
* Creates generated property instance from the getter <code>method</code> name and return type.
- *
+ *
* @param method method signature from which is the method name and return type obtained
* @return generated property instance for the getter <code>method</code>
* @throws IllegalArgumentException<ul>
var prefix = "get";
if(Types.BOOLEAN.equals(method.returnType)) {
prefix = "is";
- }
+ }
if (method.name.startsWith(prefix)) {
val fieldName = method.getName().substring(prefix.length()).toFirstLower
val tmpGenTO = new GeneratedTOBuilderImpl("foo", "foo")
}
/**
- * Template method which generates JAVA class body for builder class and for IMPL class.
- *
+ * Template method which generates JAVA class body for builder class and for IMPL class.
+ *
* @return string with JAVA source code
*/
override body() '''
«generateHashCode()»
«generateEquals()»
-
+
«generateToString(properties)»
}
*/
def private generateConstructorsFromIfcs(Type type) '''
public «type.name»«BUILDER»() {
- }
+ }
«IF (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject))»
«val ifc = type as GeneratedType»
«FOR impl : ifc.implements»
baseIfcs.add(ifc)
}
}
- return baseIfcs
+ return baseIfcs
}
private def Set<Type> getAllIfcs(Type type) {
baseIfcs.addAll(impl.getAllIfcs)
}
}
- return baseIfcs
+ return baseIfcs
}
private def List<String> toListOfNames(Collection<Type> types) {
break;
case 1:
final «Map.importedName».Entry<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»> e = «prop».«augmentField.name».entrySet().iterator().next();
- this.«augmentField.name» = «Collections.importedName».<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»>singletonMap(e.getKey(), e.getValue());
+ this.«augmentField.name» = «Collections.importedName».<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»>singletonMap(e.getKey(), e.getValue());
break;
default :
this.«augmentField.name» = new «HashMap.importedName»<>(«prop».«augmentField.name»);
/**
* Template method which generate getter methods for IMPL class.
- *
+ *
* @return string with getter methods
*/
def private generateGetters(boolean addOverride) '''
/**
* Template method which generates the method <code>hashCode()</code>.
- *
+ *
* @return string with the <code>hashCode()</code> method definition in JAVA format
*/
def protected generateHashCode() '''
/**
* Template method which generates the method <code>equals()</code>.
- *
- * @return string with the <code>equals()</code> method definition in JAVA format
+ *
+ * @return string with the <code>equals()</code> method definition in JAVA format
*/
def protected generateEquals() '''
«IF !properties.empty || augmentField != null»
return «type.importedName».class;
}
'''
-
+
private def createDescription(GeneratedType type) {
return '''
Class that builds {@link «type.importedName»} instances.
-
+
@see «type.importedName»
'''
}
-
+
override def protected String formatDataForJavaDoc(GeneratedType type) {
val typeDescription = createDescription(type)
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
/**
- * Template for generating JAVA enumeration type.
+ * Template for generating JAVA enumeration type.
*/
class EnumTemplate extends BaseTemplate {
-
+
/**
* Enumeration which will be transformed to JAVA source code for enumeration
*/
val Enumeration enums
-
+
/**
* Constructs instance of this class with concrete <code>enums</code>.
- *
- * @param enums enumeration which will be transformed to JAVA source code
+ *
+ * @param enums enumeration which will be transformed to JAVA source code
*/
new(Enumeration enums) {
super(enums as GeneratedType )
this.enums = enums
}
-
-
+
+
/**
* Generates only JAVA enumeration source code.
- *
+ *
* @return string with JAVA enumeration source code
*/
def generateAsInnerClass() {
return body
}
-
+
def writeEnumItem(String name, int value, String description) '''
«asJavadoc(formatToParagraph(description))»
«name»(«value»)
/**
* Template method which generates enumeration body (declaration + enumeration items).
- *
- * @return string with the enumeration body
+ *
+ * @return string with the enumeration body
*/
override body() '''
«wrapToDocumentation(formatDataForJavaDoc(enums))»
VALUE_MAP = b.build();
}
-
+
private «enums.name»(int value) {
this.value = value;
}
-
+
/**
* @return integer value
*/
import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature\rimport org.opendaylight.yangtools.sal.binding.model.api.AnnotationType
/**
- * Template for generating JAVA interfaces.
+ * Template for generating JAVA interfaces.
*/
class InterfaceTemplate extends BaseTemplate {
-
+
/**
* List of constant instances which are generated as JAVA public static final attributes.
*/
val List<Constant> consts
-
+
/**
* List of method signatures which are generated as method declarations.
*/
val List<MethodSignature> methods
-
+
/**
* List of enumeration which are generated as JAVA enum type.
*/
val List<Enumeration> enums
-
+
/**
* List of generated types which are enclosed inside <code>genType</code>
*/
val List<GeneratedType> enclosedGeneratedTypes
-
+
/**
- * Creates the instance of this class which is used for generating the interface file source
+ * Creates the instance of this class which is used for generating the interface file source
* code from <code>genType</code>.
- *
+ *
* @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>
*/
new(GeneratedType genType) {
if (genType == null) {
throw new IllegalArgumentException("Generated type reference cannot be NULL!")
}
-
+
consts = genType.constantDefinitions
methods = genType.methodDefinitions
enums = genType.enumerations
enclosedGeneratedTypes = genType.enclosedTypes
}
-
+
/**
* Template method which generate the whole body of the interface.
- *
+ *
* @return string with code for interface body in JAVA format
*/
override body() '''
public interface «type.name»
«superInterfaces»
{
-
+
«generateInnerClasses»
-
+
«generateEnums»
-
+
«generateConstants»
-
+
«generateMethods»
-
+
}
-
+
'''
-
+
def private generateAnnotations(List<AnnotationType> annotations) '''
«IF annotations != null && !annotations.empty»
/**
* Template method which generates the interface name declaration.
- *
+ *
* @return string with the code for the interface declaration in JAVA format
*/
- def private superInterfaces()
+ def private superInterfaces()
'''
«IF (!type.implements.empty)»
extends
/**
* Template method which generates inner classes inside this interface.
- *
+ *
* @return string with the source code for inner classes in JAVA format
*/
def private generateInnerClasses() '''
/**
* Template method which generates JAVA enum type.
- *
+ *
* @return string with inner enum source code in JAVA format
- */
+ */
def private generateEnums() '''
«IF !enums.empty»
«FOR e : enums SEPARATOR "\n"»
«ENDFOR»
«ENDIF»
'''
-
+
/**
* Template method wich generates JAVA constants.
- *
- * @return string with constants in JAVA format
- */
+ *
+ * @return string with constants in JAVA format
+ */
def private generateConstants() '''
«IF !consts.empty»
«FOR c : consts»
/**
* Template method which generates the declaration of the methods.
- *
- * @return string with the declaration of methods source code in JAVA format
- */
+ *
+ * @return string with the declaration of methods source code in JAVA format
+ */
def private generateMethods() '''
«IF !methods.empty»
«FOR m : methods SEPARATOR "\n"»
import static org.opendaylight.yangtools.binding.generator.util.Types.*
/**
- * Template for generating JAVA class.
+ * Template for generating JAVA class.
*/
class UnionTemplate extends ClassTemplate {
/**
* Creates instance of this class with concrete <code>genType</code>.
- *
+ *
* @param genType generated transfer object which will be transformed to JAVA class source code
*/
new(GeneratedTransferObject genType) {
«IF isCharArray»
/**
* Constructor provided only for using in JMX. Don't use it for
- * construction new object of this union type.
+ * construction new object of this union type.
*/
@«ConstructorProperties.importedName»("«property.name»")
public «type.name»(«propRet.importedName» «property.fieldName») {
this.«other.fieldName» = «property.fieldName».getValue();
«ELSEIF propRet instanceof GeneratedTransferObject // Is it a GeneratedTransferObject
&& (propRet as GeneratedTransferObject).typedef // Is it a typedef
- && (propRet as GeneratedTransferObject).properties != null
- && !(propRet as GeneratedTransferObject).properties.empty
- && ((propRet as GeneratedTransferObject).properties.size == 1)
- && (propRet as GeneratedTransferObject).properties.get(0).name.equals("value")
+ && (propRet as GeneratedTransferObject).properties != null
+ && !(propRet as GeneratedTransferObject).properties.empty
+ && ((propRet as GeneratedTransferObject).properties.size == 1)
+ && (propRet as GeneratedTransferObject).properties.get(0).name.equals("value")
&& BOOLEAN.equals((propRet as GeneratedTransferObject).properties.get(0).returnType)» // And the property value is of type boolean
««« generated boolean typedef
this.«other.fieldName» = «property.fieldName».isValue().toString().toCharArray();
«val DateFormat df = new SimpleDateFormat("yyyy-MM-dd")»
private final «String.importedName» revision = "«df.format(module.revision)»";
private final «String.importedName» resourcePath = "«sourcePath»";
-
+
private final «Set.importedName»<YangModuleInfo> importedModules;
public static «YangModuleInfo.importedName» getInstance() {
return "/" + module.moduleSourcePath.replace(java.io.File.separatorChar, '/')
}
- private def imports() '''
+ private def imports() '''
«IF !importMap.empty»
«FOR entry : importMap.entrySet»
«IF entry.value != getRootPackageName(module.QNameModule)»