fix annotation processing with array values

This commit is contained in:
Sebastian Sdorra
2015-02-06 22:38:35 +01:00
parent b07b11a73d
commit ed76f14aa4
3 changed files with 173 additions and 1 deletions

View File

@@ -61,7 +61,9 @@ import java.io.InputStream;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -311,6 +313,31 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
return doc;
}
/**
* Method description
*
*
* @param obj
*
* @return
*/
private String prepareArrayElement(Object obj)
{
String v = obj.toString();
if (v.startsWith("\""))
{
v = v.substring(1);
if (v.endsWith(""))
{
v = v.substring(0, v.length() - 1);
}
}
return v;
}
/**
* Method description
*
@@ -510,7 +537,7 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
? extends AnnotationValue> entry : am.getElementValues().entrySet())
{
attributes.put(entry.getKey().getSimpleName().toString(),
entry.getValue().getValue().toString());
getValue(entry.getValue()));
}
}
}
@@ -518,6 +545,45 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
return attributes;
}
/**
* Method description
*
*
* @param v
*
* @return
*/
private String getValue(AnnotationValue v)
{
String value;
Object object = v.getValue();
if (object instanceof Iterable)
{
Iterator<?> it = ((Iterable<?>) object).iterator();
StringBuilder buffer = new StringBuilder();
while (it.hasNext())
{
buffer.append(prepareArrayElement(it.next()));
if (it.hasNext())
{
buffer.append(",");
}
}
value = buffer.toString();
}
else
{
value = object.toString();
}
return value;
}
//~--- inner classes --------------------------------------------------------
/**