Просмотр исходного кода

- 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 лет назад
Родитель
Сommit
b434566f11

+ 4
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java Просмотреть файл

@@ -5,11 +5,11 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.member;
7 7
 
8
-import java.lang.reflect.Modifier;
9 8
 import org.openzen.zencode.shared.CodePosition;
10 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 10
 import org.openzen.zenscript.codemodel.GenericMapper;
12 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Modifiers;
13 13
 import org.openzen.zenscript.codemodel.expression.Expression;
14 14
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
15 15
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
@@ -65,8 +65,9 @@ public class FieldMember extends PropertyMember {
65 65
 				parameters[i] = registry.getGeneric(definition.typeParameters[i]);
66 66
 		}
67 67
 		
68
+		int autoMemberModifiers = modifiers & Modifiers.STATIC;
68 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 71
 			this.autoGetter.setBody(new ReturnStatement(position, new GetFieldExpression(
71 72
 					position,
72 73
 					new ThisExpression(position, thisType),
@@ -75,7 +76,7 @@ public class FieldMember extends PropertyMember {
75 76
 			this.autoGetter = null;
76 77
 		}
77 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 80
 			this.autoSetter.setBody(new ExpressionStatement(position, new SetFieldExpression(
80 81
 					position,
81 82
 					new ThisExpression(position, thisType),

+ 3
- 1
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java Просмотреть файл

@@ -167,7 +167,9 @@ public class JavaNativeModule {
167 167
 			String name = global.value().isEmpty() ? field.getName() : global.value();
168 168
 			FieldMember fieldMember = new FieldMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, name, thisType, type, registry, Modifiers.PUBLIC, 0, null);
169 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 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 Просмотреть файл

@@ -12,7 +12,9 @@ jar {
12 12
 	dependsOn javaScriptingProjects.collect{ it+":compileJava"}
13 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 18
 install {
17 19
 	repositories.mavenInstaller {
18 20
 		pom.artifactId = 'zencode-javascripting'

+ 2
- 0
ScriptingExample/scripts/integration.zs Просмотреть файл

@@ -15,3 +15,5 @@ class TestOperators {
15 15
 
16 16
 val testInstance = new TestOperators();
17 17
 //testInstance("something");
18
+
19
+something.dump();

+ 3
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Globals.java Просмотреть файл

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

+ 4
- 2
common.gradle Просмотреть файл

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

Загрузка…
Отмена
Сохранить