This is an automated email from the ASF dual-hosted git repository. kexianjun pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push: new 36c75d7 extract 2 methods: (#3453) 36c75d7 is described below commit 36c75d7ce4895ec0aa856ae6ddaeda7de9b3a402 Author: wanghbxxxx <wanghbx...@gmail.com> AuthorDate: Tue Feb 12 15:52:38 2019 +0800 extract 2 methods: (#3453) isSetter: test if a method is a setter getSetterProperty: get property for setter, for instance setVersion return "version" --- .../dubbo/common/extension/ExtensionLoader.java | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java index 1b36047..36c7707 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java @@ -544,9 +544,7 @@ public class ExtensionLoader<T> { try { if (objectFactory != null) { for (Method method : instance.getClass().getMethods()) { - if (method.getName().startsWith("set") - && method.getParameterTypes().length == 1 - && Modifier.isPublic(method.getModifiers())) { + if (isSetter(method)) { /** * Check {@link DisableInject} to see if we need auto injection for this property */ @@ -558,7 +556,7 @@ public class ExtensionLoader<T> { continue; } try { - String property = method.getName().length() > 3 ? method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4) : ""; + String property = getSetterProperty(method); Object object = objectFactory.getExtension(pt, property); if (object != null) { method.invoke(instance, object); @@ -576,6 +574,30 @@ public class ExtensionLoader<T> { return instance; } + /** + * get properties name for setter, for instance: setVersion, return "version" + * <p> + * return "", if setter name with length less than 3 + */ + private String getSetterProperty(Method method) { + return method.getName().length() > 3 ? method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4) : ""; + } + + /** + * return true if and only if: + * <p> + * 1, public + * <p> + * 2, name starts with "set" + * <p> + * 3, only has one parameter + */ + private boolean isSetter(Method method) { + return method.getName().startsWith("set") + && method.getParameterTypes().length == 1 + && Modifier.isPublic(method.getModifiers()); + } + private Class<?> getExtensionClass(String name) { if (type == null) { throw new IllegalArgumentException("Extension type == null");