Stan Hebben преди 5 години
родител
ревизия
d151b5ef99

+ 25
- 2
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java Целия файл

@@ -240,12 +240,27 @@ public class JavaNativeModule {
240 240
 		if ((cls.getModifiers() & Modifier.PUBLIC) == 0)
241 241
 			throw new IllegalArgumentException("Class must be public");
242 242
 		
243
-		ZenCodeType.Name name = cls.getDeclaredAnnotation(ZenCodeType.Name.class);
244
-		String className = name == null ? cls.getName() : name.value();
243
+		String className = cls.getName();
245 244
 		boolean isStruct = cls.getAnnotation(ZenCodeType.Struct.class) != null;
246 245
 		
247 246
 		ZSPackage classPkg = getPackage(className);
247
+		ZenCodeType.Name name = cls.getDeclaredAnnotation(ZenCodeType.Name.class);
248 248
 		className = className.contains(".") ? className.substring(className.lastIndexOf('.') + 1) : className;
249
+		if (name != null) {
250
+			String specifiedName = name.value();
251
+			if (specifiedName.startsWith(".")) {
252
+				classPkg = getPackage(specifiedName);
253
+				className = className.substring(className.lastIndexOf('.') + 1);
254
+			} else if (specifiedName.indexOf('.') >= 0) {
255
+				if (!specifiedName.startsWith(pkg.fullName))
256
+					throw new IllegalArgumentException("Specified @Name as " + specifiedName + " but it's not in the module root package");
257
+				
258
+				classPkg = getPackage(basePackage + specifiedName.substring(pkg.fullName.length()));
259
+				className = className.substring(className.lastIndexOf('.') + 1);
260
+			} else {
261
+				className = name.value();
262
+			}
263
+		}
249 264
 		
250 265
 		TypeVariableContext context = new TypeVariableContext();
251 266
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
@@ -546,6 +561,14 @@ public class JavaNativeModule {
546 561
 	}
547 562
 	
548 563
 	private StoredType loadType(TypeVariableContext context, Type type, boolean nullable, boolean unsigned) {
564
+		StoredType result = loadType(context, type, unsigned);
565
+		if (nullable)
566
+			result = new StoredType(registry.getOptional(result.type), result.getSpecifiedStorage());
567
+		
568
+		return result;
569
+	}
570
+	
571
+	private StoredType loadType(TypeVariableContext context, Type type, boolean unsigned) {
549 572
 		if (type instanceof Class) {
550 573
 			Class<?> classType = (Class<?>) type;
551 574
 			if (unsigned) {

+ 12
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Globals.java Целия файл

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.scriptingexample;
7 7
 
8 8
 import org.openzen.zencode.java.ZenCodeGlobals;
9
+import static org.openzen.zencode.java.ZenCodeType.*;
9 10
 
10 11
 /**
11 12
  *
@@ -57,6 +58,12 @@ public class Globals implements ZenCodeGlobals {
57 58
 		System.out.println("FunctionalInt: " + calculator.doSomething(7, 13));
58 59
 	}
59 60
 	
61
+	@Global
62
+	public static void testOptional(MyOptionalInterface function) {
63
+		System.out.println("Null: " + function.doSomething(null));
64
+		System.out.println("Hello: " + function.doSomething("hello"));
65
+	}
66
+	
60 67
 	public static TestClass bracket(String value) {
61 68
 		return new TestClass(value);
62 69
 	}
@@ -70,4 +77,9 @@ public class Globals implements ZenCodeGlobals {
70 77
 	public static interface MyFunctionalInterfaceInt {
71 78
 		int doSomething(int valueA, int valueB);
72 79
 	}
80
+	
81
+	@FunctionalInterface
82
+	public static interface MyOptionalInterface {
83
+		int doSomething(@Nullable String value);
84
+	}
73 85
 }

+ 1
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java Целия файл

@@ -286,6 +286,7 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
286 286
 
287 287
 	@Override
288 288
 	public Void visitFunction(FunctionExpression expression) {
289
+		
289 290
 		// TODO
290 291
 		return null;
291 292
 	}

Loading…
Отказ
Запис