@@ -544,9 +544,7 @@ private T injectExtension(T instance) {
544544 try {
545545 if (objectFactory != null ) {
546546 for (Method method : instance .getClass ().getMethods ()) {
547- if (method .getName ().startsWith ("set" )
548- && method .getParameterTypes ().length == 1
549- && Modifier .isPublic (method .getModifiers ())) {
547+ if (isSetter (method )) {
550548 /**
551549 * Check {@link DisableInject} to see if we need auto injection for this property
552550 */
@@ -558,7 +556,7 @@ private T injectExtension(T instance) {
558556 continue ;
559557 }
560558 try {
561- String property = method . getName (). length () > 3 ? method . getName (). substring ( 3 , 4 ). toLowerCase () + method . getName (). substring ( 4 ) : "" ;
559+ String property = getSetterProperty ( method ) ;
562560 Object object = objectFactory .getExtension (pt , property );
563561 if (object != null ) {
564562 method .invoke (instance , object );
@@ -576,6 +574,30 @@ private T injectExtension(T instance) {
576574 return instance ;
577575 }
578576
577+ /**
578+ * get properties name for setter, for instance: setVersion, return "version"
579+ * <p>
580+ * return "", if setter name with length less than 3
581+ */
582+ private String getSetterProperty (Method method ) {
583+ return method .getName ().length () > 3 ? method .getName ().substring (3 , 4 ).toLowerCase () + method .getName ().substring (4 ) : "" ;
584+ }
585+
586+ /**
587+ * return true if and only if:
588+ * <p>
589+ * 1, public
590+ * <p>
591+ * 2, name starts with "set"
592+ * <p>
593+ * 3, only has one parameter
594+ */
595+ private boolean isSetter (Method method ) {
596+ return method .getName ().startsWith ("set" )
597+ && method .getParameterTypes ().length == 1
598+ && Modifier .isPublic (method .getModifiers ());
599+ }
600+
579601 private Class <?> getExtensionClass (String name ) {
580602 if (type == null ) {
581603 throw new IllegalArgumentException ("Extension type == null" );
0 commit comments