Description parseValue(TypedValue value) { Description d = new Description(); if (value == null) { d.type = ABSOLUTE; d.value = 0; } else { if (value.type == TypedValue.TYPE_FRACTION) { d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) == TypedValue.COMPLEX_UNIT_FRACTION_PARENT ? RELATIVE_TO_PARENT : RELATIVE_TO_SELF; d.value = TypedValue.complexToFloat(value.data); return d; } else if (value.type == TypedValue.TYPE_FLOAT) { d.type = ABSOLUTE; d.value = value.getFloat(); return d; } else if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT) { d.type = ABSOLUTE; d.value = value.data; return d; } } d.type = ABSOLUTE; d.value = 0.0f; return d; }
ParameterExtractor(TypeCaster caster, Class<?> type, Parameter param, Description description) { this.caster = caster; this.type = type; this.name = param.name(); this.optional = param.optional(); this.description = description == null ? "" : description.value(); }
private static LinkedHashMap<String, Prop> createProps() { Field[] fs = Configuration.class.getDeclaredFields(); LinkedHashMap<String, Prop> res = new LinkedHashMap<String, Prop>(); for (Field f : fs) if (!Modifier.isStatic(f.getModifiers())) { Description annotation = f.getAnnotation(Description.class); if (annotation != null) { String name = f.getName().replace('_', '.'); res.put(name, new Prop(name, annotation.value(), f)); } } return res; }
public static void parse() { Class classt = ITCAST.class; /** 类上的注解 */ if (classt.isAnnotationPresent(Name.class)) { Name name = (Name) classt.getAnnotation(Name.class); System.out.println(name.value()); } Method[] methods = classt.getMethods(); for (Method method : methods) { if (method.isAnnotationPresent(Description.class)) { Description description = (Description) method.getAnnotation(Description.class); System.out.println(description.value()); } } }