소스 검색

Enums now are registered to their class package, fields use the correct modifiers

TODO: Verify that the access check is correct
kindlich 5 년 전
부모
커밋
b34bdf376a
No known key found for this signature in database

+ 7
- 11
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java 파일 보기

@@ -5,13 +5,7 @@
5 5
  */
6 6
 package org.openzen.zencode.java;
7 7
 
8
-import java.lang.reflect.AnnotatedType;
9
-import java.lang.reflect.Field;
10
-import java.lang.reflect.Method;
11
-import java.lang.reflect.Modifier;
12
-import java.lang.reflect.ParameterizedType;
13
-import java.lang.reflect.Type;
14
-import java.lang.reflect.TypeVariable;
8
+import java.lang.reflect.*;
15 9
 import java.util.Collections;
16 10
 import java.util.HashMap;
17 11
 import java.util.Map;
@@ -55,6 +49,7 @@ import org.openzen.zenscript.codemodel.type.member.BuiltinID;
55 49
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
56 50
 import org.openzen.zenscript.codemodel.type.storage.AutoStorageTag;
57 51
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
52
+import org.openzen.zenscript.javabytecode.compiler.CompilerUtils;
58 53
 import org.openzen.zenscript.javashared.JavaClass;
59 54
 import org.openzen.zenscript.javashared.JavaCompiledModule;
60 55
 import org.openzen.zenscript.javashared.JavaField;
@@ -286,10 +281,10 @@ public class JavaNativeModule {
286 281
 			definition = new InterfaceDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
287 282
 			javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.INTERFACE);
288 283
 		} else if (cls.isEnum()) {
289
-			definition = new EnumDefinition(CodePosition.NATIVE, module, pkg, className, Modifiers.PUBLIC, null);
284
+			definition = new EnumDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
290 285
 			javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.ENUM);
291 286
 		} else if (isStruct) {
292
-			definition = new StructDefinition(CodePosition.NATIVE, module, pkg, className, Modifiers.PUBLIC, null);
287
+			definition = new StructDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
293 288
 			javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.CLASS);
294 289
 		} else {
295 290
 			definition = new ClassDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC);
@@ -324,7 +319,8 @@ public class JavaNativeModule {
324 319
 			final String fieldName = annotation.value().isEmpty() ? field.getName() : annotation.value();
325 320
 			
326 321
 			StoredType fieldType = loadStoredType(context, field.getAnnotatedType());
327
-			FieldMember member = new FieldMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC, fieldName, thisType, fieldType, registry, 0, 0, null);
322
+			
323
+			FieldMember member = new FieldMember(CodePosition.NATIVE, definition, getMethodModifiers(field), fieldName, thisType, fieldType, registry, 0, 0, null);
328 324
 			definition.addMember(member);
329 325
 			compiled.setFieldInfo(member, new JavaField(javaClass, field.getName(), getDescriptor(field.getType())));
330 326
 		}
@@ -659,7 +655,7 @@ public class JavaNativeModule {
659 655
 		return null;
660 656
 	}
661 657
 	
662
-	private int getMethodModifiers(Method method) {
658
+	private int getMethodModifiers(Member method) {
663 659
 		int result = Modifiers.PUBLIC;
664 660
 		if (isStatic(method.getModifiers()))
665 661
 			result |= Modifiers.STATIC;

+ 2
- 2
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java 파일 보기

@@ -739,8 +739,8 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
739 739
 	}
740 740
 
741 741
 	private void checkFieldAccess(CodePosition position, FieldMemberRef field) {
742
-		if (!scope.getAccessScope().hasAccessTo(field.getTarget().getAccessScope(), Modifiers.PRIVATE))
743
-			validator.logError(ValidationLogEntry.Code.NO_ACCESS, position, "fields are private");
742
+		if (!scope.getAccessScope().hasAccessTo(field.getTarget().getAccessScope(), field.getTarget().getEffectiveModifiers()))
743
+			validator.logError(ValidationLogEntry.Code.NO_ACCESS, position, "no field access to " + field.describe());
744 744
 	}
745 745
 	
746 746
 	private void checkStatic(CodePosition position, DefinitionMemberRef member) {

Loading…
취소
저장