當前位置: 首頁>>代碼示例>>Java>>正文


Java Annotation.getMemberNames方法代碼示例

本文整理匯總了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;
}
 
開發者ID:siom79,項目名稱:japicmp,代碼行數:17,代碼來源:JApiAnnotation.java

示例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;
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:73,代碼來源:JavassistUtils.java


注:本文中的javassist.bytecode.annotation.Annotation.getMemberNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。