1
2
3
4
5
6
7
8
9
10
11
12 package org.hyphenType.documentation;
13
14 import java.lang.reflect.Method;
15 import java.util.ArrayList;
16 import java.util.ListResourceBundle;
17
18 import org.hyphenType.datastructure.annotations.Option;
19 import org.hyphenType.datastructure.annotations.SimpleArgument;
20
21
22
23
24 public class OptionListResourceBundle extends ListResourceBundle {
25
26 public static final String PROPERTIES_PREFIX = OptionListResourceBundle.class.getPackage().getName();
27
28 private Object[][] map;
29
30 @SuppressWarnings("unchecked")
31 public OptionListResourceBundle(Class optionsInterface) {
32
33 ArrayList<String> keys = new ArrayList<String>();
34 ArrayList<String> values = new ArrayList<String>();
35
36 for (Method method : optionsInterface.getMethods()) {
37 if (method.isAnnotationPresent(Option.class)) {
38 keys.add(PROPERTIES_PREFIX + method.getName());
39 values.add(((Option) method.getAnnotation(Option.class)).description());
40 } else if (method.isAnnotationPresent(SimpleArgument.class)) {
41 keys.add(PROPERTIES_PREFIX + method.getName());
42 values.add(((SimpleArgument) method.getAnnotation(SimpleArgument.class)).description());
43 }
44 }
45
46 map = new Object[keys.size()][2];
47 for (int i = 0; i < keys.size(); i++) {
48 map[i][0] = keys.get(i);
49 map[i][1] = values.get(i);
50 }
51 }
52
53 @Override
54 protected Object[][] getContents() {
55 return map;
56 }
57 }