本文整理汇总了Java中sun.reflect.annotation.AnnotationParser.annotationForMap方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationParser.annotationForMap方法的具体用法?Java AnnotationParser.annotationForMap怎么用?Java AnnotationParser.annotationForMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.reflect.annotation.AnnotationParser
的用法示例。
在下文中一共展示了AnnotationParser.annotationForMap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAnnotationInstance
import sun.reflect.annotation.AnnotationParser; //导入方法依赖的package包/类
private static <A extends Annotation> A createAnnotationInstance(Map<String, Object> customValues,
Class<A> annotationType) {
Map<String, Object> values = new HashMap<>();
// Extract default values from annotation
for (Method method : annotationType.getDeclaredMethods()) {
values.put(method.getName(), method.getDefaultValue());
}
// Populate required values
values.putAll(customValues);
return (A) AnnotationParser.annotationForMap(annotationType, values);
}
示例2: getAnnotation
import sun.reflect.annotation.AnnotationParser; //导入方法依赖的package包/类
/**
* 获得配置转换注解
*
* @param field
* 字段
* @param classz
* 注解
* @return 注解类
*/
public static <T extends Annotation> T getAnnotation(Field field, Class<T> classz) {
T annotation = field.getAnnotation(classz);
if (annotation != null) {
return annotation;
}
Map<String, String> mapping = MappingProperty.getConfigMapping();
String objName = field.getDeclaringClass().getName();
String fieldName = field.getName();
String annoName = classz.getSimpleName();
String key = objName + "." + fieldName + "[" + annoName + "]";
String property = mapping.get(key);
if (property != null) {
try {
Map<String, Object> map = new HashMap<>();
map.put("value", property);
Method[] fields = classz.getDeclaredMethods();
for (Method method : fields) {
String name = method.getName();
Class<?> returnType = method.getReturnType();
if (returnType.isAssignableFrom(Class.class)) {
map.put("value", Class.forName(property));
}
Object value = mapping.get(key + "[" + name + "]");
if (!map.containsKey(name)) {
if (value != null) {
if (returnType.isAssignableFrom(boolean.class)) {
value = Boolean.valueOf(value.toString());
} else if (returnType.isAssignableFrom(Number.class) || returnType.isAssignableFrom(Boolean.class)) {
value = returnType.getConstructor(String.class).newInstance(value.toString());
}
map.put(name, value);
} else {
map.put(name, method.getDefaultValue());
}
}
}
return (T) AnnotationParser.annotationForMap(classz, map);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
示例3: generateAnnotation
import sun.reflect.annotation.AnnotationParser; //导入方法依赖的package包/类
/**
* Returns a dynamic proxy for an annotation mirror.
*/
private Annotation generateAnnotation() {
return AnnotationParser.annotationForMap(annoType,
getAllReflectedValues());
}
示例4: ann
import sun.reflect.annotation.AnnotationParser; //导入方法依赖的package包/类
private static Annotation ann(Class<? extends Annotation> annotationType,
Object value) {
return AnnotationParser.annotationForMap(annotationType,
Collections.singletonMap("value", value));
}