diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-06-19 17:41:39 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-06-19 17:41:47 +0200 |
commit | 4488da6577653a2912f54b8692240791acee6f87 (patch) | |
tree | 696bc42f687ddcc003a441409ebd7ec923627ef8 /sonar-deprecated/src/main | |
parent | 861565e0491c53ffff1d8dbe5b28de9cf496fa90 (diff) | |
download | sonarqube-4488da6577653a2912f54b8692240791acee6f87.tar.gz sonarqube-4488da6577653a2912f54b8692240791acee6f87.zip |
SONAR-4409 Support arrays returned by methods annotated with @DependsUpon or @DependedUpon
Diffstat (limited to 'sonar-deprecated/src/main')
-rw-r--r-- | sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java index 39c3eb27252..bc88a95116d 100644 --- a/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java @@ -32,6 +32,7 @@ import org.sonar.api.utils.AnnotationUtils; import org.sonar.api.utils.dag.DirectAcyclicGraph; import java.lang.annotation.Annotation; +import java.lang.reflect.Array; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; @@ -45,7 +46,7 @@ import java.util.List; @Deprecated public class BatchExtensionDictionnary { - private ComponentContainer componentContainer; + private final ComponentContainer componentContainer; public BatchExtensionDictionnary(ComponentContainer componentContainer) { this.componentContainer = componentContainer; @@ -204,13 +205,17 @@ public class BatchExtensionDictionnary { try { Object result = method.invoke(extension); if (result != null) { - // TODO add arrays/collections of objects/classes if (result instanceof Class<?>) { results.addAll(componentContainer.getComponentsByType((Class<?>) result)); } else if (result instanceof Collection<?>) { results.addAll((Collection<?>) result); + } else if (result.getClass().isArray()) { + for (int i = 0; i < Array.getLength(result); i++) { + results.add(Array.get(result, i)); + } + } else { results.add(result); } @@ -222,10 +227,10 @@ public class BatchExtensionDictionnary { private void checkAnnotatedMethod(Method method) { if (!Modifier.isPublic(method.getModifiers())) { - throw new IllegalStateException("Annotated method must be public :" + method); + throw new IllegalStateException("Annotated method must be public:" + method); } if (method.getParameterTypes().length > 0) { - throw new IllegalStateException("Annotated method must not have parameters :" + method); + throw new IllegalStateException("Annotated method must not have parameters:" + method); } } } |