|
@@ -76,6 +76,7 @@ public class JavaNativeModule {
|
76
|
76
|
private final JavaCompiledModule compiled;
|
77
|
77
|
|
78
|
78
|
private final Map<Class<?>, HighLevelDefinition> definitionByClass = new HashMap<>();
|
|
79
|
+ private final JavaNativeModule[] dependencies;
|
79
|
80
|
private final Map<Class<?>, TypeID> typeByClass = new HashMap<>();
|
80
|
81
|
private final Map<Class<?>, TypeID> unsignedByClass = new HashMap<>();
|
81
|
82
|
|
|
@@ -91,10 +92,7 @@ public class JavaNativeModule {
|
91
|
92
|
this.basePackage = basePackage;
|
92
|
93
|
module = new Module(name);
|
93
|
94
|
this.registry = registry;
|
94
|
|
-
|
95
|
|
- for (JavaNativeModule dependency : dependencies) {
|
96
|
|
- definitionByClass.putAll(dependency.definitionByClass);
|
97
|
|
- }
|
|
95
|
+ this.dependencies = dependencies;
|
98
|
96
|
|
99
|
97
|
compiled = new JavaCompiledModule(module, FunctionParameter.NONE);
|
100
|
98
|
|
|
@@ -145,11 +143,25 @@ public class JavaNativeModule {
|
145
|
143
|
return compiled;
|
146
|
144
|
}
|
147
|
145
|
|
|
146
|
+ private HighLevelDefinition getDefinitionForClass(Class<?> cls) {
|
|
147
|
+ HighLevelDefinition definition = definitionByClass.get(cls);
|
|
148
|
+
|
|
149
|
+ if(definition != null)
|
|
150
|
+ return definition;
|
|
151
|
+ for (JavaNativeModule dependency : this.dependencies) {
|
|
152
|
+ definition = dependency.getDefinitionForClass(cls);
|
|
153
|
+ if(definition != null)
|
|
154
|
+ return definition;
|
|
155
|
+ }
|
|
156
|
+ return null;
|
|
157
|
+ }
|
|
158
|
+
|
148
|
159
|
public HighLevelDefinition addClass(Class<?> cls) {
|
149
|
|
- if (definitionByClass.containsKey(cls))
|
150
|
|
- return definitionByClass.get(cls);
|
|
160
|
+ HighLevelDefinition result = getDefinitionForClass(cls);
|
|
161
|
+ if(result != null)
|
|
162
|
+ return result;
|
151
|
163
|
|
152
|
|
- HighLevelDefinition result = convertClass(cls);
|
|
164
|
+ result = convertClass(cls);
|
153
|
165
|
return result;
|
154
|
166
|
}
|
155
|
167
|
|
|
@@ -216,6 +228,20 @@ public class JavaNativeModule {
|
216
|
228
|
return className.startsWith(basePackage + ".");
|
217
|
229
|
}
|
218
|
230
|
|
|
231
|
+ private ZSPackage getPackageOrNull(String className) {
|
|
232
|
+ ZSPackage zsPackage;
|
|
233
|
+ for (JavaNativeModule dependency : this.dependencies) {
|
|
234
|
+ zsPackage = dependency.getPackageOrNull(className);
|
|
235
|
+ if(zsPackage != null)
|
|
236
|
+ return zsPackage;
|
|
237
|
+ }
|
|
238
|
+
|
|
239
|
+ if(className.startsWith(this.basePackage))
|
|
240
|
+ return getPackage(className);
|
|
241
|
+ return null;
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+
|
219
|
245
|
private ZSPackage getPackage(String className) {
|
220
|
246
|
//TODO make a lang package?
|
221
|
247
|
if (!className.contains(".") || className.startsWith("java.lang"))
|
|
@@ -225,8 +251,12 @@ public class JavaNativeModule {
|
225
|
251
|
className = className.substring(1);
|
226
|
252
|
else if (className.startsWith(basePackage + "."))
|
227
|
253
|
className = className.substring(basePackage.length() + 1);
|
228
|
|
- else
|
229
|
|
- throw new IllegalArgumentException("Invalid class name: not in the given base package");
|
|
254
|
+ else {
|
|
255
|
+ ZSPackage zsPackage = getPackageOrNull(className);
|
|
256
|
+ if(zsPackage != null)
|
|
257
|
+ return zsPackage;
|
|
258
|
+ throw new IllegalArgumentException(String.format("Invalid class name: %s not in the given base package[%s]", className, this.basePackage));
|
|
259
|
+ }
|
230
|
260
|
|
231
|
261
|
String[] classNameParts = Strings.split(className, '.');
|
232
|
262
|
ZSPackage classPkg = pkg;
|