-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGirCodebase.java
More file actions
71 lines (59 loc) · 1.75 KB
/
GirCodebase.java
File metadata and controls
71 lines (59 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gir2java;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import nu.xom.Document;
import com.sun.codemodel.JCodeModel;
/**
* The core class of gir2java. Responsible for traversing the XOM tree of GIR XML documents, and building a
* CodeModel AST from them. There is one GirCodebase for all GIR XMLs you want to generate a common Java
* codebase for. The general correct usage is something like
*
* <pre><code>
* Document doc = getGirFromSomewhere();
* GirCodebase cb = new GirCodebase();
* cb.addGir(doc);
* cb.addGir(someOtherDoc);
* cb.saveJava(javadir);
* </code></pre>
*
* @author relek
*
*/
public class GirCodebase {
private JCodeModel cm;
private GirParser parser;
private GirDependencyGraph girs;
public GirCodebase() {
cm = new JCodeModel();
parser = new GirParser(cm);
girs = new GirDependencyGraph(parser);
}
public void addGir(Document gir) {
girs.addGir(gir);
}
public void saveJava(File javadir) throws IOException {
System.out.println("Preprocessing begins");
System.out.println(girs);
List<Document> girsTopoSorted = girs.getGirsTopoSorted();
System.out.println("Gir parsing order:");
for (Document gir : girsTopoSorted) {
System.out.println(gir.getBaseURI());
}
System.out.println("Parsing begins");
for (Document gir : girsTopoSorted) {
parser.parseElement(gir.getRootElement());
}
System.out.println("Collecting type references");
for (Document gir : girsTopoSorted) {
parser.findAllTypeReferences(gir.getRootElement());
}
cm.build(javadir);
}
public void saveTypes(File found, File referenced, File undefined) {
parser.outputTypes(found, referenced, undefined);
}
}