aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1782620 - in /aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model: Argument.java Bean.java Property.java
Date Sat, 11 Feb 2017 16:41:52 GMT
Author: alien11689
Date: Sat Feb 11 16:41:52 2017
New Revision: 1782620

URL: http://svn.apache.org/viewvc?rev=1782620&view=rev
Log:
[REFACTOR] Clean code duplication in BMP

Modified:
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java?rev=1782620&r1=1782619&r2=1782620&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java
Sat Feb 11 16:41:52 2017
@@ -30,12 +30,20 @@ import static org.apache.aries.blueprint
 import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findValue;
 import static org.apache.aries.blueprint.plugin.model.NamingHelper.getBeanName;
 
-class Argument implements XmlWriter{
+class Argument implements XmlWriter {
     private final String ref;
     private final String value;
 
     Argument(BlueprintRegistry blueprintRegistry, Class<?> argumentClass, Annotation[]
annotations) {
-        String value = findValue(annotations);
+        this.value = findValue(annotations);
+        if (value != null) {
+            ref = null;
+            return;
+        }
+        this.ref = findRef(blueprintRegistry, argumentClass, annotations);
+    }
+
+    private String findRef(BlueprintRegistry blueprintRegistry, Class<?> argumentClass,
Annotation[] annotations) {
         String ref = findName(annotations);
 
         for (CustomDependencyAnnotationHandler customDependencyAnnotationHandler : Handlers.CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS)
{
@@ -49,22 +57,16 @@ class Argument implements XmlWriter{
             }
         }
 
-        if (ref == null && value == null) {
+        if (ref == null) {
             BeanTemplate template = new BeanTemplate(argumentClass, annotations);
             BeanRef bean = blueprintRegistry.getMatching(template);
             if (bean != null) {
                 ref = bean.id;
             } else {
-                String name = findName(annotations);
-                if (name != null) {
-                    ref = name;
-                } else {
-                    ref = getBeanName(argumentClass);
-                }
+                ref = getBeanName(argumentClass);
             }
         }
-        this.value = value;
-        this.ref = ref;
+        return ref;
     }
 
     String getRef() {

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1782620&r1=1782619&r2=1782620&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
Sat Feb 11 16:41:52 2017
@@ -22,7 +22,6 @@ import org.apache.aries.blueprint.plugin
 import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.BeanEnricher;
 import org.apache.aries.blueprint.plugin.spi.ContextEnricher;
-import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler;
 import org.apache.aries.blueprint.plugin.spi.InjectLikeHandler;
 import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler;
@@ -42,9 +41,7 @@ import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findName;
 import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findSingleton;
-import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findValue;
 import static org.apache.aries.blueprint.plugin.model.NamingHelper.getBeanName;
 
 class Bean implements BeanEnricher, XmlWriter {

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java?rev=1782620&r1=1782619&r2=1782620&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
Sat Feb 11 16:41:52 2017
@@ -53,15 +53,9 @@ class Property implements Comparable<Pro
                 return new Property(field.getName(), null, value, true);
             }
             String ref = getForcedRefName(field);
-            for (CustomDependencyAnnotationHandler customDependencyAnnotationHandler : Handlers.CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS)
{
-                Annotation annotation = (Annotation) AnnotationHelper.findAnnotation(field.getAnnotations(),
customDependencyAnnotationHandler.getAnnotation());
-                if (annotation != null) {
-                    String generatedRef = customDependencyAnnotationHandler.handleDependencyAnnotation(field,
ref, blueprintRegistry);
-                    if (generatedRef != null) {
-                        ref = generatedRef;
-                        break;
-                    }
-                }
+            String refFromCustomeDependencyHandler = getRefFromCustomDependencyHandlers(blueprintRegistry,
field, ref);
+            if (refFromCustomeDependencyHandler != null) {
+                ref = refFromCustomeDependencyHandler;
             }
             if (ref != null) {
                 return new Property(field.getName(), ref, null, true);
@@ -75,6 +69,19 @@ class Property implements Comparable<Pro
         }
     }
 
+    private static String getRefFromCustomDependencyHandlers(BlueprintRegistry blueprintRegistry,
AnnotatedElement annotatedElement, String ref) {
+        for (CustomDependencyAnnotationHandler customDependencyAnnotationHandler : Handlers.CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS)
{
+            Annotation annotation = (Annotation) AnnotationHelper.findAnnotation(annotatedElement.getAnnotations(),
customDependencyAnnotationHandler.getAnnotation());
+            if (annotation != null) {
+                String generatedRef = customDependencyAnnotationHandler.handleDependencyAnnotation(annotatedElement,
ref, blueprintRegistry);
+                if (generatedRef != null) {
+                    return generatedRef;
+                }
+            }
+        }
+        return null;
+    }
+
     static Property create(BlueprintRegistry blueprintRegistry, Method method) {
         String propertyName = resolveProperty(method);
         if (propertyName == null) {
@@ -91,16 +98,11 @@ class Property implements Comparable<Pro
             if (ref == null) {
                 ref = findName(method.getParameterAnnotations()[0]);
             }
-            for (CustomDependencyAnnotationHandler customDependencyAnnotationHandler : Handlers.CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS)
{
-                Annotation annotation = (Annotation) AnnotationHelper.findAnnotation(method.getAnnotations(),
customDependencyAnnotationHandler.getAnnotation());
-                if (annotation != null) {
-                    String generatedRef = customDependencyAnnotationHandler.handleDependencyAnnotation(method,
ref, blueprintRegistry);
-                    if (generatedRef != null) {
-                        ref = generatedRef;
-                        break;
-                    }
-                }
+            String refFromCustomeDependencyHandler = getRefFromCustomDependencyHandlers(blueprintRegistry,
method, ref);
+            if (refFromCustomeDependencyHandler != null) {
+                ref = refFromCustomeDependencyHandler;
             }
+
             if (ref != null) {
                 return new Property(propertyName, ref, null, false);
             }



Mime
View raw message