X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2Fftl%2FRuntimeRegistratorFtlTemplate.java;fp=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2Fftl%2FRuntimeRegistratorFtlTemplate.java;h=dd2cd8cc46306e919a7ac5d55762036e7477033f;hp=27fb2bcba153f953ebd0559fc8a9ee377b5e7ca8;hb=8cc33e526b0f9ad956dcc96e57cff02679d643b3;hpb=2cf4749c41aa32c6b77064fc1ae0e231adc4a5f4 diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/RuntimeRegistratorFtlTemplate.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/RuntimeRegistratorFtlTemplate.java index 27fb2bcba1..dd2cd8cc46 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/RuntimeRegistratorFtlTemplate.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/RuntimeRegistratorFtlTemplate.java @@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; import com.google.common.collect.Lists; import java.io.Closeable; import java.util.ArrayList; @@ -25,11 +26,11 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import javax.lang.model.element.Modifier; import org.opendaylight.controller.config.api.runtime.HierarchicalRuntimeBeanRegistration; import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator; import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry; import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation; -import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation.Parameter; import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field; import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition; import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper; @@ -40,7 +41,7 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { String name, List fields, List methods) { // TODO header super(null, runtimeBeanEntry.getPackageName(), name, Collections - . emptyList(), Collections.singletonList(Closeable.class + .emptyList(), Collections.singletonList(Closeable.class .getCanonicalName()), fields, methods); } @@ -85,7 +86,7 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { String registratorName = getJavaNameOfRuntimeRegistrator(rootRB); List methods = new ArrayList<>(); Field rootRuntimeBeanRegistratorField = new Field( - Lists.newArrayList("final"), + Collections.singletonList(Modifier.FINAL), RootRuntimeBeanRegistrator.class.getName(), "rootRuntimeBeanRegistrator"); List constructorParameters = Lists @@ -95,8 +96,8 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { registratorName, constructorParameters, constructorBody); methods.add(constructor); - LinkedHashMap RuntimeRegistratorFtlTemplates = createRegistrationHierarchy( - rootRB, Collections. emptySet()); + LinkedHashMap RuntimeRegistratorFtlTemplates = + createRegistrationHierarchy(rootRB, Collections.emptySet()); RuntimeRegistratorFtlTemplate rootFtlFile = RuntimeRegistratorFtlTemplates .values().iterator().next(); @@ -127,7 +128,7 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { // TODO add header GeneralClassTemplate registrator = new GeneralClassTemplate(null, rootRB.getPackageName(), registratorName, - Collections. emptyList(), Collections.singletonList(Closeable.class + Collections.emptyList(), Collections.singletonList(Closeable.class .getCanonicalName()), constructorParameters, methods); checkState(!RuntimeRegistratorFtlTemplates.containsKey(registrator @@ -140,7 +141,7 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { } private static Field hierachicalRegistration = new Field( - Lists.newArrayList("final"), + Collections.singletonList(Modifier.FINAL), HierarchicalRuntimeBeanRegistration.class.getCanonicalName(), "registration"); @@ -172,7 +173,7 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { Set currentOccupiedKeys = new HashSet<>(occupiedKeys); currentOccupiedKeys.add(parent.getJavaNamePrefix()); - Field registratorsMapField = new Field(Collections.singletonList("final"), + Field registratorsMapField = new Field(Collections.singletonList(Modifier.FINAL), TypeHelper.getGenericType(Map.class, String.class, AtomicInteger.class), "unkeyedMap", "new " + TypeHelper.getGenericType(HashMap.class, @@ -209,8 +210,9 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { "String key = \"%s\"; //TODO: check for conflicts\n", key)); - if (child.getKeyJavaName().isPresent()) { - value = "bean.get" + child.getKeyJavaName().get() + "()"; + Optional childKeyJavaName = child.getKeyJavaName(); + if (childKeyJavaName.isPresent()) { + value = "bean.get" + childKeyJavaName.get() + "()"; value = "String.valueOf(" + value + ")"; } else { body.append("java.util.concurrent.atomic.AtomicInteger counter = unkeyedMap.get(key);\n" @@ -227,13 +229,13 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { body.append(format("return new %s(r);", childRegistrator.getFullyQualifiedName())); - Field param = new Field(Lists.newArrayList("final"), + Field param = new Field(Collections.singletonList(Modifier.FINAL), child.getJavaNameOfRuntimeMXBean(), "bean"); MethodDefinition register = new MethodDefinition( - Collections.singletonList("synchronized"), + Collections.singletonList(Modifier.SYNCHRONIZED), childRegistrator.getFullyQualifiedName(), "register", - Collections.singletonList(param), Collections. emptyList(), - Collections. emptyList(), body.toString()); + Collections.singletonList(param), Collections.emptyList(), + Collections.emptyList(), body.toString()); methods.add(register); } @@ -274,10 +276,10 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate { // Arrays.asList(IOException.class.getCanonicalName()), // Collections. emptyList(), body); List annotations = Lists.newArrayList(new Annotation( - "Override", Collections. emptyList())); - return new MethodDefinition(Collections. emptyList(), "void", - "close", Collections. emptyList(), - Collections. emptyList(), annotations, body); + "Override", Collections.emptyList())); + return new MethodDefinition(Collections.emptyList(), "void", + "close", Collections.emptyList(), + Collections.emptyList(), annotations, body); } @VisibleForTesting