OSDN Git Service

Auto-save
[dvibrowser/dvi2epub.git] / src / jp / sourceforge / dvibrowser / dvi2epub / opt / DefaultOptionMapper.java
index e834c9d..9e1a281 100644 (file)
@@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import jp.sourceforge.dvibrowser.dvi2epub.cmd.CommandUtils;
+import jp.sourceforge.dvibrowser.dvi2epub.cmd.Option;
 import jp.sourceforge.dvibrowser.dvi2epub.cmd.OptionMapper;
 import jp.sourceforge.dvibrowser.dvi2epub.cmd.ParserState;
 
@@ -37,54 +38,21 @@ implements OptionMapper
                return new Object[] { value };
        }
        
-       public Annotation getAnnotationForOption(Method method, String optionName) {
+       public Option getOption(Method method) {
                Annotation[] annotations = method.getDeclaredAnnotations();
                for (Annotation a : annotations) {
-                       String shortName = null, longName = null;
+                       String shortName = CommandUtils.readValue(String.class, a, "shortName");
+                       String longName = CommandUtils.readValue(String.class, a, "longName");
+                       String description = CommandUtils.readValue(String.class, a, "description");
 
-                       try {
-                               Method m = a.getClass().getDeclaredMethod("shortName",
-                                               new Class<?>[] {});
-                               shortName = (String) m.invoke(a);
-                       } catch (NoSuchMethodException ex) {
-                               // Ignored.
-                       } catch (IllegalArgumentException e) {
-                               // Ignored.
-                       } catch (IllegalAccessException e) {
-                               // Ignored.
-                       } catch (InvocationTargetException e) {
-                               // Ignored.
-                       }
-                       try {
-                               Method m = a.getClass().getDeclaredMethod("longName",
-                                               new Class<?>[] {});
-                               longName = (String) m.invoke(a);
-                       } catch (NoSuchMethodException ex) {
-                               // Ignored.
-                       } catch (IllegalArgumentException e) {
-                               // Ignored.
-                       } catch (IllegalAccessException e) {
-                               // Ignored.
-                       } catch (InvocationTargetException e) {
-                               // Ignored.
-                       }
-
-                       if (nameHits(optionName, shortName, longName)) {
-                               return a;
+                       if (longName != null || shortName != null) {
+                               Option option = new Option(a, shortName, longName, description);
+                               return option;
                        }
                }
                return null;
        }
-       
-       private static boolean nameHits(String name, String shortName, String longName) {
-               if (shortName != null && shortName.equals(name)) {
-                       return true;
-               } else if (longName != null && longName.equals(name)) {
-                       return true;
-               }
-               return false;
-       }
-       
+
        public ParserState getState() {
                return state;
        }