- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/FramsClassBuilder.java
r100 r101 5 5 import java.lang.reflect.Member; 6 6 import java.lang.reflect.Method; 7 import java.lang.reflect.ParameterizedType;8 import java.lang.reflect.Type;9 7 import java.util.ArrayList; 10 8 import java.util.Collections; … … 40 38 } 41 39 42 public static ParamBuilder induceParamType(ParamBuilder builder, Type type) {43 // if (type.equals(Void.TYPE)) {44 // throw new ConstructionException().msg("void is not a valid type");45 // }46 47 if (type instanceof ParameterizedType) {48 ParameterizedType p = (ParameterizedType) type;49 Type rawType = p.getRawType();50 Type containedType = null;51 //TODO make implementation here52 boolean map = false;53 StringBuilder b = new StringBuilder();54 if (rawType.equals(Map.class)) {55 containedType = p.getActualTypeArguments()[1];56 map = true;57 b.append("l");58 } else if (rawType.equals(List.class)) {59 containedType = p.getActualTypeArguments()[0];60 b.append("l");61 } else if (rawType.equals(EventListener.class)) {62 containedType = p.getActualTypeArguments()[0];63 b.append("e");64 }65 if (!(containedType instanceof Class)) {66 return builder;67 }68 b.append(" ");69 70 Class<?> containedClass = (Class<?>) containedType;71 FramsClassAnnotation fca = containedClass.getAnnotation(FramsClassAnnotation.class);72 if (fca == null) {73 throw new ConstructionException().msg("the contained class is not annotated").arg("class", containedClass);74 }75 b.append(getName(fca, containedClass));76 //TODO parametrize this77 if (map) {78 b.append(" uid");79 }80 81 builder.type(b.toString());82 return builder;83 }84 85 if (type instanceof Class) {86 87 Class<?> cl = (Class<?>) type;88 89 // TODO: future support for enum90 // if (cl.isEnum()) {91 // Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) cl;92 // Enum<?>[] enums = enumType.getEnumConstants();93 // StringBuilder b = new StringBuilder();94 95 // b.append("d 0 ").append(enums.length - 1).append(" 0 ");96 // for (Enum<?> e : enums) {97 // b.append("~").append(e.name());98 // }99 // return b.toString();100 // }101 if (cl.equals(Integer.class) || cl.equals(int.class)) {102 builder.type("d");103 return builder;104 }105 if (cl.equals(String.class)) {106 builder.type("s");107 return builder;108 }109 if (cl.equals(Double.class) || cl.equals(double.class)) {110 builder.type("f");111 return builder;112 }113 if (cl.equals(Boolean.class) || cl.equals(boolean.class)) {114 builder.type( "d 0 1");115 return builder;116 }117 if (cl.equals(Object.class)) {118 builder.type("x");119 return builder;120 }121 122 123 // builder.type("o " + (cl).getCanonicalName());124 builder.type("o " + cl.getSimpleName());125 builder.fillStorageType(cl);126 return builder;127 }128 129 throw new ConstructionException().msg("failed to find framsticks for native type").arg("type", type);130 }131 132 133 public static ParamBuilder induceParamType(ParamBuilder builder, ParamCandidate candidate) {134 Method method = candidate.getCaller();135 if (method == null) {136 return induceParamType(builder, candidate.getType());137 }138 139 if (!method.getReturnType().equals(Void.TYPE)) {140 builder.resultType(induceParamType(Param.build(), method.getGenericReturnType()).finish(ValueParam.class));141 }142 143 List<ValueParam> arguments = new ArrayList<>();144 int number = 0;145 for (Type arg : method.getGenericParameterTypes()) {146 arguments.add(induceParamType(Param.build(), arg).idAndName("arg" + (number++)).finish(ValueParam.class));147 }148 builder.argumentsType(arguments);149 150 return builder;151 }152 40 153 41 public static final String GENERATE_HELP_PREFIX = "automatically generated from: "; … … 238 126 ParamBuilder builder = Param.build().id(pc.getId()).name(pc.getName()).flags(pc.getFlags()); 239 127 240 induceParamType(builder, pc);128 pc.induceParamType(builder); 241 129 242 130 for (ParamAnnotation pa : pc.getAnnotations()) { … … 365 253 } 366 254 255 256 367 257 }
Note: See TracChangeset
for help on using the changeset viewer.