|
@@ -4,27 +4,32 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
|
4
|
4
|
import org.openzen.zenscript.codemodel.FunctionParameter;
|
5
|
5
|
import org.openzen.zenscript.codemodel.generic.*;
|
6
|
6
|
import org.openzen.zenscript.codemodel.type.*;
|
|
7
|
+import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
|
7
|
8
|
|
8
|
9
|
import java.util.Collection;
|
9
|
10
|
|
10
|
11
|
public class JavaTypeGenericVisitor implements ITypeVisitor<String> {
|
11
|
12
|
|
12
|
|
- public static final JavaTypeGenericVisitor INSTANCE = new JavaTypeGenericVisitor();
|
|
13
|
+ private final JavaBytecodeContext context;
|
|
14
|
+
|
|
15
|
+ public JavaTypeGenericVisitor(JavaBytecodeContext context) {
|
|
16
|
+ this.context = context;
|
|
17
|
+ }
|
13
|
18
|
|
14
|
19
|
|
15
|
|
- public static String getGenericSignature(ITypeID... types) {
|
|
20
|
+ public String getGenericSignature(ITypeID... types) {
|
16
|
21
|
if (types == null || types.length == 0)
|
17
|
22
|
return "";
|
18
|
23
|
final StringBuilder builder = new StringBuilder();
|
19
|
24
|
for (ITypeID type : types) {
|
20
|
|
- builder.append(type.accept(INSTANCE));
|
|
25
|
+ builder.append(type.accept(this));
|
21
|
26
|
}
|
22
|
27
|
|
23
|
28
|
return builder.toString();
|
24
|
29
|
}
|
25
|
30
|
|
26
|
31
|
|
27
|
|
- public static String getGenericSignature(TypeParameter... parameters) {
|
|
32
|
+ public String getGenericSignature(TypeParameter... parameters) {
|
28
|
33
|
if (parameters == null || parameters.length == 0)
|
29
|
34
|
return "";
|
30
|
35
|
|
|
@@ -35,7 +40,7 @@ public class JavaTypeGenericVisitor implements ITypeVisitor<String> {
|
35
|
40
|
return builder.toString();
|
36
|
41
|
}
|
37
|
42
|
|
38
|
|
- public static String getSignatureWithBound(ITypeID type) {
|
|
43
|
+ public String getSignatureWithBound(ITypeID type) {
|
39
|
44
|
if(type instanceof GenericTypeID){
|
40
|
45
|
final TypeParameter parameter = ((GenericTypeID) type).parameter;
|
41
|
46
|
return parameter.name + ":" + getGenericBounds(parameter.bounds);
|
|
@@ -43,24 +48,24 @@ public class JavaTypeGenericVisitor implements ITypeVisitor<String> {
|
43
|
48
|
throw new IllegalStateException("Type " + type + " is of the wrong class");
|
44
|
49
|
}
|
45
|
50
|
|
46
|
|
- private static String getGenericSignature(FunctionParameter... parameters) {
|
|
51
|
+ private String getGenericSignature(FunctionParameter... parameters) {
|
47
|
52
|
if(parameters == null || parameters.length == 0)
|
48
|
53
|
return "";
|
49
|
54
|
final StringBuilder builder = new StringBuilder();
|
50
|
55
|
for (FunctionParameter parameter : parameters) {
|
51
|
|
- builder.append(parameter.type.accept(INSTANCE));
|
|
56
|
+ builder.append(parameter.type.accept(this));
|
52
|
57
|
}
|
53
|
58
|
return builder.toString();
|
54
|
59
|
}
|
55
|
60
|
|
56
|
|
- public static String getGenericMethodSignature(FunctionHeader header) {
|
|
61
|
+ public String getGenericMethodSignature(FunctionHeader header) {
|
57
|
62
|
return "(" + getGenericSignature(header.parameters) +
|
58
|
63
|
")" +
|
59
|
64
|
getGenericSignature(header.returnType);
|
60
|
65
|
}
|
61
|
66
|
|
62
|
67
|
|
63
|
|
- public static String getGenericBounds(Collection<GenericParameterBound> collection) {
|
|
68
|
+ public String getGenericBounds(Collection<GenericParameterBound> collection) {
|
64
|
69
|
if (collection == null)
|
65
|
70
|
return "";
|
66
|
71
|
for (GenericParameterBound parameterBound : collection) {
|
|
@@ -72,7 +77,7 @@ public class JavaTypeGenericVisitor implements ITypeVisitor<String> {
|
72
|
77
|
|
73
|
78
|
@Override
|
74
|
79
|
public String visitType(ParameterTypeBound bound) {
|
75
|
|
- return bound.type.accept(INSTANCE);
|
|
80
|
+ return bound.type.accept(JavaTypeGenericVisitor.this);
|
76
|
81
|
}
|
77
|
82
|
});
|
78
|
83
|
if (s != null)
|
|
@@ -81,38 +86,34 @@ public class JavaTypeGenericVisitor implements ITypeVisitor<String> {
|
81
|
86
|
return "Ljava/lang/Object;";
|
82
|
87
|
}
|
83
|
88
|
|
84
|
|
-
|
85
|
|
- private JavaTypeGenericVisitor() {
|
86
|
|
- }
|
87
|
|
-
|
88
|
89
|
@Override
|
89
|
90
|
public String visitBasic(BasicTypeID basic) {
|
90
|
|
- return basic.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
|
|
91
|
+ return context.getDescriptor(basic);
|
91
|
92
|
}
|
92
|
93
|
|
93
|
94
|
@Override
|
94
|
95
|
public String visitArray(ArrayTypeID array) {
|
95
|
|
- return array.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
|
|
96
|
+ return context.getDescriptor(array);
|
96
|
97
|
}
|
97
|
98
|
|
98
|
99
|
@Override
|
99
|
100
|
public String visitAssoc(AssocTypeID assoc) {
|
100
|
|
- return assoc.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
|
|
101
|
+ return context.getDescriptor(assoc);
|
101
|
102
|
}
|
102
|
103
|
|
103
|
104
|
@Override
|
104
|
105
|
public String visitGenericMap(GenericMapTypeID map) {
|
105
|
|
- return map.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
|
|
106
|
+ return context.getDescriptor(map);
|
106
|
107
|
}
|
107
|
108
|
|
108
|
109
|
@Override
|
109
|
110
|
public String visitIterator(IteratorTypeID iterator) {
|
110
|
|
- return iterator.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
|
|
111
|
+ return context.getDescriptor(iterator);
|
111
|
112
|
}
|
112
|
113
|
|
113
|
114
|
@Override
|
114
|
115
|
public String visitFunction(FunctionTypeID function) {
|
115
|
|
- return function.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
|
|
116
|
+ return context.getDescriptor(function);
|
116
|
117
|
}
|
117
|
118
|
|
118
|
119
|
@Override
|
|
@@ -138,7 +139,7 @@ public class JavaTypeGenericVisitor implements ITypeVisitor<String> {
|
138
|
139
|
|
139
|
140
|
@Override
|
140
|
141
|
public String visitRange(RangeTypeID range) {
|
141
|
|
- return range.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
|
|
142
|
+ return context.getDescriptor(range);
|
142
|
143
|
}
|
143
|
144
|
|
144
|
145
|
@Override
|