import java.util.Map.Entry
import java.util.StringTokenizer
import java.util.regex.Pattern
+import org.eclipse.jdt.annotation.NonNull;
import org.gaul.modernizer_maven_annotations.SuppressModernizer
import org.opendaylight.mdsal.binding.model.api.AnnotationType
import org.opendaylight.mdsal.binding.model.api.ConcreteType
def final protected asArgumentsDeclaration(Iterable<GeneratedProperty> parameters) '''«IF !parameters.empty»«FOR parameter : parameters SEPARATOR ", "»«parameter.
returnType.importedName» «parameter.fieldName»«ENDFOR»«ENDIF»'''
+ /**
+ * Template method which generates method parameters with their types from <code>parameters</code>, annotating them
+ * with {@link NonNull}.
+ *
+ * @param parameters group of generated property instances which are transformed to the method parameters
+ * @return string with the list of the method parameters with their types in JAVA format
+ */
+ def final protected asNonNullArgumentsDeclaration(Iterable<GeneratedProperty> parameters) '''«IF !parameters.empty»
+ «FOR parameter : parameters SEPARATOR ", "»«parameter.returnType.importedNonNull» «parameter
+ .fieldName»«ENDFOR»«ENDIF»'''
+
/**
* Template method which generates sequence of the names of the class attributes from <code>parameters</code>.
*
«ENDIF»
'''
- def private allValuesConstructor() '''
+ def allValuesConstructor() '''
public «type.name»(«allProperties.asArgumentsDeclaration») {
«IF !parentProperties.empty»
super(«parentProperties.asArguments»);
}
}
- def private generateRestrictions(Type type, String paramName, Type returnType) '''
+ def generateRestrictions(Type type, String paramName, Type returnType) '''
«val restrictions = type.restrictions»
«IF restrictions !== null»
«IF restrictions.lengthConstraint.present || restrictions.rangeConstraint.present»
--- /dev/null
+/*
+ * Copyright (c) 2020 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.java.api.generator
+
+import org.opendaylight.mdsal.binding.model.api.GeneratedProperty
+import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject
+
+/**
+ * Template for generating JAVA class.
+ */
+class ListKeyTemplate 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) {
+ super(genType)
+ }
+
+
+ override final allValuesConstructor() '''
+ public «type.name»(«allProperties.asNonNullArgumentsDeclaration») {
+ «FOR p : allProperties»
+ «CODEHELPERS.importedName».requireValue(«p.fieldName»);
+ «ENDFOR»
+ «FOR p : properties»
+ «generateRestrictions(type, p.fieldName, p.returnType)»
+ «ENDFOR»
+
+ «FOR p : allProperties»
+ «val fieldName = p.fieldName»
+ «IF p.returnType.name.endsWith("[]")»
+ this.«fieldName» = «fieldName».clone();
+ «ELSE»
+ this.«fieldName» = «fieldName»;
+ «ENDIF»
+ «ENDFOR»
+ }
+ '''
+
+ override final def getterMethod(GeneratedProperty field) {
+ '''
+ public «field.returnType.importedNonNull» «field.getterMethodName»() {
+ «val fieldName = field.fieldName»
+ «IF field.returnType.name.endsWith("[]")»
+ return «fieldName».clone();
+ «ELSE»
+ return «fieldName»;
+ «ENDIF»
+ }
+ '''
+ }
+}
} else if (genTO.isUnionTypeBuilder()) {
final UnionBuilderTemplate template = new UnionBuilderTemplate(genTO);
return template.generate();
- } else {
+ } else if (genTO.isTypedef()) {
final ClassTemplate template = new ClassTemplate(genTO);
return template.generate();
+ } else {
+ final ListKeyTemplate template = new ListKeyTemplate(genTO);
+ return template.generate();
}
}
return "";
final String outputStr = clsGen.generate(genTO);
assertNotNull(outputStr);
- assertTrue(outputStr.contains("public CompositeKeyListKey(Byte _key1, String _key2)"));
+ assertTrue(outputStr.contains("public CompositeKeyListKey(@NonNull Byte _key1, @NonNull String"
+ + " _key2)"));
assertEquals(2, propertyCount);
genTOsCount++;