瀏覽代碼

Fixed Exception for invalid package even if the class name was overriden using @Name

kindlich 5 年之前
父節點
當前提交
fa8a3588cb
沒有發現已知的金鑰在資料庫的簽署中
共有 1 個文件被更改,包括 11 次插入8 次删除
  1. 11
    8
      JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java

+ 11
- 8
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java 查看文件

@@ -260,27 +260,30 @@ public class JavaNativeModule {
260 260
 			throw new IllegalArgumentException("Class must be public");
261 261
 		
262 262
 		String className = cls.getName();
263
-		boolean isStruct = cls.getAnnotation(ZenCodeType.Struct.class) != null;
263
+		boolean isStruct = cls.isAnnotationPresent(ZenCodeType.Struct.class);
264 264
 		
265
-		ZSPackage classPkg = getPackage(className);
266
-		ZenCodeType.Name name = cls.getDeclaredAnnotation(ZenCodeType.Name.class);
265
+		ZSPackage classPkg;
266
+		ZenCodeType.Name nameAnnotation = cls.getDeclaredAnnotation(ZenCodeType.Name.class);
267 267
 		className = className.contains(".") ? className.substring(className.lastIndexOf('.') + 1) : className;
268
-		if (name != null) {
269
-			String specifiedName = name.value();
268
+		if (nameAnnotation == null) {
269
+			classPkg = getPackage(className);
270
+		} else {
271
+			String specifiedName = nameAnnotation.value();
270 272
 			if (specifiedName.startsWith(".")) {
271 273
 				classPkg = getPackage(specifiedName);
272 274
 				className = className.substring(className.lastIndexOf('.') + 1);
273 275
 			} else if (specifiedName.indexOf('.') >= 0) {
274 276
 				if (!specifiedName.startsWith(pkg.fullName))
275 277
 					throw new IllegalArgumentException("Specified @Name as " + specifiedName + " but it's not in the module root package");
276
-				
278
+
277 279
 				classPkg = getPackage(basePackage + specifiedName.substring(pkg.fullName.length()));
278 280
 				className = className.substring(className.lastIndexOf('.') + 1);
279 281
 			} else {
280
-				className = name.value();
282
+				classPkg = getPackage(className);
283
+				className = nameAnnotation.value();
281 284
 			}
282 285
 		}
283
-		
286
+
284 287
 		TypeVariableContext context = new TypeVariableContext();
285 288
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
286 289
 		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];

Loading…
取消
儲存