소스 검색

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

kindlich 5 년 전
부모
커밋
fa8a3588cb
No known key found for this signature in database
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
 			throw new IllegalArgumentException("Class must be public");
260
 			throw new IllegalArgumentException("Class must be public");
261
 		
261
 		
262
 		String className = cls.getName();
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
 		className = className.contains(".") ? className.substring(className.lastIndexOf('.') + 1) : className;
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
 			if (specifiedName.startsWith(".")) {
272
 			if (specifiedName.startsWith(".")) {
271
 				classPkg = getPackage(specifiedName);
273
 				classPkg = getPackage(specifiedName);
272
 				className = className.substring(className.lastIndexOf('.') + 1);
274
 				className = className.substring(className.lastIndexOf('.') + 1);
273
 			} else if (specifiedName.indexOf('.') >= 0) {
275
 			} else if (specifiedName.indexOf('.') >= 0) {
274
 				if (!specifiedName.startsWith(pkg.fullName))
276
 				if (!specifiedName.startsWith(pkg.fullName))
275
 					throw new IllegalArgumentException("Specified @Name as " + specifiedName + " but it's not in the module root package");
277
 					throw new IllegalArgumentException("Specified @Name as " + specifiedName + " but it's not in the module root package");
276
-				
278
+
277
 				classPkg = getPackage(basePackage + specifiedName.substring(pkg.fullName.length()));
279
 				classPkg = getPackage(basePackage + specifiedName.substring(pkg.fullName.length()));
278
 				className = className.substring(className.lastIndexOf('.') + 1);
280
 				className = className.substring(className.lastIndexOf('.') + 1);
279
 			} else {
281
 			} else {
280
-				className = name.value();
282
+				classPkg = getPackage(className);
283
+				className = nameAnnotation.value();
281
 			}
284
 			}
282
 		}
285
 		}
283
-		
286
+
284
 		TypeVariableContext context = new TypeVariableContext();
287
 		TypeVariableContext context = new TypeVariableContext();
285
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
288
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
286
 		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];
289
 		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];

Loading…
취소
저장