Преглед изворни кода

Oops I forgot these for the logging and some cleanup

kindlich пре 4 година
родитељ
комит
96f81433ef
No known key found for this signature in database

+ 37
- 14
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java Прегледај датотеку

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zencode.java;
7 7
 
8 8
 import org.openzen.zencode.shared.*;
9
+import org.openzen.zencode.shared.logging.*;
9 10
 import org.openzen.zenscript.codemodel.*;
10 11
 import org.openzen.zenscript.codemodel.annotations.*;
11 12
 import org.openzen.zenscript.codemodel.context.*;
@@ -27,6 +28,7 @@ import org.openzen.zenscript.parser.type.*;
27 28
 import stdlib.*;
28 29
 
29 30
 import java.io.*;
31
+import java.lang.annotation.*;
30 32
 import java.lang.reflect.*;
31 33
 import java.util.Arrays;
32 34
 import java.util.*;
@@ -49,9 +51,11 @@ public class JavaNativeModule {
49 51
 	private final TypeVariableContext context = new TypeVariableContext();
50 52
 
51 53
 	public final Map<String, ISymbol> globals = new HashMap<>();
52
-	private BracketExpressionParser bep;
53
-
54
-	public JavaNativeModule(
54
+    private final IZSLogger logger;
55
+    private BracketExpressionParser bep;
56
+    
57
+    public JavaNativeModule(
58
+	        IZSLogger logger,
55 59
 			ZSPackage pkg,
56 60
 			String name,
57 61
 			String basePackage,
@@ -61,7 +65,8 @@ public class JavaNativeModule {
61 65
 		this.basePackage = basePackage;
62 66
 		module = new Module(name);
63 67
 		this.registry = registry;
64
-        
68
+        this.logger = logger;
69
+    
65 70
         compiled = new JavaCompiledModule(module, FunctionParameter.NONE);
66 71
         
67 72
 		for (JavaNativeModule dependency : dependencies) {
@@ -110,7 +115,7 @@ public class JavaNativeModule {
110 115
 				space.registry,
111 116
 				space.collectExpansions(),
112 117
 				space.getAnnotations(),
113
-				space.getStorageTypes());
118
+				space.getStorageTypes(), logger);
114 119
 	}
115 120
 
116 121
 	public JavaCompiledModule getCompiled() {
@@ -125,9 +130,16 @@ public class JavaNativeModule {
125 130
 	}
126 131
 
127 132
 	public void addGlobals(Class<?> cls) {
128
-		HighLevelDefinition definition = new ClassDefinition(CodePosition.NATIVE, module, pkg, "__globals__", Modifiers.PUBLIC);
129
-		JavaClass jcls = JavaClass.fromInternalName(getInternalName(cls), JavaClass.Kind.CLASS);
130
-		compiled.setClassInfo(definition, jcls);
133
+	    HighLevelDefinition definition;
134
+	    JavaClass jcls;
135
+	    if(definitionByClass.containsKey(cls)) {
136
+	        definition = definitionByClass.get(cls);
137
+	        jcls = compiled.getClassInfo(definition);
138
+        } else {
139
+	        definition = new ClassDefinition(CodePosition.NATIVE, module, pkg, "__globals__", Modifiers.PUBLIC);
140
+            jcls = JavaClass.fromInternalName(getInternalName(cls), JavaClass.Kind.CLASS);
141
+            compiled.setClassInfo(definition, jcls);
142
+        }
131 143
 		StoredType thisType = registry.getForMyDefinition(definition).stored();
132 144
 		//TypeVariableContext context = new TypeVariableContext();
133 145
 
@@ -156,11 +168,24 @@ public class JavaNativeModule {
156 168
 
157 169
 			ZenCodeGlobals.Global global = method.getAnnotation(ZenCodeGlobals.Global.class);
158 170
 			String name = global.value().isEmpty() ? method.getName() : global.value();
159
-			MethodMember methodMember = new MethodMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, name, getHeader(context, method), null);
171
+			//MethodMember methodMember = new MethodMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, name, getHeader(context, method), null);
172
+			//definition.addMember(methodMember);
173
+			MethodMember methodMember = asMethod(context, definition, method, new ZenCodeType.Method(){
174
+                @Override
175
+                public String value() {
176
+                    return name;
177
+                }
178
+                
179
+                @Override
180
+                public Class<? extends Annotation> annotationType() {
181
+                    return ZenCodeType.Method.class;
182
+                }
183
+            });
160 184
 			definition.addMember(methodMember);
161 185
 
162
-			boolean isGenericResult = methodMember.header.getReturnType().isGeneric();
163
-			compiled.setMethodInfo(methodMember, new JavaMethod(jcls, JavaMethod.Kind.STATIC, method.getName(), false, getMethodDescriptor(method), method.getModifiers(), isGenericResult));
186
+			//boolean isGenericResult = methodMember.header.getReturnType().isGeneric();
187
+			//compiled.setMethodInfo(methodMember, new JavaMethod(jcls, JavaMethod.Kind.STATIC, method.getName(), false, getMethodDescriptor(method), method.getModifiers(), isGenericResult));
188
+            compiled.setMethodInfo(methodMember, getMethod(jcls, method, loadType(context, method.getAnnotatedReturnType())));
164 189
 			globals.put(name, new ExpressionSymbol((position, scope) -> {
165 190
 				TypeMembers members = scope.getTypeMembers(thisType);
166 191
 				return new PartialStaticMemberGroupExpression(position, scope, thisType.type, members.getGroup(name), StoredType.NONE);
@@ -465,9 +490,7 @@ public class JavaNativeModule {
465 490
 				//Log?
466 491
 				continue;
467 492
 			}
468
-
469
-//			if(!method.isAnnotationPresent(ZenCodeType.Method.class))
470
-//				continue;
493
+			
471 494
 
472 495
 			final Class<?> classFromType = getClassFromType(expandedType);
473 496
 			if(classFromType == null) {

Loading…
Откажи
Сачувај