Browse Source

- Fix auto getters & setters for static fields not being static

- Fix getters for globals not having their corresponding fields registered correctly in the native implementation
- Added java sources for JavaScripting
Stan Hebben 5 years ago
parent
commit
b434566f11

+ 4
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.member;
6
 package org.openzen.zenscript.codemodel.member;
7
 
7
 
8
-import java.lang.reflect.Modifier;
9
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Modifiers;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
14
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
15
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
15
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
65
 				parameters[i] = registry.getGeneric(definition.typeParameters[i]);
65
 				parameters[i] = registry.getGeneric(definition.typeParameters[i]);
66
 		}
66
 		}
67
 		
67
 		
68
+		int autoMemberModifiers = modifiers & Modifiers.STATIC;
68
 		if (autoGetterAccess != 0) {
69
 		if (autoGetterAccess != 0) {
69
-			this.autoGetter = new GetterMember(position, definition, autoGetterAccess, name, type, null);
70
+			this.autoGetter = new GetterMember(position, definition, autoGetterAccess | autoMemberModifiers, name, type, null);
70
 			this.autoGetter.setBody(new ReturnStatement(position, new GetFieldExpression(
71
 			this.autoGetter.setBody(new ReturnStatement(position, new GetFieldExpression(
71
 					position,
72
 					position,
72
 					new ThisExpression(position, thisType),
73
 					new ThisExpression(position, thisType),
75
 			this.autoGetter = null;
76
 			this.autoGetter = null;
76
 		}
77
 		}
77
 		if (autoSetterAccess != 0) {
78
 		if (autoSetterAccess != 0) {
78
-			this.autoSetter = new SetterMember(position, definition, autoSetterAccess, name, type, null);
79
+			this.autoSetter = new SetterMember(position, definition, autoSetterAccess | autoMemberModifiers, name, type, null);
79
 			this.autoSetter.setBody(new ExpressionStatement(position, new SetFieldExpression(
80
 			this.autoSetter.setBody(new ExpressionStatement(position, new SetFieldExpression(
80
 					position,
81
 					position,
81
 					new ThisExpression(position, thisType),
82
 					new ThisExpression(position, thisType),

+ 3
- 1
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

167
 			String name = global.value().isEmpty() ? field.getName() : global.value();
167
 			String name = global.value().isEmpty() ? field.getName() : global.value();
168
 			FieldMember fieldMember = new FieldMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, name, thisType, type, registry, Modifiers.PUBLIC, 0, null);
168
 			FieldMember fieldMember = new FieldMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, name, thisType, type, registry, Modifiers.PUBLIC, 0, null);
169
 			definition.addMember(fieldMember);
169
 			definition.addMember(fieldMember);
170
-			compiled.setFieldInfo(fieldMember, new JavaField(jcls, name, getDescriptor(field.getType())));
170
+			JavaField javaField = new JavaField(jcls, name, getDescriptor(field.getType()));
171
+			compiled.setFieldInfo(fieldMember, javaField);
172
+			compiled.setFieldInfo(fieldMember.autoGetter, javaField);
171
 			globals.put(name, new ExpressionSymbol((position, scope) -> new StaticGetterExpression(CodePosition.BUILTIN, fieldMember.autoGetter.ref(thisType, GenericMapper.EMPTY))));
173
 			globals.put(name, new ExpressionSymbol((position, scope) -> new StaticGetterExpression(CodePosition.BUILTIN, fieldMember.autoGetter.ref(thisType, GenericMapper.EMPTY))));
172
 		}
174
 		}
173
 		
175
 		

+ 3
- 1
JavaScripting/build.gradle View File

12
 	dependsOn javaScriptingProjects.collect{ it+":compileJava"}
12
 	dependsOn javaScriptingProjects.collect{ it+":compileJava"}
13
     from files(javaScriptingProjects.collect{ project(it).sourceSets.main.output })
13
     from files(javaScriptingProjects.collect{ project(it).sourceSets.main.output })
14
 }
14
 }
15
-
15
+sourcesJar {
16
+    from files(javaScriptingProjects.collect { project(it).sourceSets.main.allSource })
17
+}
16
 install {
18
 install {
17
 	repositories.mavenInstaller {
19
 	repositories.mavenInstaller {
18
 		pom.artifactId = 'zencode-javascripting'
20
 		pom.artifactId = 'zencode-javascripting'

+ 2
- 0
ScriptingExample/scripts/integration.zs View File

15
 
15
 
16
 val testInstance = new TestOperators();
16
 val testInstance = new TestOperators();
17
 //testInstance("something");
17
 //testInstance("something");
18
+
19
+something.dump();

+ 3
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Globals.java View File

14
 public class Globals implements ZenCodeGlobals {
14
 public class Globals implements ZenCodeGlobals {
15
 	private Globals() {}
15
 	private Globals() {}
16
 	
16
 	
17
+	@Global
18
+	public static TestClass something = new TestClass("hello");
19
+	
17
 	@Global
20
 	@Global
18
 	public static void println(String message) {
21
 	public static void println(String message) {
19
 		System.out.println(message);
22
 		System.out.println(message);

+ 4
- 2
common.gradle View File

6
 apply plugin: 'maven'
6
 apply plugin: 'maven'
7
 
7
 
8
 String mavenGroupId = 'org.openzen.zencode'
8
 String mavenGroupId = 'org.openzen.zencode'
9
-String mavenVersion = '0.3.0'
9
+String mavenVersion = '0.3.1'
10
 
10
 
11
 sourceCompatibility = '1.8'
11
 sourceCompatibility = '1.8'
12
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
12
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
23
 
23
 
24
 group = mavenGroupId
24
 group = mavenGroupId
25
 version = mavenVersion
25
 version = mavenVersion
26
-
27
 task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from the source files.') {
26
 task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from the source files.') {
28
     classifier = 'sources'
27
     classifier = 'sources'
29
     from sourceSets.main.allSource
28
     from sourceSets.main.allSource
30
 }
29
 }
30
+artifacts {
31
+	archives sourcesJar
32
+}
31
 
33
 
32
 configure(install.repositories.mavenInstaller) {
34
 configure(install.repositories.mavenInstaller) {
33
     pom.project {
35
     pom.project {

Loading…
Cancel
Save