1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| package org.rblasch.convert; |
17 |
| |
18 |
| import org.rblasch.convert.converters.lang.CastConverter; |
19 |
| import org.rblasch.convert.converters.lang.IdentityConverter; |
20 |
| import org.rblasch.convert.converters.lang.ObjectToStringConverter; |
21 |
| import org.rblasch.convert.graph.Graph; |
22 |
| import org.rblasch.convert.graph.SparseWeightedDirectedGraph; |
23 |
| import org.rblasch.convert.graph.WeightedDirectedGraph; |
24 |
| import org.rblasch.convert.type.ClassType; |
25 |
| import org.rblasch.convert.type.ParameterizableType; |
26 |
| import org.rblasch.convert.type.Type; |
27 |
| |
28 |
| import java.util.Arrays; |
29 |
| import java.util.Iterator; |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| public class JlGraphFactory { |
36 |
0
| private static void addConnection(final Graph g, final MetaConverter mc) {
|
37 |
0
| g.addConnection(new TypeVertex(mc.getSourceType()),
|
38 |
| new ConverterEdge(mc, mc.getWeight()), |
39 |
| new TypeVertex(mc.getDestinationType())); |
40 |
| } |
41 |
| |
42 |
0
| public static WeightedDirectedGraph createGraphFor(final Type t) {
|
43 |
0
| final WeightedDirectedGraph g = new SparseWeightedDirectedGraph();
|
44 |
| |
45 |
| |
46 |
0
| addConnection(g, new IdentityConverter(t));
|
47 |
| |
48 |
| |
49 |
0
| if (t instanceof ClassType) {
|
50 |
0
| final ClassType ct = (ClassType) t;
|
51 |
| |
52 |
0
| Class tmp = ct.getTheClass();
|
53 |
0
| while (tmp.getSuperclass() != null) {
|
54 |
0
| addConnection(g, new CastConverter(tmp, tmp.getSuperclass()));
|
55 |
| |
56 |
0
| for (final Iterator i = Arrays.asList(tmp.getInterfaces()).iterator(); i.hasNext();) {
|
57 |
0
| final Class iface = (Class) i.next();
|
58 |
0
| addConnection(g, new CastConverter(tmp, iface));
|
59 |
| } |
60 |
| |
61 |
0
| tmp = tmp.getSuperclass();
|
62 |
| } |
63 |
0
| } else if (t instanceof ParameterizableType) {
|
64 |
| |
65 |
| } |
66 |
| |
67 |
| |
68 |
0
| addConnection(g, new ObjectToStringConverter());
|
69 |
| |
70 |
0
| return g;
|
71 |
| } |
72 |
| } |