package org.opendaylight.mdsal.binding.java.api.generator
import static extension org.opendaylight.mdsal.binding.generator.BindingGeneratorUtil.encodeAngleBrackets
+import static org.opendaylight.mdsal.binding.model.ri.Types.STRING;
+import static org.opendaylight.mdsal.binding.model.ri.Types.objectType;
import com.google.common.base.CharMatcher
import com.google.common.base.Splitter
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
import org.opendaylight.mdsal.binding.model.api.Constant
import org.opendaylight.mdsal.binding.model.api.Type
import org.opendaylight.mdsal.binding.model.api.TypeMemberComment
import org.opendaylight.mdsal.binding.model.ri.TypeConstants
-import org.opendaylight.mdsal.binding.spec.naming.BindingMapping
+import org.opendaylight.yangtools.yang.binding.BaseIdentity
+import org.opendaylight.yangtools.yang.binding.contract.Naming
+import org.opendaylight.yangtools.yang.common.YangDataName
-@SuppressModernizer
-abstract class BaseTemplate extends JavaFileTemplate {
+abstract class BaseTemplate extends AbstractBaseTemplate {
static final char NEW_LINE = '\n'
static final char SPACE = ' '
static val WS_MATCHER = CharMatcher.anyOf("\n\t")
super(javaType, type)
}
- final def generate() {
- val _body = body()
- '''
- package «type.packageName»;
- «generateImportBlock»
-
- «_body»
- '''.toString
- }
-
- protected abstract def CharSequence body();
-
// Helper patterns
- final protected def fieldName(GeneratedProperty property) {
- "_" + property.name
- }
-
/**
* Template method which generates the getter method for <code>field</code>
*
}
'''
- final protected def getterMethodName(GeneratedProperty field) {
- return '''«BindingMapping.GETTER_PREFIX»«field.name.toFirstUpper»'''
- }
-
/**
* Template method which generates the setter method for <code>field</code>
*
sb.append(lineBuilder).append(NEW_LINE)
lineBuilder.setLength(0)
- if (nextElement == " ") {
+ if (" ".equals(nextElement)) {
isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;
}
}
»'''
def protected emitConstant(Constant c) '''
- «IF BindingMapping.QNAME_STATIC_FIELD_NAME.equals(c.name)»
+ «IF Naming.QNAME_STATIC_FIELD_NAME.equals(c.name)»
«val entry = c.value as Entry<JavaTypeName, String>»
- public static final «c.type.importedNonNull» «c.name» = «entry.key.importedName».«BindingMapping.MODULE_INFO_QNAMEOF_METHOD_NAME»("«entry.value»");
+ /**
+ * YANG identifier of the statement represented by this class.
+ */
+ public static final «c.type.importedNonNull» «c.name» = «entry.key.importedName».«Naming.MODULE_INFO_QNAMEOF_METHOD_NAME»("«entry.value»");
+ «ELSEIF Naming.NAME_STATIC_FIELD_NAME.equals(c.name)»
+ «val entry = c.value as Entry<JavaTypeName, YangDataName>»
+ /**
+ * Yang Data template name of the statement represented by this class.
+ */
+ public static final «c.type.importedNonNull» «c.name» = «entry.key.importedName».«Naming.MODULE_INFO_YANGDATANAMEOF_METHOD_NAME»("«entry.value.name»");
+ «ELSEIF Naming.VALUE_STATIC_FIELD_NAME.equals(c.name) && BaseIdentity.equals(c.value)»
+ «val typeName = c.type.importedName»
+ «val override = OVERRIDE.importedName»
+ /**
+ * Singleton value representing the {@link «typeName»} identity.
+ */
+ public static final «c.type.importedNonNull» «c.name» = new «typeName»() {
+ @«override»
+ public «CLASS.importedName»<«typeName»> «Naming.BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME»() {
+ return «typeName».class;
+ }
+
+ @«override»
+ public int hashCode() {
+ return «typeName».class.hashCode();
+ }
+
+ @«override»
+ public boolean equals(final «objectType.importedName» obj) {
+ return obj == this || obj instanceof «typeName» other
+ && «typeName».class.equals(other.«Naming.BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME»());
+ }
+
+ @«override»
+ public «STRING.importedName» toString() {
+ return «MOREOBJECTS.importedName».toStringHelper("«c.type.name»").add("qname", QNAME).toString();
+ }
+ };
«ELSE»
public static final «c.type.importedName» «c.name» = «c.value»;
«ENDIF»
def protected generateCheckers(GeneratedProperty field, Restrictions restrictions, Type actualType) '''
«IF restrictions.rangeConstraint.present»
«AbstractRangeGenerator.forType(actualType).generateRangeChecker(field.name.toFirstUpper,
- restrictions.rangeConstraint.get, this)»
+ restrictions.rangeConstraint.orElseThrow, this)»
«ENDIF»
«IF restrictions.lengthConstraint.present»
- «LengthGenerator.generateLengthChecker(field.fieldName, actualType, restrictions.lengthConstraint.get, this)»
+ «LengthGenerator.generateLengthChecker(field.fieldName, actualType, restrictions.lengthConstraint.orElseThrow, this)»
«ENDIF»
'''
«ENDFOR»
'''
- def protected hashCodeResult(Collection<? extends GeneratedProperty> properties) '''
- final int prime = 31;
- int result = 1;
- «FOR property : properties»
- result = prime * result + «property.importedUtilClass».hashCode(«property.fieldName»);
- «ENDFOR»
- '''
-
def protected final generateAnnotation(AnnotationType annotation) '''
@«annotation.importedName»
«IF annotation.parameters !== null && !annotation.parameters.empty»