X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-java-api-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fjava%2Fapi%2Fgenerator%2FInterfaceTemplate.xtend;h=84c627c28e03af192f97626ebc632b8ec5274345;hb=d49eb84dc5c7ec6201660fa899b79c564242d275;hp=23e47b6ce0e2360d0e1fb653cac9875cf5b1df27;hpb=e54d4a7c334812e4fe01292c8316e5e6ad288210;p=mdsal.git diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/InterfaceTemplate.xtend b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/InterfaceTemplate.xtend index 23e47b6ce0..84c627c28e 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/InterfaceTemplate.xtend +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/InterfaceTemplate.xtend @@ -7,17 +7,23 @@ */ package org.opendaylight.mdsal.binding.java.api.generator -import static org.opendaylight.mdsal.binding.model.util.Types.STRING; import static extension org.opendaylight.mdsal.binding.spec.naming.BindingMapping.getGetterMethodForNonnull +import static extension org.opendaylight.mdsal.binding.spec.naming.BindingMapping.getGetterMethodForRequire import static extension org.opendaylight.mdsal.binding.spec.naming.BindingMapping.isGetterMethodName import static extension org.opendaylight.mdsal.binding.spec.naming.BindingMapping.isNonnullMethodName +import static extension org.opendaylight.mdsal.binding.spec.naming.BindingMapping.isRequireMethodName +import static org.opendaylight.mdsal.binding.model.ri.Types.BOOLEAN +import static org.opendaylight.mdsal.binding.model.ri.Types.STRING +import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.REQUIRE_PREFIX import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD +import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME +import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.BINDING_EQUALS_NAME import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.BINDING_HASHCODE_NAME import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.BINDING_TO_STRING_NAME -import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME -import com.google.common.base.MoreObjects +import com.google.common.annotations.VisibleForTesting; import java.util.List +import java.util.Locale import java.util.Map.Entry import java.util.Set import org.gaul.modernizer_maven_annotations.SuppressModernizer @@ -25,9 +31,12 @@ import org.opendaylight.mdsal.binding.model.api.AnnotationType import org.opendaylight.mdsal.binding.model.api.Constant import org.opendaylight.mdsal.binding.model.api.Enumeration import org.opendaylight.mdsal.binding.model.api.GeneratedType +import org.opendaylight.mdsal.binding.model.api.JavaTypeName 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.ri.Types +import org.opendaylight.mdsal.binding.model.ri.TypeConstants /** * Template for generating JAVA interfaces. @@ -76,8 +85,9 @@ class InterfaceTemplate extends BaseTemplate { * @return string with code for interface body in JAVA format */ override body() ''' - «wrapToDocumentation(formatDataForJavaDoc(type))» + «type.formatDataForJavaDoc.wrapToDocumentation» «type.annotations.generateAnnotations» + «generatedAnnotation» public interface «type.name» «superInterfaces» { @@ -102,6 +112,17 @@ class InterfaceTemplate extends BaseTemplate { «ENDIF» ''' + def private generateAccessorAnnotations(MethodSignature method) ''' + «val annotations = method.annotations» + «IF annotations !== null && !annotations.empty» + «FOR annotation : annotations» + «IF method.returnType != BOOLEAN || !(annotation.identifier == OVERRIDE)» + «annotation.generateAnnotation» + «ENDIF» + «ENDFOR» + «ENDIF» + ''' + /** * Template method which generates the interface name declaration. * @@ -145,7 +166,7 @@ class InterfaceTemplate extends BaseTemplate { ''' /** - * Template method wich generates JAVA constants. + * Template method which generates JAVA constants. * * @return string with constants in JAVA format */ @@ -183,17 +204,25 @@ class InterfaceTemplate extends BaseTemplate { def private generateDefaultMethod(MethodSignature method) { if (method.name.isNonnullMethodName) { generateNonnullMethod(method) + } else if (method.name.isRequireMethodName) { + generateRequireMethod(method) } else { switch method.name { - case DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME : generateDefaultImplementedInterface + case BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME : generateDefaultImplementedInterface + default : + if (VOID == method.returnType.identifier) { + generateNoopVoidInterfaceMethod(method) + } } } } def private generateStaticMethod(MethodSignature method) { switch method.name { + case BINDING_EQUALS_NAME : generateBindingEquals case BINDING_HASHCODE_NAME : generateBindingHashCode case BINDING_TO_STRING_NAME : generateBindingToString + default : "" } } @@ -203,51 +232,106 @@ class InterfaceTemplate extends BaseTemplate { «method.returnType.importedName» «method.name»(«method.parameters.generateParameters»); ''' - def private generateAccessorMethod(MethodSignature method) ''' - «val ret = method.returnType» - «formatDataForJavaDoc(method, "@return " + asCode(ret.fullyQualifiedName) + " " + asCode(propertyNameFromGetter(method)) + ", or " + asCode("null") + " if not present")» + def private generateNoopVoidInterfaceMethod(MethodSignature method) ''' + «method.comment.asJavadoc» «method.annotations.generateAnnotations» - «nullableType(ret)» «method.name»(); + default «VOID.importedName» «method.name»(«method.parameters.generateParameters») { + // No-op + } ''' + def private accessorJavadoc(MethodSignature method, String orString) { + accessorJavadoc(method, orString, null) + } + + def private accessorJavadoc(MethodSignature method, String orString, JavaTypeName exception) { + val propName = method.propertyNameFromGetter + val propReturn = propName + orString + + return wrapToDocumentation(''' + Return «propReturn» + + «method.comment?.referenceDescription.formatReference» + @return {@code «method.returnType.importedName»} «propReturn» + «IF exception !== null» + @throws «exception.importedName» if «propName» is not present + «ENDIF» + ''') + } + + def private generateAccessorMethod(MethodSignature method) { + return ''' + «accessorJavadoc(method, ", or {@code null} if it is not present.")» + «method.generateAccessorAnnotations» + «method.returnType.nullableType» «method.name»(); + ''' + } + def private generateDefaultImplementedInterface() ''' @«OVERRIDE.importedName» - default «CLASS.importedName»<«type.fullyQualifiedName»> «DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME»() { + default «CLASS.importedName»<«type.fullyQualifiedName»> «BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME»() { return «type.fullyQualifiedName».class; } ''' - def private generateBindingHashCode() ''' + @VisibleForTesting + def generateBindingHashCode() ''' «val augmentable = analyzeType» - /** - * Default implementation of {@link «Object.importedName»#hashCode()} contract for this interface. - * Implementations of this interface are encouraged to defer to this method to get consistent hashing - * results across all implementation. - * - «IF augmentable» - *
- * @param
- * @param