使用Java Preon库上的单个类上的多个@ImportStatic注释



我想知道是否有一种方法可以使用多个@Importstatic注释对单个类使用Preon?

我尝试了:

@ImportStatic(classA.class)
@ImportStatic(classB.class)
// Also tried:
@ImportStatic(classA.class classB.class)
// And: 
@ImportStatic(classA.class,classB.class)

这些都不有效...

我有一个规范,要求我查看外部(父)类的枚举值(classa),如果它与特定值匹配,那么我还必须对一个父母的另一个对象进行枚举检查在继续阅读下一个字段之前,枚举值(classB)。

编辑:这是我第一次尝试解决方案,基本上是复制导入式的,并进行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;

它使用语法如下出现:

@ImportStatic({First.class,Second.class})

相关内容

  • 没有找到相关文章

最新更新