Browse Source

Oops I forgot these for the logging and some cleanup

kindlich 4 years ago
parent
commit
96f81433ef
No known key found for this signature in database

+ 37
- 14
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

6
 package org.openzen.zencode.java;
6
 package org.openzen.zencode.java;
7
 
7
 
8
 import org.openzen.zencode.shared.*;
8
 import org.openzen.zencode.shared.*;
9
+import org.openzen.zencode.shared.logging.*;
9
 import org.openzen.zenscript.codemodel.*;
10
 import org.openzen.zenscript.codemodel.*;
10
 import org.openzen.zenscript.codemodel.annotations.*;
11
 import org.openzen.zenscript.codemodel.annotations.*;
11
 import org.openzen.zenscript.codemodel.context.*;
12
 import org.openzen.zenscript.codemodel.context.*;
27
 import stdlib.*;
28
 import stdlib.*;
28
 
29
 
29
 import java.io.*;
30
 import java.io.*;
31
+import java.lang.annotation.*;
30
 import java.lang.reflect.*;
32
 import java.lang.reflect.*;
31
 import java.util.Arrays;
33
 import java.util.Arrays;
32
 import java.util.*;
34
 import java.util.*;
49
 	private final TypeVariableContext context = new TypeVariableContext();
51
 	private final TypeVariableContext context = new TypeVariableContext();
50
 
52
 
51
 	public final Map<String, ISymbol> globals = new HashMap<>();
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
 			ZSPackage pkg,
59
 			ZSPackage pkg,
56
 			String name,
60
 			String name,
57
 			String basePackage,
61
 			String basePackage,
61
 		this.basePackage = basePackage;
65
 		this.basePackage = basePackage;
62
 		module = new Module(name);
66
 		module = new Module(name);
63
 		this.registry = registry;
67
 		this.registry = registry;
64
-        
68
+        this.logger = logger;
69
+    
65
         compiled = new JavaCompiledModule(module, FunctionParameter.NONE);
70
         compiled = new JavaCompiledModule(module, FunctionParameter.NONE);
66
         
71
         
67
 		for (JavaNativeModule dependency : dependencies) {
72
 		for (JavaNativeModule dependency : dependencies) {
110
 				space.registry,
115
 				space.registry,
111
 				space.collectExpansions(),
116
 				space.collectExpansions(),
112
 				space.getAnnotations(),
117
 				space.getAnnotations(),
113
-				space.getStorageTypes());
118
+				space.getStorageTypes(), logger);
114
 	}
119
 	}
115
 
120
 
116
 	public JavaCompiledModule getCompiled() {
121
 	public JavaCompiledModule getCompiled() {
125
 	}
130
 	}
126
 
131
 
127
 	public void addGlobals(Class<?> cls) {
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
 		StoredType thisType = registry.getForMyDefinition(definition).stored();
143
 		StoredType thisType = registry.getForMyDefinition(definition).stored();
132
 		//TypeVariableContext context = new TypeVariableContext();
144
 		//TypeVariableContext context = new TypeVariableContext();
133
 
145
 
156
 
168
 
157
 			ZenCodeGlobals.Global global = method.getAnnotation(ZenCodeGlobals.Global.class);
169
 			ZenCodeGlobals.Global global = method.getAnnotation(ZenCodeGlobals.Global.class);
158
 			String name = global.value().isEmpty() ? method.getName() : global.value();
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
 			definition.addMember(methodMember);
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
 			globals.put(name, new ExpressionSymbol((position, scope) -> {
189
 			globals.put(name, new ExpressionSymbol((position, scope) -> {
165
 				TypeMembers members = scope.getTypeMembers(thisType);
190
 				TypeMembers members = scope.getTypeMembers(thisType);
166
 				return new PartialStaticMemberGroupExpression(position, scope, thisType.type, members.getGroup(name), StoredType.NONE);
191
 				return new PartialStaticMemberGroupExpression(position, scope, thisType.type, members.getGroup(name), StoredType.NONE);
465
 				//Log?
490
 				//Log?
466
 				continue;
491
 				continue;
467
 			}
492
 			}
468
-
469
-//			if(!method.isAnnotationPresent(ZenCodeType.Method.class))
470
-//				continue;
493
+			
471
 
494
 
472
 			final Class<?> classFromType = getClassFromType(expandedType);
495
 			final Class<?> classFromType = getClassFromType(expandedType);
473
 			if(classFromType == null) {
496
 			if(classFromType == null) {

Loading…
Cancel
Save