Debian Codegraph @

jte-jsp-converter/src/main/java/gg/jte/convert/jsp/converter/JspAttributeConverter.java

raw
1 package gg.jte.convert.jsp.converter;
2
3 import gg.jte.convert.ConverterOutput;
4 import org.apache.jasper.compiler.JtpAttribute;
5 import org.apache.jasper.compiler.JtpConverter;
6
7 public class JspAttributeConverter {
8
9 @SuppressWarnings("StatementWithEmptyBody")
10 public void convert(JtpConverter converter, JtpAttribute attribute, ConverterOutput output) {
11 String type = attribute.getType();
12
13 if (type == null) {
14 type = "Object";
15 } else if (type.equals("java.lang.Boolean")) {
16 type = "boolean";
17 } else if (type.equals("java.lang.Byte")) {
18 type = "byte";
19 } else if (type.equals("java.lang.Short")) {
20 type = "short";
21 } else if (type.equals("java.lang.Integer")) {
22 type = "int";
23 } else if (type.equals("java.lang.Long")) {
24 type = "long";
25 } else if (type.equals("java.lang.Float")) {
26 type = "float";
27 } else if (type.equals("java.lang.Double")) {
28 type = "double";
29 } else if (type.startsWith("java.lang.")) {
30 type = type.substring("java.lang.".length());
31 } else if (type.contains("<") && type.contains(">")) {
32 // Keep type, if user wants imports its up to the user to do that manually
33 } else if(type.endsWith("[]")) {
34 converter.addImport(type.substring(0, type.length() - 2));
35 type = getSimpleType(type);
36 } else {
37 converter.addImport(type);
38 type = getSimpleType(type);
39 }
40
41 output.append("@param ").append(type).append(" ").append(attribute.getName());
42
43 if (!Boolean.parseBoolean(attribute.getAttribute("required"))) {
44 output.append(" = ");
45 output.append("CHOOSE_DEFAULT_VALUE");
46 }
47 }
48
49 private String getSimpleType(String type) {
50 int i = type.lastIndexOf('.');
51 if (i == -1) {
52 return type;
53 }
54
55 return type.substring(i + 1);
56 }
57 }