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;
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;
}