forked from eSprinkle/QuickAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateClass.java
98 lines (78 loc) · 2.8 KB
/
CreateClass.java
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
/**
* CreateClass is used to create a new java file with view mappings embeded in it
* @organisation: eSprinkle
* @version: 1.0.0
**/
class CreateClass{
private BufferedWriter classWriter;
public boolean embedCode(List<ViewType> activityList,String xmlSourceFileName,String packageName,String className,Path classLocationPath) throws IOException,LocalException{
File dir = new File(classLocationPath.getParent().toAbsolutePath().toString());
dir.mkdirs();
classWriter=new BufferedWriter(new FileWriter(classLocationPath.toString()));
headerClassCodings(packageName,className);
//declerations
classWriter.newLine();
classWriter.write(" /* eSprinkle-quickAndroid:decleration_begin=[true] */");
classWriter.newLine();
for(ViewType vt:activityList){
classWriter.write(SourceGenerator.getControlDecleration(vt.getControl(),vt.getId()));
classWriter.newLine();
}
classWriter.write(" /* eSprinkle-quickAndroid:decleration_end=[true] */");
classWriter.newLine();
intermediateClassCodings();
//other class def
classWriter.write(" /* eSprinkle-quickAndroid:definition_begin=[true] */");
classWriter.newLine();
for(ViewType vt:activityList){
classWriter.write(SourceGenerator.getControlDefinition(vt.getControl(),vt.getId()));
classWriter.newLine();
}
classWriter.write(" /* eSprinkle-quickAndroid:definition_end=[true]; Start your code from below */");
classWriter.newLine();
//other class def
endClassCodings();
classWriter.close();
return true;
}
private void headerClassCodings(String pack,String className) throws IOException{
if(pack!=null){
classWriter.write("package "+pack+";");
classWriter.newLine();
}
classWriter.write("import android.app.Activity;");
classWriter.newLine();
classWriter.write("import android.os.Bundle;");
classWriter.newLine();
classWriter.newLine();
classWriter.write("/* eSprinkle-quickAndroid:generatedClass=["+className+"] */");
classWriter.newLine();
classWriter.write("public class "+className+" extends Activity{");
classWriter.newLine();
}
private void intermediateClassCodings() throws IOException{
classWriter.newLine();
classWriter.write(" @Override");
classWriter.newLine();
classWriter.write(" protected void onCreate(Bundle savedInstanceState) {");
classWriter.newLine();
classWriter.write(" super.onCreate(savedInstanceState);");
classWriter.newLine();
classWriter.newLine();
}
private void endClassCodings() throws IOException{
classWriter.newLine();
classWriter.newLine();
classWriter.newLine();
classWriter.write(" }");
classWriter.newLine();
classWriter.write("}");
classWriter.newLine();
}
}