Changeset 1327 for trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
- Timestamp:
- 01/15/14 16:05:34 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
r1325 r1327 17 17 import java.util.ArrayList; 18 18 import java.util.HashMap; 19 import java.util.HashSet; 19 20 import java.util.LinkedList; 20 21 import java.util.List; 21 22 import java.util.Map; 23 import java.util.Set; 22 24 import java.util.regex.Matcher; 23 25 import java.util.regex.Pattern; … … 99 101 } 100 102 103 correctTargets(taskInstanceList); 104 101 105 return taskInstanceList; 102 106 } … … 190 194 } 191 195 else { 192 Event event = !task.getInstances().isEmpty() ? 193 ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent() : 194 createUserInteractionEvent(type, id, matcher.group(4)); 195 196 Event event = createUserInteractionEvent(type, id, matcher.group(4)); 196 197 instance = taskFactory.createNewTaskInstance((IEventTask) task, event); 197 198 } … … 237 238 238 239 /** 239 * <p> 240 * TODO: comment 241 * </p> 242 * 243 * @param id 244 * @param type 245 * @param children 246 * @return 240 * 247 241 */ 248 242 private ITask getCreateTask(String id, String type, List<ITaskInstance> children) { 249 ITask task = tasks.get(id); 243 String effectiveId = id; 244 ITask task = tasks.get(effectiveId); 250 245 251 246 if (task == null) { … … 263 258 } 264 259 else { 265 task = taskFactory.createNewEventTask(type + " --> " + id); 260 effectiveId = type + " --> " + id; 261 task = tasks.get(effectiveId); 262 263 if (task == null) { 264 task = taskFactory.createNewEventTask(effectiveId); 265 } 266 266 } 267 tasks.put( id, task);267 tasks.put(effectiveId, task); 268 268 269 269 for (ITaskInstance childInstance : children) { … … 332 332 IEventTarget eventTarget = targets.get(targetId); 333 333 if (eventTarget == null) { 334 eventTarget = determineTarget(type, targetId, furtherInfo);334 eventTarget = new DummyGUIElement(targetId); 335 335 targets.put(targetId, eventTarget); 336 336 } 337 337 338 IEventType eventType = determineType(type, furtherInfo); 338 339 339 340 return new Event(eventType, eventTarget); 340 }341 342 /**343 * <p>344 * </p>345 *346 * @param type347 * @param id348 * @param enteredText349 * @return350 */351 private IEventTarget determineTarget(String type, String id, String enteredText) {352 if ("TextInput".equals(type) && enteredText != null) {353 return new DummyTextField(enteredText);354 }355 else {356 return new DummyGUIElement(id);357 }358 341 } 359 342 … … 367 350 */ 368 351 private IEventType determineType(String type, String enteredText) { 369 if ("TextInput".equals(type) && enteredText != null) {352 if ("TextInput".equals(type)) { 370 353 return new TextInput(enteredText, new ArrayList<Event>()); 371 354 } … … 375 358 } 376 359 360 /** 361 * 362 */ 363 private void correctTargets(ITaskInstanceList taskInstanceList) { 364 Set<IEventTarget> textInputTargets = new HashSet<IEventTarget>(); 365 366 for (ITaskInstance instance : taskInstanceList) { 367 getTextInputTargets(instance, textInputTargets); 368 } 369 370 Map<IEventTarget, IEventTarget> replacements = new HashMap<IEventTarget, IEventTarget>(); 371 372 for (IEventTarget oldTarget : textInputTargets) { 373 replacements.put(oldTarget, new DummyTextField(oldTarget.toString())); 374 } 375 376 for (int i = 0; i < taskInstanceList.size(); i++) { 377 taskBuilder.setTaskInstance 378 (taskInstanceList, i, replaceTargets(taskInstanceList.get(i), replacements)); 379 } 380 381 } 382 383 /** 384 * 385 */ 386 private void getTextInputTargets(ITaskInstance instance, Set<IEventTarget> textInputTargets) { 387 if (instance instanceof ISequenceInstance) { 388 for (ITaskInstance child : (ISequenceInstance) instance) { 389 getTextInputTargets(child, textInputTargets); 390 } 391 } 392 else if (instance instanceof ISelectionInstance) { 393 getTextInputTargets(((ISelectionInstance) instance).getChild(), textInputTargets); 394 } 395 else if (instance instanceof IIterationInstance) { 396 for (ITaskInstance child : (IIterationInstance) instance) { 397 getTextInputTargets(child, textInputTargets); 398 } 399 } 400 else if (instance instanceof IOptionalInstance) { 401 getTextInputTargets(((IOptionalInstance) instance).getChild(), textInputTargets); 402 } 403 else if ((instance instanceof IEventTaskInstance) && 404 (((IEventTaskInstance) instance).getEvent().getType() instanceof TextInput)) 405 { 406 textInputTargets.add(((IEventTaskInstance) instance).getEvent().getTarget()); 407 } 408 } 409 410 /** 411 * 412 */ 413 private ITaskInstance replaceTargets(ITaskInstance instance, 414 Map<IEventTarget, IEventTarget> replacements) 415 { 416 ITaskInstance replacement = instance; 417 if (instance instanceof ITaskInstanceList) { 418 for (int i = 0; i < ((ITaskInstanceList) instance).size(); i++) { 419 taskBuilder.setTaskInstance 420 ((ITaskInstanceList) instance, i, 421 replaceTargets(((ITaskInstanceList) instance).get(i), replacements)); 422 } 423 } 424 else if (instance instanceof ISelectionInstance) { 425 ISelectionInstance selInst = (ISelectionInstance) instance; 426 taskBuilder.setChild(selInst, replaceTargets(selInst.getChild(), replacements)); 427 } 428 else if (instance instanceof IOptionalInstance) { 429 IOptionalInstance optInst = (IOptionalInstance) instance; 430 taskBuilder.setChild(optInst, replaceTargets(optInst.getChild(), replacements)); 431 } 432 else if ((instance instanceof IEventTaskInstance) && 433 (replacements.containsKey(((IEventTaskInstance) instance).getEvent().getTarget()))) 434 { 435 Event origEvent = ((IEventTaskInstance) instance).getEvent(); 436 replacement = taskFactory.createNewTaskInstance 437 (((IEventTaskInstance) instance).getEventTask(), 438 new Event(origEvent.getType(), replacements.get(origEvent.getTarget()))); 439 } 440 441 return replacement; 442 } 443 377 444 }
Note: See TracChangeset
for help on using the changeset viewer.