import java.util.Set
import java.util.TreeMap
-import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
import org.opendaylight.yangtools.binding.generator.util.Types
import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType
import org.opendaylight.yangtools.sal.binding.model.api.Type
Preconditions.checkArgument(module != null, "Module must not be null.");
this.module = module
this.ctx = ctx
- _packageName = BindingGeneratorUtil.moduleNamespaceToPackageName(module);
+ _packageName = getRootPackageName(module.getQNameModule());
_modelBindingProviderName = '''«packageName».«MODEL_BINDING_PROVIDER_CLASS_NAME»''';
}
«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 INSTANCE;
}
- «module.classBody»
+ «classBody(module, MODULE_INFO_CLASS_NAME)»
}
'''
return '''
}
- private def CharSequence classBody(Module m) '''
- private «MODULE_INFO_CLASS_NAME»() {
- «IF m.imports.size != 0»
+ private def CharSequence classBody(Module m, String className) '''
+ private «className»() {
+ «IF !m.imports.empty || !m.submodules.empty»
«Set.importedName»<«YangModuleInfo.importedName»> set = new «HashSet.importedName»<>();
+ «ENDIF»
+ «IF !m.imports.empty»
«FOR imp : m.imports»
«val name = imp.moduleName»
«val rev = imp.revision»
«sorted.put(module.revision, module)»
«ENDIF»
«ENDFOR»
- set.add(«BindingGeneratorUtil.moduleNamespaceToPackageName(sorted.lastEntry().value)».«MODULE_INFO_CLASS_NAME».getInstance());
+ set.add(«getRootPackageName(sorted.lastEntry().value.QNameModule)».«MODULE_INFO_CLASS_NAME».getInstance());
«ELSE»
- set.add(«BindingGeneratorUtil.moduleNamespaceToPackageName(ctx.findModuleByName(name, rev))».«MODULE_INFO_CLASS_NAME».getInstance());
+ set.add(«getRootPackageName((ctx.findModuleByName(name, rev).QNameModule))».«MODULE_INFO_CLASS_NAME».getInstance());
«ENDIF»
«ENDFOR»
- importedModules = «ImmutableSet.importedName».copyOf(set);
- «ELSE»
+ «ENDIF»
+ «IF !m.submodules.empty»
+ «FOR submodule : m.submodules»
+ set.add(«getClassName(submodule.name)»Info.getInstance());
+ «ENDFOR»
+ «ENDIF»
+ «IF m.imports.empty && m.submodules.empty»
importedModules = «Collections.importedName».emptySet();
+ «ELSE»
+ importedModules = «ImmutableSet.importedName».copyOf(set);
«ENDIF»
+
«InputStream.importedName» stream = «MODULE_INFO_CLASS_NAME».class.getResourceAsStream(resourcePath);
if (stream == null) {
throw new IllegalStateException("Resource '" + resourcePath + "' is missing");
sb.append("]");
return sb.toString();
}
+
+ «generateSubInfo(m)»
+
'''
def getSourcePath() {
return "/" + module.moduleSourcePath.replace(java.io.File.separatorChar, '/')
}
- private def imports() '''
+ private def imports() '''
«IF !importMap.empty»
«FOR entry : importMap.entrySet»
- «IF entry.value != BindingGeneratorUtil.moduleNamespaceToPackageName(module)»
+ «IF entry.value != getRootPackageName(module.QNameModule)»
import «entry.value».«entry.key»;
«ENDIF»
«ENDFOR»
importMap.put(typeName, typePackageName);
}
if (type instanceof ParameterizedType) {
- val ParameterizedType paramType = (type as ParameterizedType)
- val Type[] params = paramType.getActualTypeArguments()
+ val Type[] params = type.getActualTypeArguments()
if (params != null) {
for (Type param : params) {
putTypeIntoImports(param);
final def StringBuilder addActualTypeParameters(StringBuilder builder, Type type) {
if (type instanceof ParameterizedType) {
- val ParameterizedType pType = (type as ParameterizedType)
- val Type[] pTypes = pType.getActualTypeArguments();
- builder.append("<");
+ val Type[] pTypes = type.getActualTypeArguments();
+ builder.append('<');
builder.append(getParameters(pTypes));
- builder.append(">");
+ builder.append('>');
}
return builder;
}
return builder.toString();
}
+ private def generateSubInfo(Module module) '''
+ «FOR submodule : module.submodules»
+ private static final class «getClassName(submodule.name)»Info implements «YangModuleInfo.importedName» {
+
+ private static final «YangModuleInfo.importedName» INSTANCE = new «getClassName(submodule.name)»Info();
+
+ private final «String.importedName» name = "«submodule.name»";
+ private final «String.importedName» namespace = "«submodule.namespace.toString»";
+ «val DateFormat df = new SimpleDateFormat("yyyy-MM-dd")»
+ private final «String.importedName» revision = "«df.format(submodule.revision)»";
+ private final «String.importedName» resourcePath = "/«submodule.moduleSourcePath.replace(java.io.File.separatorChar, '/')»";
+
+ private final «Set.importedName»<YangModuleInfo> importedModules;
+
+ public static «YangModuleInfo.importedName» getInstance() {
+ return INSTANCE;
+ }
+
+ «classBody(submodule, getClassName(submodule.name + "Info"))»
+ }
+ «ENDFOR»
+ '''
+
}