- Timestamp:
- 07/02/13 16:20:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/FramsClassBuilder.java
r88 r90 22 22 import com.framsticks.parsers.Loaders; 23 23 import com.framsticks.util.Builder; 24 import com.framsticks.util. FramsticksException;24 import com.framsticks.util.lang.Containers; 25 25 import com.framsticks.util.lang.Strings; 26 26 … … 38 38 } 39 39 40 public static String getParamTypeForNativeType(Type type) { 40 public static ParamBuilder induceParamType(ParamBuilder builder, Type type) { 41 41 42 if (type instanceof ParameterizedType) { 42 43 ParameterizedType p = (ParameterizedType) type; … … 52 53 } 53 54 if (!(containedType instanceof Class)) { 54 return null;55 return builder; 55 56 } 56 57 Class<?> containedClass = (Class<?>) containedType; … … 60 61 if (fca == null) { 61 62 log.error("the class is not annotated: " + containedClass); 62 return null;63 return builder; 63 64 } 64 65 b.append(getName(fca, containedClass)); … … 67 68 } 68 69 69 return b.toString(); 70 builder.type(b.toString()); 71 return builder; 70 72 } 71 73 … … 87 89 // } 88 90 if (cl.equals(Integer.class) || cl.equals(int.class)) { 89 return "d"; 91 builder.type("d"); 92 return builder; 90 93 } 91 94 if (cl.equals(String.class)) { 92 return "s"; 95 builder.type("s"); 96 return builder; 93 97 } 94 98 if (cl.equals(Double.class) || cl.equals(double.class)) { 95 return "f"; 99 builder.type("f"); 100 return builder; 96 101 } 97 102 if (cl.equals(Boolean.class) || cl.equals(boolean.class)) { 98 return "d 0 1"; 103 builder.type( "d 0 1"); 104 return builder; 99 105 } 100 106 if (cl.equals(Object.class)) { 101 return "x"; 102 } 103 104 return "o " + ((Class<?>) type).getCanonicalName(); 107 builder.type("x"); 108 return builder; 109 } 110 111 // builder.type("o " + (cl).getCanonicalName()); 112 builder.type("o " + cl.getSimpleName()); 113 builder.fillStorageType(cl); 114 return builder; 105 115 } 106 116 107 117 throw new ConstructionException().msg("failed to find framsticks for native type").arg("type", type); 118 } 119 120 121 public static ParamBuilder induceParamType(ParamBuilder builder, ParamCandidate candidate) { 122 Method method = candidate.getCaller(); 123 if (method == null) { 124 return induceParamType(builder, candidate.getType()); 125 } 126 127 builder.resultType(induceParamType(Param.build(), method.getGenericReturnType()).finish(ValueParam.class)); 128 129 List<ValueParam> arguments = new ArrayList<>(); 130 int number = 0; 131 for (Type arg : method.getGenericParameterTypes()) { 132 arguments.add(induceParamType(Param.build(), arg).idAndName("arg" + (number++)).finish(ValueParam.class)); 133 } 134 builder.argumentsType(arguments); 135 136 return builder; 108 137 } 109 138 … … 183 212 name(getName(fca, javaClass)); 184 213 185 Map<String, ParamCandidate> candidates = ParamCandidate.getAllCandidates(javaClass); 186 187 for (ParamCandidate pc : candidates.values()) { 188 String type = getParamTypeForNativeType(pc.getType()); 189 if (type == null) { 190 throw new FramsticksException().msg("failed to find type for param candidate").arg("candidate", pc); 191 } 192 param(Param.build().id(pc.getId()).name(pc.getName()).type(type).flags(pc.getFlags())); 214 for (ParamCandidate pc : ParamCandidate.getAllCandidates(javaClass).getOrder()) { 215 ParamBuilder builder = Param.build().id(pc.getId()).name(pc.getName()).flags(pc.getFlags()); 216 217 induceParamType(builder, pc); 218 219 for (ParamAnnotation pa : pc.getAnnotations()) { 220 if (!"".equals(pa.def())) { 221 builder.def(pa.def()); 222 } 223 if (!"".equals(pa.help())) { 224 builder.help(pa.help()); 225 } 226 if (!"".equals(pa.min())) { 227 builder.min(pa.min()); 228 } 229 if (!"".equals(pa.max())) { 230 builder.max(pa.max()); 231 } 232 builder.extra(pa.extra()); 233 if (!"".equals(pa.stringType())) { 234 builder.type(pa.stringType()); 235 } 236 if (!pa.paramType().equals(Param.class)) { 237 builder.type(pa.paramType()); 238 } 239 } 240 param(builder); 193 241 } 194 242 … … 209 257 protected final List<Param> params = new LinkedList<>(); 210 258 211 protected List<Group > groups = new ArrayList<Group>();259 protected List<GroupBuilder> groupBuilders = new ArrayList<GroupBuilder>(); 212 260 213 261 @ParamAnnotation … … 242 290 } 243 291 244 public FramsClassBuilder append(Param param) {245 params.add(param);246 return this;247 }248 249 292 @AutoAppendAnnotation 250 293 public FramsClassBuilder param(ParamBuilder builder) { 251 return append(builder.finish()); 294 Param param = builder.finish(); 295 296 Integer group = param.getGroup(); 297 if (group != null) { 298 Containers.getFromList(groupBuilders, group, "group", this).addParam(param); 299 } 300 301 params.add(param); 302 return this; 252 303 } 253 304 254 305 @AutoAppendAnnotation 255 306 public FramsClassBuilder group(GroupBuilder builder) { 256 return group(builder.finish()); 257 } 258 259 @AutoAppendAnnotation 260 public FramsClassBuilder group(Group group) { 261 groups.add(group); 307 groupBuilders.add(builder); 262 308 return this; 263 309 } … … 288 334 289 335 public FramsClassBuilder group(String group) { 290 return group(new Group(group)); 291 } 292 293 public ParamBuilder param(String id) { 294 return new ParamBuilder(this).id(id); 295 } 336 return group(new GroupBuilder().name(group)); 337 } 338 296 339 297 340 }
Note: See TracChangeset
for help on using the changeset viewer.