View Javadoc
1   package de.fhdw.wtf.walker.tasks.util;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.concurrent.ExecutionException;
6   
7   import de.fhdw.wtf.common.ast.Model;
8   import de.fhdw.wtf.common.task.TaskExecutor;
9   import de.fhdw.wtf.common.task.TaskExecutorFixed;
10  import de.fhdw.wtf.common.task.result.ExceptionalTaskResult;
11  import de.fhdw.wtf.common.task.result.OKTaskResult;
12  import de.fhdw.wtf.common.task.result.TaskResult;
13  import de.fhdw.wtf.common.task.result.visitor.TaskResultVisitor;
14  import de.fhdw.wtf.walker.tasks.ConstructorReferencer;
15  import de.fhdw.wtf.walker.tasks.TypeReferencer;
16  
17  /**
18   * Contains all values of the execution of referencer: Collection<OKTaskResult> okResult;
19   * Collection<ExceptionalTaskResult> failResult; Collection<TaskResult> results;.
20   */
21  public class ConstructorReferencerTestReturnValue {
22  	
23  	/**
24  	 * Contains all positive results of task execution.
25  	 */
26  	private final Collection<OKTaskResult> okResult;
27  	
28  	/**
29  	 * Contains all negative results of task execution.
30  	 */
31  	private final Collection<ExceptionalTaskResult> failResult;
32  	
33  	/**
34  	 * The referencer which is executed to get the return values.
35  	 */
36  	private final TypeReferencer referencer;
37  	
38  	/**
39  	 * Constructor. Executes the referencing of the given model.
40  	 * 
41  	 * @param model
42  	 *            - model for type referencing.
43  	 * @throws InterruptedException
44  	 *             - {@link InterruptedException}
45  	 * @throws ExecutionException
46  	 *             - {@link ExecutionException}.
47  	 */
48  	public ConstructorReferencerTestReturnValue(final Model model) throws InterruptedException, ExecutionException {
49  		
50  		final TaskExecutor taskManager = TaskExecutorFixed.create();
51  		this.referencer = TypeReferencer.create(model, taskManager);
52  		taskManager.startAllKnownTasks();
53  		this.okResult = new ArrayList<>();
54  		this.failResult = new ArrayList<>();
55  		final Collection<TaskResult> results = taskManager.getResultsAndShutdown();
56  		final TaskExecutor taskManager2 = TaskExecutorFixed.create();
57  		ConstructorReferencer.create(model, taskManager2);
58  		taskManager2.startAllKnownTasks();
59  		results.addAll(taskManager2.getResultsAndShutdown());
60  		
61  		for (final TaskResult current : results) {
62  			current.accept(new TaskResultVisitor() {
63  				
64  				@Override
65  				public void handleOkTaskResult(final OKTaskResult result) {
66  					ConstructorReferencerTestReturnValue.this.okResult.add(result);
67  				}
68  				
69  				@Override
70  				public void handleExceptionalTaskResult(final ExceptionalTaskResult result) {
71  					ConstructorReferencerTestReturnValue.this.failResult.add(result);
72  				}
73  			});
74  		}
75  	}
76  	
77  	/**
78  	 * Returns the collection of positive results of the task execution.
79  	 * 
80  	 * @return Collection of positive results.
81  	 */
82  	public Collection<OKTaskResult> getOkResult() {
83  		return this.okResult;
84  	}
85  	
86  	/**
87  	 * Returns the collection of negative results of the task execution.
88  	 * 
89  	 * @return Collection of negative results.
90  	 */
91  	public Collection<ExceptionalTaskResult> getFailResult() {
92  		return this.failResult;
93  	}
94  	
95  	/**
96  	 * Returns the referencer which is used for referencing the given model.
97  	 * 
98  	 * @return used {@link TypeReferencer}.
99  	 */
100 	public TypeReferencer getTypeReferencer() {
101 		return this.referencer;
102 	}
103 }