Browse Source

Minor code reformat

kindlich 6 years ago
parent
commit
75785f413f
No known key found for this signature in database

+ 10
- 14
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

60
 import stdlib.Strings;
60
 import stdlib.Strings;
61
 
61
 
62
 /**
62
 /**
63
- *
64
  * @author Stan Hebben
63
  * @author Stan Hebben
65
  */
64
  */
66
 public class JavaNativeModule {
65
 public class JavaNativeModule {
82
 			String name,
81
 			String name,
83
 			String basePackage,
82
 			String basePackage,
84
 			GlobalTypeRegistry registry,
83
 			GlobalTypeRegistry registry,
85
-			JavaNativeModule[] dependencies)
86
-	{
84
+			JavaNativeModule[] dependencies) {
87
 		this.pkg = pkg;
85
 		this.pkg = pkg;
88
 		this.basePackage = basePackage;
86
 		this.basePackage = basePackage;
89
 		module = new Module(name);
87
 		module = new Module(name);
208
 	}
206
 	}
209
 	
207
 	
210
 	private ZSPackage getPackage(String className) {
208
 	private ZSPackage getPackage(String className) {
211
-		if (!className.contains("."))
209
+		//TODO make a lang package?
210
+		if (!className.contains(".") || className.startsWith("java.lang"))
212
 			return pkg;
211
 			return pkg;
213
 		
212
 		
214
 		if (className.startsWith("."))
213
 		if (className.startsWith("."))
277
 				continue;
276
 				continue;
278
 			if (!isPublic(field.getModifiers()))
277
 			if (!isPublic(field.getModifiers()))
279
 				continue;
278
 				continue;
280
-
281
-			String fieldName = field.getName();
282
-			if (annotation != null && !annotation.value().isEmpty())
283
-				fieldName = annotation.value();
279
+			
280
+			final String fieldName = annotation.value().isEmpty() ? field.getName() : annotation.value();
284
 			
281
 			
285
 			StoredType fieldType = loadStoredType(field.getAnnotatedType());
282
 			StoredType fieldType = loadStoredType(field.getAnnotatedType());
286
 			FieldMember member = new FieldMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC, fieldName, thisType, fieldType, registry, 0, 0, null);
283
 			FieldMember member = new FieldMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC, fieldName, thisType, fieldType, registry, 0, 0, null);
290
 		
287
 		
291
 		boolean hasConstructor = false;
288
 		boolean hasConstructor = false;
292
 		for (java.lang.reflect.Constructor constructor : cls.getConstructors()) {
289
 		for (java.lang.reflect.Constructor constructor : cls.getConstructors()) {
293
-			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor)constructor.getAnnotation(ZenCodeType.Constructor.class);
290
+			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor) constructor.getAnnotation(ZenCodeType.Constructor.class);
294
 			if (constructorAnnotation != null) {
291
 			if (constructorAnnotation != null) {
295
 				ConstructorMember member = asConstructor(definition, constructor);
292
 				ConstructorMember member = asConstructor(definition, constructor);
296
 				definition.addMember(member);
293
 				definition.addMember(member);
468
 			AnnotatedType javaReturnType,
465
 			AnnotatedType javaReturnType,
469
 			AnnotatedType[] parameterTypes,
466
 			AnnotatedType[] parameterTypes,
470
 			TypeVariable<Method>[] javaTypeParameters,
467
 			TypeVariable<Method>[] javaTypeParameters,
471
-			AnnotatedType[] exceptionTypes)
472
-	{
468
+			AnnotatedType[] exceptionTypes) {
473
 		StoredType returnType = javaReturnType == null ? BasicTypeID.VOID.stored : loadStoredType(javaReturnType);
469
 		StoredType returnType = javaReturnType == null ? BasicTypeID.VOID.stored : loadStoredType(javaReturnType);
474
 		
470
 		
475
 		FunctionParameter[] parameters = new FunctionParameter[parameterTypes.length];
471
 		FunctionParameter[] parameters = new FunctionParameter[parameterTypes.length];
513
 	
509
 	
514
 	private TypeID loadType(Type type, boolean nullable, boolean unsigned) {
510
 	private TypeID loadType(Type type, boolean nullable, boolean unsigned) {
515
 		if (type instanceof Class) {
511
 		if (type instanceof Class) {
516
-			Class<?> classType = (Class<?>)type;
512
+			Class<?> classType = (Class<?>) type;
517
 			if (unsigned) {
513
 			if (unsigned) {
518
 				if (unsignedByClass.containsKey(classType))
514
 				if (unsignedByClass.containsKey(classType))
519
 					return unsignedByClass.get(classType);
515
 					return unsignedByClass.get(classType);
529
 			HighLevelDefinition definition = addClass(classType);
525
 			HighLevelDefinition definition = addClass(classType);
530
 			return registry.getForDefinition(definition);
526
 			return registry.getForDefinition(definition);
531
 		} else if (type instanceof ParameterizedType) {
527
 		} else if (type instanceof ParameterizedType) {
532
-			ParameterizedType parameterizedType = (ParameterizedType)type;
533
-			Class<?> rawType = (Class)parameterizedType.getRawType();
528
+			ParameterizedType parameterizedType = (ParameterizedType) type;
529
+			Class<?> rawType = (Class) parameterizedType.getRawType();
534
 			
530
 			
535
 			HighLevelDefinition definition = addClass(rawType);
531
 			HighLevelDefinition definition = addClass(rawType);
536
 			Type[] parameters = parameterizedType.getActualTypeArguments();
532
 			Type[] parameters = parameterizedType.getActualTypeArguments();

Loading…
Cancel
Save