本文整理匯總了Java中javassist.bytecode.annotation.Annotation.addMemberValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Annotation.addMemberValue方法的具體用法?Java Annotation.addMemberValue怎麽用?Java Annotation.addMemberValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javassist.bytecode.annotation.Annotation
的用法示例。
在下文中一共展示了Annotation.addMemberValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: addAnnotation
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
public void addAnnotation(Class<?> type, Class<?>... values) {
ClassFile cf = cc.getClassFile();
ConstPool cp = cf.getConstPool();
ClassMemberValue[] elements = new ClassMemberValue[values.length];
for (int i = 0; i < values.length; i++) {
elements[i] = cb.createClassMemberValue(values[i], cp);
}
ArrayMemberValue value = new ArrayMemberValue(cp);
value.setValue(elements);
AnnotationsAttribute ai = (AnnotationsAttribute) cf
.getAttribute(visibleTag);
if (ai == null) {
ai = new AnnotationsAttribute(cp, visibleTag);
cf.addAttribute(ai);
}
try {
Annotation annotation = new Annotation(cp, get(type));
annotation.addMemberValue("value", value);
ai.addAnnotation(annotation);
} catch (NotFoundException e) {
throw new AssertionError(e);
}
}
示例3: href
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
@Override
public DynamicField href(boolean click, String... value) {
Annotation annot = new Annotation(Href.class.getName(), cpool);
annot.addMemberValue("click", new BooleanMemberValue(click, cpool));
ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cpool);
MemberValue[] memberValues = new StringMemberValue[value.length];
for(int i = 0; i < value.length; i++) {
memberValues[i] = new StringMemberValue(value[i], cpool);
}
arrayMemberValue.setValue(memberValues);
annot.addMemberValue("value", arrayMemberValue);
attr.addAnnotation(annot);
return this;
}
示例4: image
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
@Override
public DynamicField image(String download, String... value) {
Annotation annot = new Annotation(Image.class.getName(), cpool);
annot.addMemberValue("download", new StringMemberValue(download, cpool));
ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cpool);
MemberValue[] memberValues = new StringMemberValue[value.length];
for(int i = 0; i < value.length; i++) {
memberValues[i] = new StringMemberValue(value[i], cpool);
}
arrayMemberValue.setValue(memberValues);
annot.addMemberValue("value", arrayMemberValue);
attr.addAnnotation(annot);
return this;
}
示例5: addMimicAnnotation
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private void addMimicAnnotation(CtClass dst, String sourceClassName,
boolean isMimicingInterfaces, boolean isMimicingFields,
boolean isMimicingConstructors, boolean isMimicingMethods) {
ClassFile cf = dst.getClassFile();
ConstPool cp = cf.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(cp,
AnnotationsAttribute.visibleTag);
Annotation a = new Annotation(Mimic.class.getName(), cp);
a.addMemberValue("sourceClass", new ClassMemberValue(sourceClassName,
cp));
a.addMemberValue("isMimicingInterfaces", new BooleanMemberValue(
isMimicingInterfaces, cp));
a.addMemberValue("isMimicingFields", new BooleanMemberValue(
isMimicingFields, cp));
a.addMemberValue("isMimicingConstructors", new BooleanMemberValue(
isMimicingConstructors, cp));
a.addMemberValue("isMimicingMethods", new BooleanMemberValue(
isMimicingMethods, cp));
attr.setAnnotation(a);
cf.addAttribute(attr);
cf.setVersionToJava5();
}
示例6: createJavassistAnnotation
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
public static Annotation createJavassistAnnotation(ConstPool constpool,
java.lang.annotation.Annotation annotation)
throws CannotBuildClassException {
Annotation annotationCopy = new Annotation(annotation.annotationType()
.getName(), constpool);
for (Method m : annotation.annotationType().getDeclaredMethods()) {
try {
Object value = m.invoke(annotation);
annotationCopy.addMemberValue(m.getName(),
JavassistUtils.createMemberValue(value, constpool));
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
e.printStackTrace();
throw new CannotBuildClassException(
"Could not copy info from annotation "
+ annotation.annotationType().getName());
}
}
return annotationCopy;
}
示例7: addEndpointMapping
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
@Override
protected void addEndpointMapping(CtMethod ctMethod, String method, String request) {
MethodInfo methodInfo = ctMethod.getMethodInfo();
ConstPool constPool = methodInfo.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation requestMapping = new Annotation(RequestMapping.class.getName(), constPool);
ArrayMemberValue valueVals = new ArrayMemberValue(constPool);
StringMemberValue valueVal = new StringMemberValue(constPool);
valueVal.setValue(request);
valueVals.setValue(new MemberValue[]{valueVal});
requestMapping.addMemberValue("value", valueVals);
ArrayMemberValue methodVals = new ArrayMemberValue(constPool);
EnumMemberValue methodVal = new EnumMemberValue(constPool);
methodVal.setType(RequestMethod.class.getName());
methodVal.setValue(method);
methodVals.setValue(new MemberValue[]{methodVal});
requestMapping.addMemberValue("method", methodVals);
attr.addAnnotation(requestMapping);
methodInfo.addAttribute(attr);
}
示例8: addClassAnnotation
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
public static void addClassAnnotation(CtClass clazz, Class<?> annotationClass, Object... values) {
ClassFile ccFile = clazz.getClassFile();
ConstPool constPool = ccFile.getConstPool();
AnnotationsAttribute attr = getAnnotationsAttribute(ccFile);
Annotation annot = new Annotation(annotationClass.getName(), constPool);
for(int i = 0; i < values.length; i = i + 2) {
String valueName = (String)values[i];
Object value = values[i+1];
if (valueName != null && value != null) {
MemberValue memberValue = createMemberValue(constPool, value);
annot.addMemberValue(valueName, memberValue);
}
}
attr.addAnnotation(annot);
}
示例9: addIdParameter
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
protected Annotation[] addIdParameter(
CtMethod ctMethod,
Class<?> idType,
ClassPool cp) throws NotFoundException, CannotCompileException {
// Clone the parameter Class
//
CtClass ctParm = cp.get(idType.getName());
// Add the parameter to the method
//
ctMethod.addParameter(ctParm);
// Add the Parameter Annotations to the Method
//
MethodInfo methodInfo = ctMethod.getMethodInfo();
ConstPool constPool = methodInfo.getConstPool();
Annotation annot = new Annotation(getPathAnnotationClass().getName(), constPool);
StringMemberValue valueVal = new StringMemberValue("id", constPool);
annot.addMemberValue("value", valueVal);
return new Annotation[]{ annot };
}
示例10: annotateMethod
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private AnnotationsAttribute annotateMethod(
CtMethod ctmethod,
String annotationName,
int annotationValue ) {
AnnotationsAttribute attr = new AnnotationsAttribute(
ctmethod.getMethodInfo().getConstPool(),
AnnotationsAttribute.visibleTag);
Annotation anno = new Annotation(
"java.lang.Integer",
ctmethod.getMethodInfo().getConstPool());
anno.addMemberValue(
annotationName,
new IntegerMemberValue(
ctmethod.getMethodInfo().getConstPool(),
annotationValue));
attr.addAnnotation(anno);
ctmethod.getMethodInfo().addAttribute(
attr);
return attr;
}
示例11: annotateField
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private void annotateField(
CtField ctfield,
String annotationName,
int annotationValue ) {
AnnotationsAttribute attr = new AnnotationsAttribute(
ctfield.getFieldInfo().getConstPool(),
AnnotationsAttribute.visibleTag);
Annotation anno = new Annotation(
"java.lang.Integer",
ctfield.getFieldInfo().getConstPool());
anno.addMemberValue(
annotationName,
new IntegerMemberValue(
ctfield.getFieldInfo().getConstPool(),
annotationValue));
attr.addAnnotation(anno);
ctfield.getFieldInfo().addAttribute(
attr);
}
示例12: copyAnnotation
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
* @param classPool class pool to use
* @param constPool constants pool
* @param ann annotation to copy
* @return javassist annotation object (copy of original annotation)
* @throws Exception on errors
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public static Annotation copyAnnotation(final ClassPool classPool, final ConstPool constPool,
final java.lang.annotation.Annotation ann) throws Exception {
final Class<? extends java.lang.annotation.Annotation> annotationType = ann.annotationType();
final Annotation copy = new Annotation(annotationType.getName(), constPool);
final Method[] methods = annotationType.getDeclaredMethods();
for (final Method method : methods) {
final CtClass ctType = classPool.get(method.getReturnType().getName());
final MemberValue memberValue = Annotation.createMemberValue(constPool, ctType);
final Object value = method.invoke(ann);
memberValue.accept(new AnnotationMemberValueVisitor(classPool, constPool, value));
copy.addMemberValue(method.getName(), memberValue);
}
return copy;
}
示例13: xmlRootElement
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
* Create new <tt>XmlRootElement</tt> annotation.
* @param file Javassist file to work with
* @param name Name of root element
* @return The annotation
*/
private static Annotation xmlRootElement(final ClassFile file,
final String name) {
final AnnotationsAttribute attribute = AnnotationsAttribute.class.cast(
file.getAttribute(AnnotationsAttribute.visibleTag)
);
final Annotation annotation = attribute.getAnnotation(
XmlRootElement.class.getName()
);
annotation.addMemberValue(
"name",
new StringMemberValue(name, file.getConstPool())
);
Logger.debug(
JaxbGroup.class,
"#xmlRootElement(.., '%s'): annotation created",
name
);
return annotation;
}
示例14: addParamAnnotations
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
@Override
protected void addParamAnnotations(CtMethod ctMethod) {
Annotation[][] annotations = new Annotation[4][1];
Annotation headersParam = new Annotation(Context.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
annotations[0][0] = headersParam;
Annotation uriInfoParam = new Annotation(Context.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
annotations[1][0] = uriInfoParam;
Annotation providersParam = new Annotation(Context.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
annotations[2][0] = providersParam;
Annotation apiParam = new Annotation(ApiParam.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
apiParam.addMemberValue("name", new StringMemberValue("body", ctMethod.getMethodInfo().getConstPool()));
apiParam.addMemberValue("access", new StringMemberValue("internal", ctMethod.getMethodInfo().getConstPool()));
apiParam.addMemberValue("paramType", new StringMemberValue("body", ctMethod.getMethodInfo().getConstPool()));
annotations[3][0] = apiParam;
JavassistUtils.addParameterAnnotation(ctMethod, annotations);
}
示例15: getApiPathParamAnnotations
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
* Returns the api path parameter annotations
*
* @return
*/
protected List<Annotation> getApiPathParamAnnotations() {
List<Annotation> annotations = new ArrayList<Annotation>();
List<String> parameters = getRoutePattern().getParameterNames();
for (int i = 0; i < parameters.size(); i++) {
Annotation annotation = new Annotation(ApiImplicitParam.class.getCanonicalName(), ctClass.getClassFile().getConstPool());
annotation.addMemberValue("name", new StringMemberValue(parameters.get(i), ctClass.getClassFile().getConstPool()));
annotation.addMemberValue("paramType", new StringMemberValue("path", ctClass.getClassFile().getConstPool()));
annotation.addMemberValue("dataType", new StringMemberValue(String.class.getCanonicalName(), ctClass.getClassFile().getConstPool()));
annotation.addMemberValue("value", new StringMemberValue("The " + getResourcePath().getNodePath().get(i).getEntityMetaData().getName() + " identifier", ctClass.getClassFile().getConstPool()));
annotation.addMemberValue("required", new BooleanMemberValue(true, ctClass.getClassFile().getConstPool()));
if (i == parameters.size() - 1) {
annotation.addMemberValue("allowMultiple", new BooleanMemberValue(true, ctClass.getClassFile().getConstPool()));
}
annotations.add(annotation);
}
return annotations;
}