X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdynamicmbean%2FAnnotationsHelper.java;h=f9548ae08e4d4e9685569ccb89f9c8a89d6599e0;hp=fba9844dbfaf9d7fc8cef7ed54e223c73c7431b2;hb=2b78ca93f44c372fd72927db6cbd65f5d8387b49;hpb=3927509ec3ecfa32a51b725d2b7155d425f5b877 diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java index fba9844dbf..f9548ae08e 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 Cisco Systems, Inc. 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, @@ -16,69 +16,67 @@ import java.util.List; import java.util.Set; import org.opendaylight.controller.config.api.annotations.Description; -public class AnnotationsHelper { +public final class AnnotationsHelper { private AnnotationsHelper() { } /** * Look for annotation specified by annotationType on method. First observe - * method's class, then its super classes, then all provided interfaces. - * Used for finding @Description and @RequireInterface + * method's class, then its super classes, then all provided interfaces. Used + * for finding @Description and @RequireInterface * * @param * generic type of annotation * @return list of found annotations */ - static List findMethodAnnotationInSuperClassesAndIfcs( - final Method setter, final Class annotationType, - final Set> inspectedInterfaces) { + static List findMethodAnnotationInSuperClassesAndIfcs(final Method setter, + final Class annotationType, final Set> inspectedInterfaces) { Builder result = ImmutableSet.builder(); Class inspectedClass = setter.getDeclaringClass(); do { try { - Method foundSetter = inspectedClass.getMethod(setter.getName(), - setter.getParameterTypes()); + Method foundSetter = inspectedClass.getMethod(setter.getName(), setter.getParameterTypes()); T annotation = foundSetter.getAnnotation(annotationType); if (annotation != null) { result.add(annotation); } // we need to go deeper inspectedClass = inspectedClass.getSuperclass(); - } catch (NoSuchMethodException e) { - inspectedClass = Object.class; // no need to go further + // no need to go further + } catch (final NoSuchMethodException e) { + inspectedClass = Object.class; } } while (!inspectedClass.equals(Object.class)); // inspect interfaces for (Class ifc : inspectedInterfaces) { - if (ifc.isInterface() == false) { + if (!ifc.isInterface()) { throw new IllegalArgumentException(ifc + " is not an interface"); } try { - Method foundSetter = ifc.getMethod(setter.getName(), - setter.getParameterTypes()); + Method foundSetter = ifc.getMethod(setter.getName(), setter.getParameterTypes()); T annotation = foundSetter.getAnnotation(annotationType); if (annotation != null) { result.add(annotation); } - } catch (NoSuchMethodException e) { - + } catch (final NoSuchMethodException e) { + break; // FIXME: is this ok? } } return new ArrayList<>(result.build()); } /** - * Look for annotation specified by annotationType on type. First observe - * class clazz, then its super classes, then all exported interfaces with - * their super types. Used for finding @Description of modules. + * Look for annotation specified by annotationType on type. First observe class + * clazz, then its super classes, then all exported interfaces with their super + * types. Used for finding @Description of modules. * * @return list of found annotations */ - static List findClassAnnotationInSuperClassesAndIfcs( - final Class clazz, final Class annotationType, final Set> interfaces) { - List result = new ArrayList(); + static List findClassAnnotationInSuperClassesAndIfcs(final Class clazz, + final Class annotationType, final Set> interfaces) { + List result = new ArrayList<>(); Class declaringClass = clazz; do { T annotation = declaringClass.getAnnotation(annotationType); @@ -86,10 +84,10 @@ public class AnnotationsHelper { result.add(annotation); } declaringClass = declaringClass.getSuperclass(); - } while (declaringClass.equals(Object.class) == false); + } while (!declaringClass.equals(Object.class)); // inspect interfaces for (Class ifc : interfaces) { - if (ifc.isInterface() == false) { + if (!ifc.isInterface()) { throw new IllegalArgumentException(ifc + " is not an interface"); } T annotation = ifc.getAnnotation(annotationType); @@ -101,6 +99,8 @@ public class AnnotationsHelper { } /** + * Lists aggregate descriptions. + * * @return empty string if no annotation is found, or list of descriptions * separated by newline */