0

I'm wondering if there is a way to use multiple @ImportStatic annotations for a single class with Preon?

I tried:

@ImportStatic(classA.class)
@ImportStatic(classB.class)

// Also tried:

@ImportStatic(classA.class classB.class)

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

None of these are valid however...

I have a specification that asks me to look at the enum value (classA) of the outer (parent) class, if it matches a specific value, then I must also do an enum check on on one of the parents other object's enum values (classB) before proceeding to read the next field.

EDIT: Here's my first attempt at a solution, basically copy ImportStatic and make an ImportStatic2 annotation... Have to see how well it works.

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;
ged
  • 33
  • 8

1 Answers1

0

It appears using the syntax as follows works:

@ImportStatic({First.class,Second.class})
ged
  • 33
  • 8