本文整理匯總了Java中javassist.bytecode.annotation.Annotation.getMemberNames方法的典型用法代碼示例。如果您正苦於以下問題:Java Annotation.getMemberNames方法的具體用法?Java Annotation.getMemberNames怎麽用?Java Annotation.getMemberNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javassist.bytecode.annotation.Annotation
的用法示例。
在下文中一共展示了Annotation.getMemberNames方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildMemberValueMap
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private Map<String, Optional<MemberValue>> buildMemberValueMap(Annotation annotation) {
Map<String, Optional<MemberValue>> map = new HashMap<>();
@SuppressWarnings("unchecked")
Set<String> memberNames = annotation.getMemberNames();
if (memberNames != null) {
for (String memberName : memberNames) {
MemberValue memberValue = annotation.getMemberValue(memberName);
if (memberValue == null) {
map.put(memberName, Optional.<MemberValue>absent());
} else {
map.put(memberName, Optional.of(memberValue));
}
}
}
return map;
}
示例2: cloneAnnotationsAttribute
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
* This function will take the given annotations attribute and create a new
* attribute, cloning all the annotations and specified values within the
* attribute. The annotations attribute can then be set on a method, class,
* or field.
*
* @param attr
* @return
*/
public static AnnotationsAttribute cloneAnnotationsAttribute(
ConstPool constPool,
AnnotationsAttribute attr,
ElementType validElementType ) {
// We can use system class loader here because the annotations for
// Target
// are part of the Java System.
ClassLoader cl = ClassLoader.getSystemClassLoader();
AnnotationsAttribute attrNew = new AnnotationsAttribute(
constPool,
AnnotationsAttribute.visibleTag);
if (attr != null) {
for (Annotation annotation : attr.getAnnotations()) {
Annotation newAnnotation = new Annotation(
annotation.getTypeName(),
constPool);
// If this must target a certain type of field, then ensure we
// only
// copy over annotations that can target that type of field.
// For instances, a METHOD annotation can't be applied to a
// FIELD or TYPE.
Class<?> annoClass;
try {
annoClass = cl.loadClass(annotation.getTypeName());
Target target = annoClass.getAnnotation(Target.class);
if (target != null && !Arrays.asList(
target.value()).contains(
validElementType)) {
continue;
}
}
catch (ClassNotFoundException e) {
// Cannot apply this annotation because its type cannot be
// found.
LOGGER.error(
"Cannot apply this annotation because it's type cannot be found",
e);
continue;
}
// Copy over the options for this annotation. For example:
// @Parameter(names = "-blah")
// For this, a member value would be "names" which would be a
// StringMemberValue
if (annotation.getMemberNames() != null) {
for (Object memberName : annotation.getMemberNames()) {
MemberValue memberValue = annotation.getMemberValue((String) memberName);
if (memberValue != null) {
newAnnotation.addMemberValue(
(String) memberName,
memberValue);
}
}
}
attrNew.addAnnotation(newAnnotation);
}
}
return attrNew;
}