FELIX-2908 - Use same mechanism to get single annotation values as for multiple annotation values
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1132949 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/generator/changelog.txt b/scrplugin/generator/changelog.txt
index 1c2f6d0..0ded2d5 100644
--- a/scrplugin/generator/changelog.txt
+++ b/scrplugin/generator/changelog.txt
@@ -12,6 +12,7 @@
** Improvement
* [FELIX-2492] - scr plugin: using src annotations causes NoClassDefFoundError and other errors
* [FELIX-2939] - Maven SCR Plugin is not (marked as) thread-safe for parallel builds
+ * [FELIX-2908] - Use same mechanism to get single annotation values as for multiple annotation values
Changes from 1.0.0 to 1.1.0
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
index 671c616..61eef89 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
@@ -40,36 +40,36 @@
* @param clazz The annotation class.
* @return The boolean value.
*/
- public static boolean getBooleanValue(Annotation annotation, String name, final Class<?> clazz) {
- final Object obj = annotation.getNamedParameter(name);
- if ( obj != null ) {
- return Boolean.valueOf(obj.toString());
+ public static boolean getBooleanValue(final Annotation annotation, final JavaClassDescription desc, final String name, final Class<?> clazz) {
+ final String[] sValues = getAnnotationValues(annotation, name, desc);
+ if ( sValues != null )
+ {
+ return Boolean.valueOf(sValues[0]);
}
- try {
+ try
+ {
return (Boolean) clazz.getMethod(name).getDefaultValue();
- } catch( NoSuchMethodException mnfe) {
+ }
+ catch( final NoSuchMethodException mnfe)
+ {
// we ignore this
return true;
}
}
- public static int getIntValue(Annotation annotation, String name, final Class<?> clazz) {
- final Object obj = annotation.getNamedParameter(name);
- if ( obj != null ) {
- if ( obj instanceof Number ) {
- return ((Number)obj).intValue();
- }
- final String value = obj.toString();
- if ( value.equals("Integer.MAX_VALUE") ) {
- return Integer.MAX_VALUE;
- } else if ( value.equals("Integer.MIN_VALUE") ) {
- return Integer.MIN_VALUE;
- }
- return Integer.valueOf(value);
+ public static int getIntValue(final Annotation annotation, final JavaClassDescription desc, final String name, final Class<?> clazz) {
+ final String[] sValues = getAnnotationValues(annotation, name, desc);
+ if ( sValues != null )
+ {
+ return Integer.valueOf(sValues[0]);
+
}
- try {
+ try
+ {
return (Integer) clazz.getMethod(name).getDefaultValue();
- } catch( NoSuchMethodException mnfe) {
+ }
+ catch(final NoSuchMethodException mnfe)
+ {
// we ignore this
return 0;
}
@@ -382,11 +382,11 @@
return getEnumValue(annotation, name, enumClass, clazz, true);
}
+ @SuppressWarnings("unchecked")
public static String[] getAnnotationValues(final Annotation annotation, final String name, final JavaClassDescription desc)
throws IllegalArgumentException
{
-
- EvaluatingVisitor evaluatingVisitor = new EvaluatingVisitor() {
+ final EvaluatingVisitor evaluatingVisitor = new EvaluatingVisitor() {
public Object visitAnnotationFieldRef( AnnotationFieldRef fieldRef ) {
// during prescan of AnnotationTagProviderManager#hasScrPluginAnnotation this method is called without desc attribute
@@ -438,9 +438,9 @@
}
};
- @SuppressWarnings("unchecked")
final List<Object> valueList = evaluatingVisitor.getListValue(annotation, name);
- if (valueList==null) {
+ if (valueList == null || valueList.size() == 0)
+ {
return null;
}
String[] values = new String[valueList.size()];