グラマー作成中
@@ -3,7 +3,9 @@ | ||
3 | 3 | import java.io.FileInputStream; |
4 | 4 | import java.io.IOException; |
5 | 5 | import java.util.ArrayList; |
6 | +import java.util.HashMap; | |
6 | 7 | import java.util.List; |
8 | +import java.util.Map; | |
7 | 9 | |
8 | 10 | import jp.fs.rgsslib.tools.rpgtkool.common.CommonUtils; |
9 | 11 | import jp.sf.rgsslib.tools.j2rlib.vxace.RGSSProxyFacade; |
@@ -46,76 +48,121 @@ | ||
46 | 48 | } |
47 | 49 | return proxyFacade.createSystem(); |
48 | 50 | } |
49 | - | |
51 | + | |
50 | 52 | // 変数の情報 |
51 | - private static List<String> getVariables(SystemDSLModel dsl, | |
52 | - List<String> variables) { | |
53 | - for (VariableInfo variableInfo : dsl.getVariable().getVariables()) { | |
54 | - if (variableInfo.getName() != null) | |
55 | - variables.add(variableInfo.getName()); | |
53 | + private static Map<Integer,String> getVariablesInternal(Resource resource) { | |
54 | + Map<Integer,String> variables = new HashMap<Integer,String>(); | |
55 | + int count = 0; | |
56 | + if (resource.getURI().segmentCount() > 1) { | |
57 | + String projectName = resource.getURI().segment(1); | |
58 | + if (projectName != null) { | |
59 | + System systemData = getSystemData(projectName); | |
60 | + for (String name : systemData.getVariables()) { | |
61 | + variables.put(count,name); | |
62 | + count++; | |
63 | + } | |
64 | + } | |
56 | 65 | } |
57 | - return variables; | |
58 | - } | |
59 | 66 | |
60 | - private static List<String> getVariables(System systemData, | |
61 | - List<String> variables) { | |
62 | - for (String variable : systemData.getVariables()) { | |
63 | - if (variable != null) | |
64 | - variables.add(variable); | |
67 | + EObject object = CommonUtils.getSystemDSLModel(resource); | |
68 | + if (object instanceof SystemDSLModel) { | |
69 | + SystemDSLModel dsl = (SystemDSLModel) object; | |
70 | + for (VariableInfo info : dsl.getVariable().getVariables()) { | |
71 | + if (info.getName() != null) { | |
72 | + if (info.getId() > 0) { | |
73 | + count = info.getId(); | |
74 | + } | |
75 | + variables.put(count,info.getName()); | |
76 | + count++; | |
77 | + } | |
78 | + } | |
65 | 79 | } |
66 | 80 | return variables; |
67 | 81 | } |
68 | 82 | |
83 | + /** | |
84 | + * コンテンツアシスト用に、null の入らない名前のリストを返す。 | |
85 | + * @param resource | |
86 | + * @return | |
87 | + */ | |
69 | 88 | public static List<String> getVariables(Resource resource) { |
70 | - List<String> variables = new ArrayList<String>(); | |
71 | - | |
72 | - EObject object = CommonUtils.getSystemDSLModel(resource); | |
73 | - if (object instanceof SystemDSLModel) { | |
74 | - getVariables((SystemDSLModel) object, variables); | |
89 | + List<String> list = new ArrayList<String>(); | |
90 | + for(String name : getVariablesInternal(resource).values()) { | |
91 | + if (name != null) | |
92 | + list.add(name); | |
75 | 93 | } |
94 | + return list; | |
95 | + } | |
96 | + /** | |
97 | + * データ生成用に、名前からIDを取るためのマップを返す。 | |
98 | + * @param resource | |
99 | + * @return | |
100 | + */ | |
101 | + public static Map<String,Integer> getVariablesMap(Resource resource) { | |
102 | + Map<String,Integer> map = new HashMap<String,Integer>(); | |
103 | + for(Map.Entry<Integer, String> et : getVariablesInternal(resource).entrySet()) { | |
104 | + if (et.getValue() != null) { | |
105 | + map.put(et.getValue(), et.getKey()); | |
106 | + } | |
107 | + } | |
108 | + return map; | |
109 | + } | |
76 | 110 | |
111 | + // スイッチの情報 | |
112 | + private static Map<Integer,String> getSwitchesInternal(Resource resource) { | |
113 | + Map<Integer,String> switches = new HashMap<Integer,String>(); | |
114 | + int count = 0; | |
77 | 115 | if (resource.getURI().segmentCount() > 1) { |
78 | 116 | String projectName = resource.getURI().segment(1); |
79 | 117 | if (projectName != null) { |
80 | - getVariables(getSystemData(projectName), variables); | |
118 | + System systemData = getSystemData(projectName); | |
119 | + for (String name : systemData.getSwitches()) { | |
120 | + switches.put(count,name); | |
121 | + count++; | |
122 | + } | |
81 | 123 | } |
82 | 124 | } |
83 | - return variables; | |
84 | - } | |
85 | 125 | |
86 | - // スイッチの情報 | |
87 | - private static List<String> getSwitches(SystemDSLModel dsl, | |
88 | - List<String> switches) { | |
89 | - for (SwitchInfo switchInfo : dsl.getSwitch().getSwitches()) { | |
90 | - if (switchInfo.getName() != null) | |
91 | - switches.add(switchInfo.getName()); | |
126 | + EObject object = CommonUtils.getSystemDSLModel(resource); | |
127 | + if (object instanceof SystemDSLModel) { | |
128 | + SystemDSLModel dsl = (SystemDSLModel) object; | |
129 | + for (SwitchInfo info : dsl.getSwitch().getSwitches()) { | |
130 | + if (info.getName() != null) { | |
131 | + if (info.getId() > 0) { | |
132 | + count = info.getId(); | |
133 | + } | |
134 | + switches.put(count,info.getName()); | |
135 | + count++; | |
136 | + } | |
137 | + } | |
92 | 138 | } |
93 | 139 | return switches; |
94 | 140 | } |
95 | - | |
96 | - private static List<String> getSwitches(System systemData, | |
97 | - List<String> switches) { | |
98 | - for (String _switch : systemData.getSwitches()) { | |
99 | - if (_switch != null) | |
100 | - switches.add(_switch); | |
141 | + /** | |
142 | + * コンテンツアシスト用に、null の入らない名前のリストを返す。 | |
143 | + * @param resource | |
144 | + * @return | |
145 | + */ | |
146 | + public static List<String> getSwitches(Resource resource) { | |
147 | + List<String> list = new ArrayList<String>(); | |
148 | + for(String name : getSwitchesInternal(resource).values()) { | |
149 | + if (name != null) | |
150 | + list.add(name); | |
101 | 151 | } |
102 | - return switches; | |
152 | + return list; | |
103 | 153 | } |
104 | - | |
105 | - public static List<String> getSwitches(Resource resource) { | |
106 | - List<String> switches = new ArrayList<String>(); | |
107 | - | |
108 | - EObject object = CommonUtils.getSystemDSLModel(resource); | |
109 | - if (object instanceof SystemDSLModel) { | |
110 | - getSwitches((SystemDSLModel) object, switches); | |
111 | - } | |
112 | - | |
113 | - if (resource.getURI().segmentCount() > 1) { | |
114 | - String projectName = resource.getURI().segment(1); | |
115 | - if (projectName != null) { | |
116 | - getSwitches(getSystemData(projectName), switches); | |
154 | + /** | |
155 | + * データ生成用に、名前からIDを取るためのマップを返す。 | |
156 | + * @param resource | |
157 | + * @return | |
158 | + */ | |
159 | + public static Map<String,Integer> getSwitchesMap(Resource resource) { | |
160 | + Map<String,Integer> map = new HashMap<String,Integer>(); | |
161 | + for(Map.Entry<Integer, String> et : getSwitchesInternal(resource).entrySet()) { | |
162 | + if (et.getValue() != null) { | |
163 | + map.put(et.getValue(), et.getKey()); | |
117 | 164 | } |
118 | 165 | } |
119 | - return switches; | |
166 | + return map; | |
120 | 167 | } |
121 | 168 | } |