1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.eclipse.swtbot.generator; |
12 | |
|
13 | |
import java.util.ArrayList; |
14 | |
import java.util.Arrays; |
15 | |
import java.util.Collection; |
16 | |
import java.util.List; |
17 | |
|
18 | |
import org.eclipse.swt.widgets.Widget; |
19 | |
import org.eclipse.swtbot.swt.finder.ReferenceBy; |
20 | |
import org.eclipse.swtbot.swt.finder.SWTBotWidget; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 0 | public class MethodFactory { |
27 | |
|
28 | |
public static ArrayList<String> methods(SWTBotWidget annotation, Class<?> returnType, Class<?> creationType, Class<? extends Widget> widgetType, String methodPrefix) { |
29 | 0 | ArrayList<String> result = new ArrayList<String>(); |
30 | |
|
31 | 0 | List<List<ReferenceBy>> references = getReferenceCombinations(annotation); |
32 | 0 | for (List<ReferenceBy> list : references) { |
33 | 0 | result.add(new MethodGenerator(returnType, creationType, widgetType, methodPrefix, annotation.style().name(), list).commentContents()); |
34 | 0 | result.add(new MethodGenerator(returnType, creationType, widgetType, methodPrefix, annotation.style().name(), list).methodContents()); |
35 | 0 | result.add(new MethodGenerator(returnType, creationType, widgetType, methodPrefix, annotation.style().name(), list).commentContentsWithIndex()); |
36 | 0 | result.add(new MethodGenerator(returnType, creationType, widgetType, methodPrefix, annotation.style().name(), list).methodContentsWithIndex()); |
37 | |
} |
38 | 0 | return result; |
39 | |
} |
40 | |
|
41 | |
private static List<List<ReferenceBy>> getReferenceCombinations(SWTBotWidget annotation) { |
42 | 0 | List<ReferenceBy> value = new ArrayList<ReferenceBy>(Arrays.asList(annotation.referenceBy())); |
43 | 0 | value.addAll(Arrays.asList(annotation.defaultReferenceBy())); |
44 | 0 | ReferenceBy[] array = value.toArray(new ReferenceBy[] {}); |
45 | 0 | return ReferenceBy.getCombinations(array); |
46 | |
} |
47 | |
|
48 | |
public static Collection<? extends String> imports(SWTBotWidget annotation, Class<?> returnType, Class<? extends Widget> widgetType, String methodPrefix) { |
49 | 0 | ArrayList<String> result = new ArrayList<String>(); |
50 | 0 | List<List<ReferenceBy>> references = getReferenceCombinations(annotation); |
51 | 0 | for (List<ReferenceBy> list : references) { |
52 | 0 | result.addAll(new MethodGenerator(returnType, null, widgetType, methodPrefix, annotation.style().name(), list).imports()); |
53 | |
} |
54 | 0 | return result; |
55 | |
} |
56 | |
} |