/*
* This is all ugly as hell, and pretty slow, but it works :)
*/
String ann = Regex.matchFirst(java, "\\@" + this.annotationName + "\\s*\\([^\\)]+\\)", false);
DynMap mp = new DynMap();
if (ann == null) {
return mp;
}
ann = ann.replaceFirst("\\@" + this.annotationName + "\\s*\\(", "");
ann = ann.replaceAll("\\)$", "");
String[] tokens = ann.split("\\s*\\=\\s*");
String key = null;
String value = null;
for (String t : tokens) {
if (key == null) {
key = t;
continue;
}
//else parse the value.
String nextKey = Regex.matchFirst(t, "[\\n\\r]+\\s*[^\\s]+\\s*$", false);
value = t.replaceFirst("[\\n\\r]+\\s*[^\\s]+\\s*$", "").trim();
boolean isList = value.startsWith("{");
value = StringHelper.trim(value, ",");
value = StringHelper.trim(value, "{");
value = StringHelper.trim(value, "}");
value = StringHelper.trim(value.trim(), "\"");
if (isList) {
List<String> values = new ArrayList<String>();
for (String v : value.split(",")) {
values.add(StringHelper.trim(v.trim(), "\""));
}
mp.put(key.trim(), values);
} else {
mp.put(key.trim(), value);
}
if (nextKey != null) {
key = nextKey;
}
}
System.out.println(mp.toJSONString());
return mp;
}