本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
}
}
示例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;
}
}
}
}
示例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;
}
}
}
}
示例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;
}
示例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);
}