FullyQualifiedName moduleFQN,
List<Field> moduleFields) {
JavaFileInputBuilder b = new JavaFileInputBuilder();
+
+ b.addImportFQN(new FullyQualifiedName(Module.class));
+ b.addImportFQN(new FullyQualifiedName(ModuleIdentifier.class));
+
Annotation moduleQNameAnnotation = Annotation.createModuleQNameANnotation(yangModuleQName);
b.addClassAnnotation(moduleQNameAnnotation);
));
b.addToBody(format("\n"+
- "public %s handleChangedClass(%s dependencyResolver, %s old, %s bundleContext) throws Exception {\n"+
- "return handleChangedClass(old);\n"+
+ "public %s handleChangedClass(%s dependencyResolver, %s old, %s bundleContext) throws Exception {\n" +
+ // "// @Deprecated return handleChangedClass(old);\n" +
+ "String instanceName = old.getModule().getIdentifier().getInstanceName();\n" +
+ "%1$s newModule = new %1$s(new ModuleIdentifier(NAME, instanceName), dependencyResolver);\n" +
+ "Module oldModule = old.getModule();\n" +
+ "Class<? extends Module> oldModuleClass = oldModule.getClass();\n" +
+ genCodeToCopyAttributes(moduleFields) +
+ "return newModule;\n" +
"}\n", moduleFQN, DependencyResolver.class.getCanonicalName(), DynamicMBeanWithInstance.class.getCanonicalName(), BUNDLE_CONTEXT));
b.addToBody(format("\n@Deprecated\n"+
"throw new UnsupportedOperationException(\"Class reloading is not supported\");\n"+
"}\n", moduleFQN, DynamicMBeanWithInstance.class.getCanonicalName()));
- // TODO The generic specifier in HashSet<> isn't necessary, but the Eclipse AST parser used in the unit tests doesn't support this
b.addToBody(format("\n"+
"@Override\n"+
"public java.util.Set<%s> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory, %s bundleContext) {\n"+
- "return new java.util.HashSet<%1$s>();\n"+
+ "return new java.util.HashSet<>();\n"+
"}\n", moduleFQN, BUNDLE_CONTEXT));
return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
}
+ private String genCodeToCopyAttributes(List<Field> moduleFields) {
+ StringBuilder sb = new StringBuilder("\n");
+ for (Field field : moduleFields) {
+ sb.append(format("newModule.set%1$s( (%2$s) oldModuleClass.getMethod(\"get%1$s\").invoke(oldModule));\n", field.getName(), field.getType()));
+ }
+ sb.append('\n');
+ return sb.toString();
+ }
+
private static String getCreateModule(FullyQualifiedName moduleFQN, List<Field> moduleFields) {
String result = "\n"+
"@Override\n"+
String result = "static {\n";
if (!providedServices.isEmpty()) {
- // TODO The generic specifier in HashSet<> isn't necessary, but the Eclipse AST parser used in the unit tests doesn't support this
- result += format("java.util.Set<%1$s> serviceIfcs2 = new java.util.HashSet<%1$s>();\n", generic);
+ result += format("java.util.Set<%1$s> serviceIfcs2 = new java.util.HashSet<>();\n", generic);
for(FullyQualifiedName fqn: providedServices) {
result += format("serviceIfcs2.add(%s.class);\n", fqn);