소스 검색

Merge remote-tracking branch 'kindlich/development' into development

Stan Hebben 6 년 전
부모
커밋
6d84156dfd

+ 8
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java 파일 보기

@@ -23,7 +23,10 @@ import org.openzen.zenscript.javashared.*;
23 23
 import java.io.FileOutputStream;
24 24
 import java.io.IOException;
25 25
 import java.lang.reflect.Modifier;
26
-import java.util.*;
26
+import java.util.Arrays;
27
+import java.util.Comparator;
28
+import java.util.Objects;
29
+import java.util.StringJoiner;
27 30
 
28 31
 public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativeTranslator<Void> {
29 32
 	private static final JavaMethod BOOLEAN_PARSE = JavaMethod.getNativeStatic(JavaClass.BOOLEAN, "parseBoolean", "(Ljava/lang/String;)Z");
@@ -374,12 +377,12 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
374 377
 		BuiltinID builtin = expression.member.getBuiltin();
375 378
 		if (builtin == null) {
376 379
 			expression.target.accept(this);
377
-			
380
+
378 381
 			JavaMethod methodInfo = context.getJavaMethod(expression.member);
379 382
 			for (int i = 0; i < expression.arguments.typeArguments.length; i++) {
380 383
 				if (methodInfo.typeParameterArguments[i]) {
381 384
 					StoredType arguments = expression.arguments.typeArguments[i];
382
-					
385
+
383 386
 				}
384 387
 			}
385 388
 			for (Expression argument : expression.arguments.arguments) {
@@ -3988,6 +3991,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3988 3991
 			getJavaWriter().invokeInterface(methodInfo);
3989 3992
 		} else if (methodInfo.kind == JavaMethod.Kind.COMPILED) {
3990 3993
 			Objects.requireNonNull(methodInfo.translation).translate(expression, this);
3994
+		} else if (methodInfo.cls.kind == JavaClass.Kind.INTERFACE) {
3995
+			getJavaWriter().invokeInterface(methodInfo);
3991 3996
 		} else {
3992 3997
 			getJavaWriter().invokeVirtual(methodInfo);
3993 3998
 		}

+ 10
- 14
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java 파일 보기

@@ -62,7 +62,6 @@ import org.openzen.zenscript.javashared.JavaMethod;
62 62
 import stdlib.Strings;
63 63
 
64 64
 /**
65
- *
66 65
  * @author Stan Hebben
67 66
  */
68 67
 public class JavaNativeModule {
@@ -84,8 +83,7 @@ public class JavaNativeModule {
84 83
 			String name,
85 84
 			String basePackage,
86 85
 			GlobalTypeRegistry registry,
87
-			JavaNativeModule[] dependencies)
88
-	{
86
+			JavaNativeModule[] dependencies) {
89 87
 		this.pkg = pkg;
90 88
 		this.basePackage = basePackage;
91 89
 		module = new Module(name);
@@ -214,7 +212,8 @@ public class JavaNativeModule {
214 212
 	}
215 213
 	
216 214
 	private ZSPackage getPackage(String className) {
217
-		if (!className.contains("."))
215
+		//TODO make a lang package?
216
+		if (!className.contains(".") || className.startsWith("java.lang"))
218 217
 			return pkg;
219 218
 		
220 219
 		if (className.startsWith("."))
@@ -296,10 +295,8 @@ public class JavaNativeModule {
296 295
 				continue;
297 296
 			if (!isPublic(field.getModifiers()))
298 297
 				continue;
299
-
300
-			String fieldName = field.getName();
301
-			if (annotation != null && !annotation.value().isEmpty())
302
-				fieldName = annotation.value();
298
+			
299
+			final String fieldName = annotation.value().isEmpty() ? field.getName() : annotation.value();
303 300
 			
304 301
 			StoredType fieldType = loadStoredType(field.getAnnotatedType());
305 302
 			FieldMember member = new FieldMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC, fieldName, thisType, fieldType, registry, 0, 0, null);
@@ -309,7 +306,7 @@ public class JavaNativeModule {
309 306
 		
310 307
 		boolean hasConstructor = false;
311 308
 		for (java.lang.reflect.Constructor constructor : cls.getConstructors()) {
312
-			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor)constructor.getAnnotation(ZenCodeType.Constructor.class);
309
+			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor) constructor.getAnnotation(ZenCodeType.Constructor.class);
313 310
 			if (constructorAnnotation != null) {
314 311
 				ConstructorMember member = asConstructor(definition, constructor);
315 312
 				definition.addMember(member);
@@ -487,8 +484,7 @@ public class JavaNativeModule {
487 484
 			AnnotatedType javaReturnType,
488 485
 			AnnotatedType[] parameterTypes,
489 486
 			TypeVariable<Method>[] javaTypeParameters,
490
-			AnnotatedType[] exceptionTypes)
491
-	{
487
+			AnnotatedType[] exceptionTypes) {
492 488
 		StoredType returnType = javaReturnType == null ? BasicTypeID.VOID.stored : loadStoredType(javaReturnType);
493 489
 		
494 490
 		FunctionParameter[] parameters = new FunctionParameter[parameterTypes.length];
@@ -532,7 +528,7 @@ public class JavaNativeModule {
532 528
 	
533 529
 	private TypeID loadType(Type type, boolean nullable, boolean unsigned) {
534 530
 		if (type instanceof Class) {
535
-			Class<?> classType = (Class<?>)type;
531
+			Class<?> classType = (Class<?>) type;
536 532
 			if (unsigned) {
537 533
 				if (unsignedByClass.containsKey(classType))
538 534
 					return unsignedByClass.get(classType);
@@ -548,8 +544,8 @@ public class JavaNativeModule {
548 544
 			HighLevelDefinition definition = addClass(classType);
549 545
 			return registry.getForDefinition(definition);
550 546
 		} else if (type instanceof ParameterizedType) {
551
-			ParameterizedType parameterizedType = (ParameterizedType)type;
552
-			Class<?> rawType = (Class)parameterizedType.getRawType();
547
+			ParameterizedType parameterizedType = (ParameterizedType) type;
548
+			Class<?> rawType = (Class) parameterizedType.getRawType();
553 549
 			
554 550
 			HighLevelDefinition definition = addClass(rawType);
555 551
 			Type[] parameters = parameterizedType.getActualTypeArguments();

Loading…
취소
저장