-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
279 lines (247 loc) · 10.4 KB
/
index.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html style="background: antiquewhite;font-weight: bold;">
<style>
.generate {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
.generate:hover {background-color: #3e8e41}
.generate:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>
<head>
</head>
<title>POJO Utility</title>
<body>
Enter the variable's Definations : <br>
<textarea id="codeTextArea" placeholder="public int height;"style="width: 100%; overflow-y: auto; margin: 0px; height: 165px;resize:none;border: 2px solid #555;"></textarea>
<br />
Select the outputs : <br>
<input type="checkbox" id="Getters" name="Getters" value="Getters">
<label for="Getters">Getters</label><br>
<textArea id="result" style="display:none;width: 100%; overflow-y: auto; margin: 0px; height: 165px;resize:none;border: 2px solid #555;"></textArea><br>
<input type="checkbox" id="Setters" name="Setters" value="Setters">
<label for="Setters" >Setters</label><br>
<textArea id="result1" style="display:none;width: 100%; overflow-y: auto; margin: 0px; height: 165px;resize:none;border: 2px solid #555;"></textArea><br>
<input type="checkbox" id="Constructor" name="Constructor" value="Constructor">
<label for="Constructor">Constructor</label><br>
<textArea id="result2" style="display:none;width: 100%; overflow-y: auto; margin: 0px; height: 165px;resize:none;border: 2px solid #555;"></textArea><br>
<input type="checkbox" id="ToString" name="ToString" value="ToString">
<label for="ToString">ToString</label><br>
<textArea id="result3" style="display:none;width: 100%; overflow-y: auto; margin: 0px; height: 165px;resize:none;border: 2px solid #555;"></textArea><br>
<input type="checkbox" id="completeClass" name="completeClass" value="completeClass">
<label for="completeClass">Complete Class</label><br><br>
<textArea id="result4" style="display:none;width: 100%; overflow-y: auto; margin: 0px; height: 165px;resize:none;border: 2px solid #555;"></textArea><br>
<button onclick="generate();" class="generate">Generate</button>
<br><br>
</body>
<script>
var code = null;
function generate(){
code = document.getElementById("codeTextArea");
var variables = code.value;
if (variables != null && variables.trim() !== "" && variables != undefined) {
if(document.getElementById("Getters").checked){
generateGetters(variables);
document.getElementById("result").style.display = "block";
}
else{
document.getElementById("result").innerHTML = "";
document.getElementById("result").style.display = "none";
}
if(document.getElementById("Setters").checked){
generateSetters(variables);
document.getElementById("result1").style.display = "block";
}
else{
document.getElementById("result1").innerHTML = "";
document.getElementById("result1").style.display = "none";
}
if(document.getElementById("Constructor").checked){
generateConstructor(variables);
document.getElementById("result2").style.display = "block";
}
else{
document.getElementById("result2").innerHTML = "";
document.getElementById("result2").style.display = "none"
}
if(document.getElementById("ToString").checked){
generateToString(variables);
document.getElementById("result3").style.display = "block";
}else{
document.getElementById("result3").innerHTML = "";
document.getElementById("result3").style.display = "none"
}
if(document.getElementById("completeClass").checked){
generateCompleteClass(variables);
document.getElementById("result4").style.display = "block";
}else{
document.getElementById("result4").innerHTML = "";
document.getElementById("result4").style.display = "none"
}
} else {
alert("Put some code in Code area");
}
}
function resetAll(){
document.getElementById("result").innerHTML = "";
document.getElementById("result1").innerHTML = "";
document.getElementById("result2").innerHTML = "";
document.getElementById("result3").innerHTML = "";
}
function generateCompleteClass(variables){
generateGetters(variables);
generateSetters(variables);
generateConstructor(variables);
generateToString(variables);
var completeClassString = "public CLASS_NAME{\n\n";
completeClassString += variables+"\n";
completeClassString += document.getElementById("result2").innerHTML+"\n\n";
completeClassString += document.getElementById("result").innerHTML+"\n\n";
completeClassString += document.getElementById("result1").innerHTML+"\n\n";
completeClassString += document.getElementById("result3").innerHTML+"\n\n";
completeClassString +="\n\n}"
document.getElementById("result4").innerHTML = "";
document.getElementById("result4").innerHTML = completeClassString;
}
function generateToString(variables){
var toString = "";
var constructorBody = "";
var finalLine = "public String toString(){\n\t return ";
var vals = variables.split("\n");
for (var k in vals) {
if (vals[k] != null && vals[k].trim() !== "" && vals[k] != undefined) {
vals[k] = vals[k].replace(";","");
vals[k] = vals[k].trim();
var line = vals[k].split(" ");
var datatypeAdded = false;
var nameAdded = false;
var bodyAdded = false;
var datatype = "";
for (var i in line) {
if (line[i].toLowerCase().trim() == "public" || line[i].toLowerCase().trim() == "private" || line[i].toLowerCase().trim() == "protected" || line[i].toLowerCase().trim() == "global" || line[i].toLowerCase().trim() == "static" || line[i].toLowerCase().trim() == "final") continue;
//else append the code
if (!datatypeAdded) {
datatypeAdded = true;
} else if (!nameAdded) {
finalLine += "\","+line[i]+" :\"+"+line[i]+"+";
nameAdded = true;
constructorBody += "\n\tthis."+line[i]+"="+line[i]+";";
}
}
toString = finalLine;
}
toString = toString.substring(0,toString.length-1);
toString = toString.replace(",","");
toString +=";\n}";
document.getElementById("result3").innerHTML = "";
document.getElementById("result3").innerHTML += toString;
}
}
function generateConstructor(variables){
var constructorString = "";
var constructorBody = "";
var finalLine = "public CLASS_NAME(";
var vals = variables.split("\n");
for (var k in vals) {
if (vals[k] != null && vals[k].trim() !== "" && vals[k] != undefined) {
vals[k] = vals[k].replace(";","");
vals[k] = vals[k].trim();
var line = vals[k].split(" ");
var datatypeAdded = false;
var nameAdded = false;
var bodyAdded = false;
var datatype = "";
for (var i in line) {
if (line[i].toLowerCase().trim() == "public" || line[i].toLowerCase().trim() == "private" || line[i].toLowerCase().trim() == "protected" || line[i].toLowerCase().trim() == "global" || line[i].toLowerCase().trim() == "static" || line[i].toLowerCase().trim() == "final") continue;
//else append the code
if (!datatypeAdded) {
finalLine += line[i];
datatypeAdded = true;
} else if (!nameAdded) {
finalLine += " "+line[i]+",";
nameAdded = true;
constructorBody += "\n\tthis."+line[i]+"="+line[i]+";";
}
}
constructorString = finalLine;
}
constructorString = constructorString.substring(0,constructorString.length-1);
constructorString +="){"+constructorBody+"\n}";
document.getElementById("result2").innerHTML = "";
document.getElementById("result2").innerHTML += constructorString;
}
}
function generateGetters(variables){
var getterString = "";
var vals = variables.split("\n");
for (var k in vals) {
if (vals[k] != null && vals[k].trim() !== "" && vals[k] != undefined) {
vals[k] = vals[k].replace(";","");
vals[k] = vals[k].trim();
var line = vals[k].split(" ");
var finalLine = "public ";
var datatypeAdded = false;
var nameAdded = false;
var bodyAdded = false;
for (var i in line) {
if (line[i].toLowerCase().trim() == "public" || line[i].toLowerCase().trim() == "private" || line[i].toLowerCase().trim() == "protected" || line[i].toLowerCase().trim() == "global" || line[i].toLowerCase().trim() == "static" || line[i].toLowerCase().trim() == "final") continue;
//else append the code
if (!datatypeAdded) {
finalLine += line[i];
datatypeAdded = true;
} else if (!nameAdded) {
finalLine += " get" + line[i].charAt(0).toUpperCase()+""+line[i].substring(1)+"(){\n\treturn "+line[i]+";\n}";
nameAdded = true;
}
}
getterString += finalLine + "\n";
}
document.getElementById("result").innerHTML = "";
document.getElementById("result").innerHTML += getterString;
}
}
function generateSetters(variables) {
var setterString = "";
var vals = variables.split("\n");
for (var k in vals) {
if (vals[k] != null && vals[k].trim() !== "" && vals[k] != undefined) {
vals[k] = vals[k].replace(";","");
vals[k] = vals[k].trim();
var line = vals[k].split(" ");
var finalLine = "public ";
var datatypeAdded = false;
var datatype = "";
var nameAdded = false;
var bodyAdded = false;
for (var i in line) {
if (line[i].toLowerCase().trim() == "public" || line[i].toLowerCase().trim() == "private" || line[i].toLowerCase().trim() == "protected" || line[i].toLowerCase().trim() == "global" || line[i].toLowerCase().trim() == "static" || line[i].toLowerCase().trim() == "final") continue;
//else append the code
if (!datatypeAdded) {
finalLine += "void";
datatypeAdded = true;
datatype = line[i];
} else if (!nameAdded) {
finalLine += " set" + line[i].charAt(0).toUpperCase()+""+line[i].substring(1)+"("+datatype+" "+line[i]+"){\n\tthis."+line[i]+"="+line[i]+";\n}";
nameAdded = true;
}
}
setterString += finalLine + "\n";
}
document.getElementById("result1").innerHTML = "";
document.getElementById("result1").innerHTML += setterString;
}
}
</script>
</html>