ソースを参照

[WIP] Duplicate class names, pt. II

Fixed functions not working properly
kindlich 4年前
コミット
c4acf675e8
この署名に対応する既知のキーがデータベースに存在しません

+ 3
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java ファイルの表示

@@ -48,8 +48,9 @@ public class JavaCompiler {
48 48
 		context.addModule(module.module, target);
49 49
 		
50 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 54
 			definition.accept(definitionPreparer);
54 55
 		}
55 56
 		

+ 1
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java ファイルの表示

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

+ 10
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java ファイルの表示

@@ -73,7 +73,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
73 73
 			JavaNativeClass list = new JavaNativeClass(new JavaClass("java.util", "List", JavaClass.Kind.INTERFACE));
74 74
 			JavaClass arrayList = new JavaClass("java.util", "ArrayList", JavaClass.Kind.CLASS);
75 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 77
 			list.addInstanceMethod("insert", "add", "(Ljava/lang/Object;I)V");
78 78
 			list.addInstanceMethod("remove", "remove", "(Ljava/lang/Object;)Z");
79 79
 			list.addInstanceMethod("indexOf", "indexOf", "(Ljava/lang/Object;)I");
@@ -236,14 +236,20 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
236 236
 	
237 237
 	private final JavaContext context;
238 238
 	private final String filename;
239
+	private final String className;
239 240
 	private final JavaClass outerClass;
240 241
 	private final JavaCompiledModule module;
241
-	
242
+
242 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 248
 		this.context = context;
244 249
 		this.filename = filename;
245 250
 		this.outerClass = outerClass;
246 251
 		this.module = module;
252
+		this.className = className;
247 253
 	}
248 254
 	
249 255
 	private boolean isPrepared(HighLevelDefinition definition) {
@@ -298,7 +304,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
298 304
 		if (isPrepared(definition))
299 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 308
 		context.setJavaClass(definition, cls);
303 309
 		return cls;
304 310
 	}
@@ -313,7 +319,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
313 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 323
 		context.setJavaClass(definition, cls);
318 324
 		return cls;
319 325
 	}

読み込み中…
キャンセル
保存