package org.opendaylight.mdsal.binding.java.api.generator
import org.opendaylight.mdsal.binding.model.api.GeneratedProperty
+import org.opendaylight.mdsal.binding.model.api.GeneratedType
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject
+import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
+import org.opendaylight.mdsal.binding.model.api.Type
+import org.opendaylight.mdsal.binding.model.ri.BindingTypes
/**
* Template for generating JAVA class.
}
override allValuesConstructor() '''
+ /**
+ * Constructs an instance.
+ *
+ «FOR p : allProperties»
+ * @param «p.fieldName» the entity «p.getName»
+ «ENDFOR»
+ * @throws NullPointerException if any of the arguments are null
+ */
public «type.name»(«allProperties.asNonNullArgumentsDeclaration») {
«FOR p : allProperties»
«val fieldName = p.fieldName»
'''
override getterMethod(GeneratedProperty field) '''
+ /**
+ * Return «field.getName», guaranteed to be non-null.
+ *
+ * @return {@code «field.returnType.importedName»} «field.getName», guaranteed to be non-null.
+ */
public «field.returnType.importedNonNull» «field.getterMethodName»() {
return «field.fieldName»«field.cloneCall»;
}
'''
+
+ override protected String formatDataForJavaDoc(GeneratedType type) {
+ val listType = findListType(type)
+ if (listType === null) {
+ return ""
+ }
+
+ val importedName = listType.importedName
+ return '''
+ This class represents the key of {@link «importedName»} class.
+
+ @see «importedName»
+ '''
+ }
+
+ private static def Type findListType(GeneratedType type) {
+ for (Type implType : type.getImplements()) {
+ if (implType instanceof ParameterizedType) {
+ val identifiable = BindingTypes.extractIdentifiable(implType)
+ if (identifiable !== null) {
+ return identifiable
+ }
+ }
+ }
+ return null
+ }
}
}
return null;
}
+
+ /**
+ * Return the {@link Identifiable} type a parameterized {@link Identifier} type references.
+ *
+ * @param type Parameterized type
+ * @return Identifiable target, or null if {@code type} does not match the result of {@link #identifier(Type)}
+ * @throws NullPointerException if {@code type} is null
+ */
+ @Beta
+ public static @Nullable Type extractIdentifiable(final ParameterizedType type) {
+ if (IDENTIFIER.equals(type.getRawType())) {
+ final var args = type.getActualTypeArguments();
+ if (args.length == 1) {
+ final var arg = args[0];
+ if (arg != null) {
+ return arg;
+ }
+ }
+ }
+ return null;
+ }
}