我想知道是否有办法为 Preon 的单个类使用多个 @ImportStatic 注释?
我试过了:
@ImportStatic(classA.class)
@ImportStatic(classB.class)
// Also tried:
@ImportStatic(classA.class classB.class)
// And:
@ImportStatic(classA.class,classB.class)
然而,这些都不是有效的......
我有一个规范,要求我查看外部(父)类的枚举值(classA),如果它与特定值匹配,那么我还必须对其他对象的枚举值之一进行枚举检查( classB) 在继续阅读下一个字段之前。
编辑:这是我第一次尝试解决方案,基本上是复制 ImportStatic 并制作 ImportStatic2 注释......必须看看它的效果如何。
diff --git a/preon-binding/src/main/java/org/codehaus/preon/el/ImportSupportingObjectResolverContext.java b/preon-binding/src/main/java/org/codehaus/preon/el/ImportSupportingObjectResolverContext.java
index b737719..8f4946c 100644
--- a/preon-binding/src/main/java/org/codehaus/preon/el/ImportSupportingObjectResolverContext.java
+++ b/preon-binding/src/main/java/org/codehaus/preon/el/ImportSupportingObjectResolverContext.java
@@ -89,14 +89,23 @@ public class ImportSupportingObjectResolverContext implements
public static ObjectResolverContext decorate(ObjectResolverContext context,
Class<?> type) {
- if (type.isAnnotationPresent(ImportStatic.class)) {
+ if (type.isAnnotationPresent(ImportStatic.class) || type.isAnnotationPresent(ImportStatic2.class)) {
ImportSupportingObjectResolverContext replacement = new ImportSupportingObjectResolverContext();
Map<String, Reference<Resolver>> references = new HashMap<String, Reference<Resolver>>();
+ if (type.isAnnotationPresent(ImportStatic.class)) {
for (Class<?> imported : type.getAnnotation(ImportStatic.class)
.value()) {
references.put(imported.getSimpleName(), new ClassReference(
imported, replacement));
}
+ }
+ if (type.isAnnotationPresent(ImportStatic2.class)) {
+ for (Class<?> imported : type.getAnnotation(ImportStatic2.class)
+ .value()) {
+ references.put(imported.getSimpleName(), new ClassReference(
+ imported, replacement));
+ }
+ }
replacement.context = context;
replacement.references = references;
return replacement;