1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.eclipse.swtbot.generator; |
12 | |
|
13 | |
import java.lang.reflect.Constructor; |
14 | |
import java.util.ArrayList; |
15 | |
import java.util.Collection; |
16 | |
|
17 | |
import org.eclipse.swtbot.swt.finder.SWTBotWidget; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class SWTBotGeneratorFactoryReader { |
24 | |
|
25 | |
private SWTBotWidget annotation; |
26 | |
private Constructor<?> constructor; |
27 | |
private Class<?> clasz; |
28 | |
|
29 | 0 | public SWTBotGeneratorFactoryReader(String className) throws ClassNotFoundException { |
30 | 0 | clasz = Class.forName(className); |
31 | 0 | annotation = getSWTBotAnnotation(); |
32 | 0 | constructor = getConstructor(); |
33 | 0 | } |
34 | |
|
35 | |
public ArrayList<String> getMethods() { |
36 | 0 | if (annotation == null) |
37 | 0 | return new ArrayList<String>(); |
38 | |
|
39 | |
Class<?> returnType; |
40 | |
|
41 | 0 | returnType = annotation.returnType(); |
42 | 0 | if (returnType == Object.class) |
43 | 0 | returnType = constructor.getDeclaringClass(); |
44 | |
|
45 | 0 | Class<?> creationType = constructor.getDeclaringClass(); |
46 | 0 | return MethodFactory.methods(annotation, returnType, creationType, annotation.clasz(), annotation.preferredName()); |
47 | |
} |
48 | |
|
49 | |
public Collection<? extends String> getImports() { |
50 | 0 | if (annotation == null) |
51 | 0 | return new ArrayList<String>(); |
52 | 0 | return MethodFactory.imports(annotation, constructor.getDeclaringClass(), annotation.clasz(), annotation.preferredName()); |
53 | |
} |
54 | |
|
55 | |
private Constructor<?> getConstructor() { |
56 | 0 | return clasz.getConstructors()[0]; |
57 | |
} |
58 | |
|
59 | |
private SWTBotWidget getSWTBotAnnotation() { |
60 | 0 | return clasz.getAnnotation(SWTBotWidget.class); |
61 | |
} |
62 | |
|
63 | |
} |