|
22 | 22 |
|
23 | 23 | import java.lang.annotation.Annotation; |
24 | 24 | import java.util.ArrayList; |
| 25 | +import java.util.Arrays; |
25 | 26 | import java.util.HashMap; |
| 27 | +import java.util.HashSet; |
26 | 28 | import java.util.List; |
27 | 29 | import java.util.Map; |
28 | 30 | import java.util.Set; |
|
64 | 66 | import com.sun.codemodel.JExpr; |
65 | 67 | import com.sun.codemodel.JExpression; |
66 | 68 | import com.sun.codemodel.JFieldRef; |
| 69 | +import com.sun.codemodel.JInvocation; |
67 | 70 | import com.sun.codemodel.JMethod; |
68 | 71 | import com.sun.codemodel.JVar; |
69 | 72 |
|
@@ -247,14 +250,28 @@ private JExpression createFieldMethod(SharedPrefHolder holder, ExecutableElement |
247 | 250 | JExpression defaultValueExpr; |
248 | 251 |
|
249 | 252 | Object value = null; |
250 | | - if (annotation != null && method.getAnnotation(DefaultStringSet.class) == null) { |
| 253 | + if (annotation != null) { |
251 | 254 | value = annotationHelper.extractAnnotationParameter(method, annotationClass.getName(), "value"); |
| 255 | + } |
| 256 | + |
| 257 | + if (annotation != null && method.getAnnotation(DefaultStringSet.class) == null) { |
252 | 258 | defaultValueExpr = codeModelHelper.litObject(value); |
253 | 259 | } else if (method.getAnnotation(DefaultRes.class) != null) { |
254 | 260 | defaultValueExpr = extractResValue(holder, method, resType); |
255 | 261 | annotationClass = DefaultRes.class; |
256 | 262 | } else if (method.getAnnotation(DefaultStringSet.class) != null) { |
257 | | - defaultValueExpr = newEmptyStringHashSet(); |
| 263 | + if (value != null) { |
| 264 | + Set<String> arrayValues = new HashSet<>(Arrays.asList((String[]) value)); |
| 265 | + value = arrayValues; |
| 266 | + |
| 267 | + JInvocation arrayAsList = getClasses().ARRAYS.staticInvoke("asList"); |
| 268 | + for (String arrayValue : arrayValues) { |
| 269 | + arrayAsList.arg(lit(arrayValue)); |
| 270 | + } |
| 271 | + defaultValueExpr = JExpr._new(getClasses().HASH_SET.narrow(getClasses().STRING)).arg(arrayAsList); |
| 272 | + } else { |
| 273 | + defaultValueExpr = newEmptyStringHashSet(); |
| 274 | + } |
258 | 275 | annotationClass = DefaultStringSet.class; |
259 | 276 | } else { |
260 | 277 | defaultValueExpr = defaultValue != null ? codeModelHelper.litObject(defaultValue) : newEmptyStringHashSet(); |
|
0 commit comments