Browse Source

[WIP] Duplicate class names, pt. II

Fixed functions not working properly
kindlich 5 years ago
parent
commit
c4acf675e8
No known key found for this signature in database

+ 3
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java View File

48
 		context.addModule(module.module, target);
48
 		context.addModule(module.module, target);
49
 		
49
 		
50
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
50
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
51
-			String filename = getFilename(definition) + "_" + (definition.name == null ? "generated" : definition.name) + "_" + expansionCounter++;
52
-			JavaPrepareDefinitionVisitor definitionPreparer = new JavaPrepareDefinitionVisitor(context, target, filename, null);
51
+			final String className = getFilename(definition);
52
+			String filename = className + "_" + (definition.name == null ? "generated" : definition.name) + "_" + expansionCounter++;
53
+			JavaPrepareDefinitionVisitor definitionPreparer = new JavaPrepareDefinitionVisitor(context, target, filename, null, className);
53
 			definition.accept(definitionPreparer);
54
 			definition.accept(definitionPreparer);
54
 		}
55
 		}
55
 		
56
 		

+ 1
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java View File

52
 	
52
 	
53
 	public static String getNameFromFile(String filename) {
53
 	public static String getNameFromFile(String filename) {
54
 		if (filename.indexOf('.') > 0)
54
 		if (filename.indexOf('.') > 0)
55
-			return filename.substring(0, filename.indexOf('.'));
55
+			return filename.substring(0, filename.lastIndexOf('.'));
56
 		else
56
 		else
57
 			return filename;
57
 			return filename;
58
 	}
58
 	}

+ 10
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java View File

73
 			JavaNativeClass list = new JavaNativeClass(new JavaClass("java.util", "List", JavaClass.Kind.INTERFACE));
73
 			JavaNativeClass list = new JavaNativeClass(new JavaClass("java.util", "List", JavaClass.Kind.INTERFACE));
74
 			JavaClass arrayList = new JavaClass("java.util", "ArrayList", JavaClass.Kind.CLASS);
74
 			JavaClass arrayList = new JavaClass("java.util", "ArrayList", JavaClass.Kind.CLASS);
75
 			list.addMethod("constructor", JavaMethod.getNativeConstructor(arrayList, "()V"));
75
 			list.addMethod("constructor", JavaMethod.getNativeConstructor(arrayList, "()V"));
76
-			list.addInstanceMethod("add", "add", "(Ljava/lang/Object;)Z"); List<?> l;
76
+			list.addInstanceMethod("add", "add", "(Ljava/lang/Object;)Z");
77
 			list.addInstanceMethod("insert", "add", "(Ljava/lang/Object;I)V");
77
 			list.addInstanceMethod("insert", "add", "(Ljava/lang/Object;I)V");
78
 			list.addInstanceMethod("remove", "remove", "(Ljava/lang/Object;)Z");
78
 			list.addInstanceMethod("remove", "remove", "(Ljava/lang/Object;)Z");
79
 			list.addInstanceMethod("indexOf", "indexOf", "(Ljava/lang/Object;)I");
79
 			list.addInstanceMethod("indexOf", "indexOf", "(Ljava/lang/Object;)I");
236
 	
236
 	
237
 	private final JavaContext context;
237
 	private final JavaContext context;
238
 	private final String filename;
238
 	private final String filename;
239
+	private final String className;
239
 	private final JavaClass outerClass;
240
 	private final JavaClass outerClass;
240
 	private final JavaCompiledModule module;
241
 	private final JavaCompiledModule module;
241
-	
242
+
242
 	public JavaPrepareDefinitionVisitor(JavaContext context, JavaCompiledModule module, String filename, JavaClass outerClass) {
243
 	public JavaPrepareDefinitionVisitor(JavaContext context, JavaCompiledModule module, String filename, JavaClass outerClass) {
244
+		this(context, module, filename, outerClass, JavaClass.getNameFromFile(filename));
245
+	}
246
+
247
+	public JavaPrepareDefinitionVisitor(JavaContext context, JavaCompiledModule module, String filename, JavaClass outerClass, String className) {
243
 		this.context = context;
248
 		this.context = context;
244
 		this.filename = filename;
249
 		this.filename = filename;
245
 		this.outerClass = outerClass;
250
 		this.outerClass = outerClass;
246
 		this.module = module;
251
 		this.module = module;
252
+		this.className = className;
247
 	}
253
 	}
248
 	
254
 	
249
 	private boolean isPrepared(HighLevelDefinition definition) {
255
 	private boolean isPrepared(HighLevelDefinition definition) {
298
 		if (isPrepared(definition))
304
 		if (isPrepared(definition))
299
 			return context.getJavaClass(definition);
305
 			return context.getJavaClass(definition);
300
 		
306
 		
301
-		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
307
+		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), className, JavaClass.Kind.CLASS);
302
 		context.setJavaClass(definition, cls);
308
 		context.setJavaClass(definition, cls);
303
 		return cls;
309
 		return cls;
304
 	}
310
 	}
313
 			context.setJavaNativeClass(definition, nativeClasses.get(nativeTag.value));
319
 			context.setJavaNativeClass(definition, nativeClasses.get(nativeTag.value));
314
 		}
320
 		}
315
 		
321
 		
316
-		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
322
+		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), className, JavaClass.Kind.CLASS);
317
 		context.setJavaClass(definition, cls);
323
 		context.setJavaClass(definition, cls);
318
 		return cls;
324
 		return cls;
319
 	}
325
 	}

Loading…
Cancel
Save