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


Java Annotation.getMemberValue方法代碼示例

本文整理匯總了Java中javassist.bytecode.annotation.Annotation.getMemberValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Annotation.getMemberValue方法的具體用法?Java Annotation.getMemberValue怎麽用?Java Annotation.getMemberValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javassist.bytecode.annotation.Annotation的用法示例。


在下文中一共展示了Annotation.getMemberValue方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getEntityListeners

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
protected Annotation getEntityListeners(ConstPool constantPool, Annotation existingEntityListeners, Annotation templateEntityListeners) {
    Annotation listeners = new Annotation(EntityListeners.class.getName(), constantPool);
    ArrayMemberValue listenerArray = new ArrayMemberValue(constantPool);
    Set<MemberValue> listenerMemberValues = new HashSet<MemberValue>();
    {
        ArrayMemberValue templateListenerValues = (ArrayMemberValue) templateEntityListeners.getMemberValue("value");
        listenerMemberValues.addAll(Arrays.asList(templateListenerValues.getValue()));
        logger.debug("Adding template values to new EntityListeners");
    }
    if (existingEntityListeners != null) {
        ArrayMemberValue oldListenerValues = (ArrayMemberValue) existingEntityListeners.getMemberValue("value");
        listenerMemberValues.addAll(Arrays.asList(oldListenerValues.getValue()));
        logger.debug("Adding previous values to new EntityListeners");
    }
    listenerArray.setValue(listenerMemberValues.toArray(new MemberValue[listenerMemberValues.size()]));
    listeners.addMemberValue("value", listenerArray);

    return listeners;

}
 
開發者ID:passion1014,項目名稱:metaworks_framework,代碼行數:21,代碼來源:DirectCopyClassTransformer.java

示例2: getExistingXmlJavaTypeAdapters

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
 * A narrow-purpose helper method that accepts an {@link
 * ArrayMemberValue} parameter whose value is (semantically) the
 * return value of the {@link XmlJavaTypeAdapters#value()}
 * annotation attribute, and returns a {@link Map} of {@link
 * Annotation} objects representing {@link XmlJavaTypeAdapter}
 * annotations indexed by the {@linkplain XmlJavaTypeAdapter#type()
 * types} that each of them governs.
 *
 * <p>This method never returns {@code null}.</p>
 *
 * @param adaptersHolder the {@link ArrayMemberValue} that resulted
 * from calling {@link Annotation#getMemberValue(String)
 * Annotation#getMemberValue("value")} on an {@link Annotation} that
 * is Javassist's representation of the {@link XmlJavaTypeAdapters}
 * annotation.  This parameter may be {@code null}.
 *
 * @return a {@link Map} of {@link Annotation} objects representing
 * {@link XmlJavaTypeAdapter} annotations indexed by the {@linkplain
 * XmlJavaTypeAdapter#type() types} that each of them governs; never
 * {@code null}
 */
private static final Map<String, Annotation> getExistingXmlJavaTypeAdapters(final ArrayMemberValue adaptersHolder) {
  // Build a Map indexing existing @XmlJavaTypeAdapter annotations
  // by the types that they govern.
  final Map<String, Annotation> xmlJavaTypeAdapters = new HashMap<String, Annotation>();
  if (adaptersHolder != null) {
    final MemberValue[] rawMemberValue = adaptersHolder.getValue();
    if (rawMemberValue != null && rawMemberValue.length > 0) {
      for (final MemberValue mv : rawMemberValue) {
        if (mv instanceof AnnotationMemberValue) {
          final Annotation xmlJavaTypeAdapter = ((AnnotationMemberValue)mv).getValue();
          if (xmlJavaTypeAdapter != null && XmlJavaTypeAdapter.class.getName().equals(xmlJavaTypeAdapter.getTypeName())) {
            final ClassMemberValue typeHolder = (ClassMemberValue)xmlJavaTypeAdapter.getMemberValue("type");
            if (typeHolder != null) {
              final String interfaceTypeName = typeHolder.getValue();
              if (interfaceTypeName != null) {
                xmlJavaTypeAdapters.put(interfaceTypeName, xmlJavaTypeAdapter);
              }
            }
          }
        }
      }
    }
  }
  return xmlJavaTypeAdapters;
}
 
開發者ID:ljnelson,項目名稱:jaxb-tools,代碼行數:48,代碼來源:PackageInfoModifier.java

示例3: 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

示例4: applyTransformations

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
@Override
protected void applyTransformations(CtClass clazz) throws Exception {
    AnnotationsAttribute attribute = (AnnotationsAttribute) clazz.getClassFile().getAttribute(AnnotationsAttribute.visibleTag);
    Annotation annotation = attribute.getAnnotation("org.spongepowered.api.plugin.Plugin");
    StringMemberValue version = (StringMemberValue) annotation.getMemberValue("version");
    version.setValue(this.version);
    attribute.setAnnotation(annotation);
}
 
開發者ID:BuycraftPlugin,項目名稱:BuycraftX,代碼行數:9,代碼來源:Transform.java

示例5: analizePotentialPlugins

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private static void analizePotentialPlugins(InputStream input, Set<DiscoveredPlugin> discovered, boolean isClasspath, File file) throws IOException {
    DataInputStream in;
    if(input instanceof DataInputStream){
        in = ((DataInputStream) input);
    }else{
        in = new DataInputStream(input);
    }

    ClassFile classFile = new ClassFile(in);

    AnnotationsAttribute annotations = ((AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag));
    if(annotations == null){
        return;
    }
    for(Annotation annotation : annotations.getAnnotations()){
        String annName = annotation.getTypeName();
        if(annName.equals("jk_5.nailed.api.plugin.Plugin")){
            StringMemberValue idValue = ((StringMemberValue) annotation.getMemberValue("id"));
            String id = idValue == null ? null : idValue.getValue();
            StringMemberValue nameValue = ((StringMemberValue) annotation.getMemberValue("name"));
            String name = nameValue == null ? null : nameValue.getValue();
            StringMemberValue versionValue = ((StringMemberValue) annotation.getMemberValue("version"));
            String version = versionValue == null ? "unknown" : versionValue.getValue();
            discovered.add(new DiscoveredPlugin(classFile.getName(), id, name, version, isClasspath, file));
        }
    }
}
 
開發者ID:nailed,項目名稱:nailed,代碼行數:28,代碼來源:PluginDiscoverer.java

示例6: disableBooleanMember

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
 * Iterate the annotations, look for a 'required' parameter, and set it to
 * false.
 * 
 * @param field
 * @param prefix
 */
private void disableBooleanMember(
		String booleanMemberName,
		CtField field ) {

	// This is the JCommander package name
	String packageName = JCommander.class.getPackage().getName();

	AnnotationsAttribute fieldAttributes = (AnnotationsAttribute) field.getFieldInfo().getAttribute(
			AnnotationsAttribute.visibleTag);

	// Look for annotations that have a 'names' attribute, and whose package
	// starts with the expected JCommander package.
	for (Annotation annotation : fieldAttributes.getAnnotations()) {
		if (annotation.getTypeName().startsWith(
				packageName)) {
			// See if it has a 'names' member variable.
			MemberValue requiredMember = annotation.getMemberValue(booleanMemberName);

			// We have a names member!!!
			if (requiredMember != null) {
				BooleanMemberValue booleanRequiredMember = (BooleanMemberValue) requiredMember;

				// Set it to not required.
				booleanRequiredMember.setValue(false);

				// This is KEY! For some reason, the existing annotation
				// will not be modified unless
				// you call 'setAnnotation' here. I'm guessing
				// 'getAnnotation()' creates a copy.
				fieldAttributes.setAnnotation(annotation);

				// Finished processing names.
				break;
			}
		}
	}
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:45,代碼來源:JCommanderTranslationMap.java

示例7: overrideParameterPrefixes

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
 * Iterate the annotations, look for a 'names' parameter, and override it to
 * prepend the given prefix.
 * 
 * @param field
 * @param prefix
 */
private void overrideParameterPrefixes(
		CtField field,
		String[] names ) {

	// This is the JCommander package name
	String packageName = JCommander.class.getPackage().getName();

	AnnotationsAttribute fieldAttributes = (AnnotationsAttribute) field.getFieldInfo().getAttribute(
			AnnotationsAttribute.visibleTag);

	// Look for annotations that have a 'names' attribute, and whose package
	// starts with the expected JCommander package.
	for (Annotation annotation : fieldAttributes.getAnnotations()) {
		if (annotation.getTypeName().startsWith(
				packageName)) {
			// See if it has a 'names' member variable.
			MemberValue namesMember = annotation.getMemberValue(NAMES_MEMBER);

			// We have a names member!!!
			if (namesMember != null) {
				ArrayMemberValue arrayNamesMember = (ArrayMemberValue) namesMember;

				// Iterate and transform each item in 'names()' list and
				// transform it.
				MemberValue[] newMemberValues = new MemberValue[names.length];
				for (int i = 0; i < names.length; i++) {
					newMemberValues[i] = new StringMemberValue(
							names[i],
							field.getFieldInfo2().getConstPool());
				}

				// Override the member values in nameMember with the new
				// one's we've generated
				arrayNamesMember.setValue(newMemberValues);

				// This is KEY! For some reason, the existing annotation
				// will not be modified unless
				// you call 'setAnnotation' here. I'm guessing
				// 'getAnnotation()' creates a copy.
				fieldAttributes.setAnnotation(annotation);

				// Finished processing names.
				break;
			}
		}
	}
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:55,代碼來源:JCommanderTranslationMap.java

示例8: 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

示例9: updatePropOrder

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
static
private void updatePropOrder(CtClass ctClass, String name){
	ClassFile classFile = ctClass.getClassFile();

	AnnotationsAttribute annotations = (AnnotationsAttribute)classFile.getAttribute(AnnotationsAttribute.visibleTag);

	Annotation xmlTypeAnnotation = annotations.getAnnotation("javax.xml.bind.annotation.XmlType");

	ArrayMemberValue propOrderValue = (ArrayMemberValue)xmlTypeAnnotation.getMemberValue("propOrder");

	removeValue(propOrderValue, name);

	annotations.addAnnotation(xmlTypeAnnotation);
}
 
開發者ID:jpmml,項目名稱:jpmml-model,代碼行數:15,代碼來源:TransformationUtil.java


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