本文整理匯總了Java中javassist.bytecode.annotation.StringMemberValue類的典型用法代碼示例。如果您正苦於以下問題:Java StringMemberValue類的具體用法?Java StringMemberValue怎麽用?Java StringMemberValue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StringMemberValue類屬於javassist.bytecode.annotation包,在下文中一共展示了StringMemberValue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: href
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的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;
}
示例2: image
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的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;
}
示例3: removeValue
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
static
private void removeValue(ArrayMemberValue memberValue, String value){
List<MemberValue> values = new ArrayList<>(Arrays.asList(memberValue.getValue()));
boolean removed = false;
Iterator<MemberValue> it = values.iterator();
while(it.hasNext()){
StringMemberValue stringValue = (StringMemberValue)it.next();
if((value).equals(stringValue.getValue())){
it.remove();
removed = true;
}
}
if(!removed){
throw new RuntimeException(value + " not in " + values);
}
memberValue.setValue(values.toArray(new MemberValue[values.size()]));
}
示例4: addDbCommentAnnotation
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
private void addDbCommentAnnotation(AnnotationsAttribute attribute) {
if (attribute.getAnnotation(DbComment.class.getName()) != null) return;
StringBuilder builder = new StringBuilder();
String display = appendDbCommentValue(attribute, Display.class);
if (StringUtils.isNotBlank(display))
builder.append(display);
String desc = appendDbCommentValue(attribute, Description.class);
if (StringUtils.isNotBlank(desc))
builder.append(" ").append(desc);
if (builder.length() > 0) {
Map<String, MemberValue> valueMap = Maps.newHashMap();
ConstPool cp = attribute.getConstPool();
valueMap.put("value", new StringMemberValue(builder.toString()
.replace("'", "''")
.replace("\r", " ")
.replace("\n", " "), cp));
addAnnotation(attribute, DbComment.class, valueMap);
}
}
示例5: addEndpointMapping
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的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);
}
示例6: addIdParameter
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的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 };
}
示例7: addParamAnnotations
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的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);
}
示例8: getApiPathParamAnnotations
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的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;
}
示例9: getSecurityAnnotation
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
/**
* Returns the security annotation
*
* @return
*/
protected Annotation getSecurityAnnotation() {
Set<String> permissions = getPermissions();
if (permissions == null || permissions.isEmpty()) {
return null;
}
Annotation rolesAllowed = new Annotation(RolesAllowed.class.getCanonicalName(), ctClass.getClassFile().getConstPool());
ArrayMemberValue values = new ArrayMemberValue(ctClass.getClassFile().getConstPool());
List<StringMemberValue> memberValues = new ArrayList<StringMemberValue>();
for (String permission : permissions) {
memberValues.add(new StringMemberValue(permission, ctClass.getClassFile().getConstPool()));
}
values.setValue(memberValues.toArray(new StringMemberValue[0]));
rolesAllowed.addMemberValue("value", values);
return rolesAllowed;
}
示例10: xmlRootElement
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的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;
}
示例11: createMemberValue
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
if (memberValue instanceof BooleanMemberValue)
((BooleanMemberValue) memberValue).setValue((Boolean) value);
else if (memberValue instanceof ByteMemberValue)
((ByteMemberValue) memberValue).setValue((Byte) value);
else if (memberValue instanceof CharMemberValue)
((CharMemberValue) memberValue).setValue((Character) value);
else if (memberValue instanceof ShortMemberValue)
((ShortMemberValue) memberValue).setValue((Short) value);
else if (memberValue instanceof IntegerMemberValue)
((IntegerMemberValue) memberValue).setValue((Integer) value);
else if (memberValue instanceof LongMemberValue)
((LongMemberValue) memberValue).setValue((Long) value);
else if (memberValue instanceof FloatMemberValue)
((FloatMemberValue) memberValue).setValue((Float) value);
else if (memberValue instanceof DoubleMemberValue)
((DoubleMemberValue) memberValue).setValue((Double) value);
else if (memberValue instanceof ClassMemberValue)
((ClassMemberValue) memberValue).setValue(((Class<?>)value).getName());
else if (memberValue instanceof StringMemberValue)
((StringMemberValue) memberValue).setValue((String) value);
else if (memberValue instanceof EnumMemberValue)
((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
/* else if (memberValue instanceof AnnotationMemberValue) */
else if (memberValue instanceof ArrayMemberValue) {
CtClass arrayType = type.getComponentType();
int len = Array.getLength(value);
MemberValue[] members = new MemberValue[len];
for (int i = 0; i < len; i ++) {
members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
}
((ArrayMemberValue) memberValue).setValue(members);
}
return memberValue;
}
示例12: createMemberValue
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
if (memberValue instanceof BooleanMemberValue)
((BooleanMemberValue) memberValue).setValue((Boolean) value);
else if (memberValue instanceof ByteMemberValue)
((ByteMemberValue) memberValue).setValue((Byte) value);
else if (memberValue instanceof CharMemberValue)
((CharMemberValue) memberValue).setValue((Character) value);
else if (memberValue instanceof ShortMemberValue)
((ShortMemberValue) memberValue).setValue((Short) value);
else if (memberValue instanceof IntegerMemberValue)
((IntegerMemberValue) memberValue).setValue((Integer) value);
else if (memberValue instanceof LongMemberValue)
((LongMemberValue) memberValue).setValue((Long) value);
else if (memberValue instanceof FloatMemberValue)
((FloatMemberValue) memberValue).setValue((Float) value);
else if (memberValue instanceof DoubleMemberValue)
((DoubleMemberValue) memberValue).setValue((Double) value);
else if (memberValue instanceof ClassMemberValue)
((ClassMemberValue) memberValue).setValue(((Class<?>) value).getName());
else if (memberValue instanceof StringMemberValue)
((StringMemberValue) memberValue).setValue((String) value);
else if (memberValue instanceof EnumMemberValue)
((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
/* else if (memberValue instanceof AnnotationMemberValue) */
else if (memberValue instanceof ArrayMemberValue) {
CtClass arrayType = type.getComponentType();
int len = Array.getLength(value);
MemberValue[] members = new MemberValue[len];
for (int i = 0; i < len; i++) {
members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
}
((ArrayMemberValue) memberValue).setValue(members);
}
return memberValue;
}
示例13: getAuthors
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
public ArrayMemberValue getAuthors(OsmiumMetaContainer meta, ConstPool cpool) {
ArrayMemberValue arrayMember = new ArrayMemberValue(cpool);
String[] authors = meta.getAuthors();
MemberValue[] elements = new MemberValue[authors.length];
for (int i = 0; i < authors.length; i++) {
elements[i] = new StringMemberValue(authors[i], cpool);
}
arrayMember.setValue(elements);
return arrayMember;
}
示例14: getDependencies
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
public ArrayMemberValue getDependencies(OsmiumMetaContainer meta, ConstPool cpool) {
ArrayMemberValue arrayMember = new ArrayMemberValue(cpool);
String[] dependencies = meta.getDependencies();
MemberValue[] elements = new MemberValue[dependencies.length];
for (int i = 0; i < dependencies.length; i++) {
elements[i] = new StringMemberValue(dependencies[i], cpool);
}
arrayMember.setValue(elements);
return arrayMember;
}
示例15: createMemberValue
import javassist.bytecode.annotation.StringMemberValue; //導入依賴的package包/類
private static MemberValue createMemberValue(Class<?> type, Object val, ConstPool cp) {
if (type == String.class) {
return new StringMemberValue((String) val, cp);
} else {
throw new RuntimeException("Only support string param value! Invalid param value type:" + type + " and value: " + val);
}
}