javassist.bytecode.annotation.IntegerMemberValue Java Examples
The following examples show how to use
javassist.bytecode.annotation.IntegerMemberValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavassistUtilsTest.java From geowave with Apache License 2.0 | 6 votes |
private void annotateField( final CtField ctfield, final String annotationName, final int annotationValue) { final AnnotationsAttribute attr = new AnnotationsAttribute( ctfield.getFieldInfo().getConstPool(), AnnotationsAttribute.visibleTag); final 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); }
Example #2
Source File: JavassistUtilsTest.java From geowave with Apache License 2.0 | 6 votes |
private AnnotationsAttribute annotateMethod( final CtMethod ctmethod, final String annotationName, final int annotationValue) { final AnnotationsAttribute attr = new AnnotationsAttribute( ctmethod.getMethodInfo().getConstPool(), AnnotationsAttribute.visibleTag); final 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; }
Example #3
Source File: JavassistUtilsTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testGenerateEmptyClass() { final CtClass emptyClass = JavassistUtils.generateEmptyClass(); final CtClass anotherEmptyClass = JavassistUtils.generateEmptyClass(); Assert.assertFalse(emptyClass.equals(anotherEmptyClass)); // test empty class works as expected final CtMethod method = addNewMethod(emptyClass, "a"); annotateMethod(method, "abc", 7); final CtField field = addNewField(emptyClass, "d"); annotateField(field, "def", 9); Assert.assertEquals( 7, ((IntegerMemberValue) ((AnnotationsAttribute) method.getMethodInfo().getAttribute( AnnotationsAttribute.visibleTag)).getAnnotation("java.lang.Integer").getMemberValue( "abc")).getValue()); Assert.assertEquals( 9, ((IntegerMemberValue) ((AnnotationsAttribute) field.getFieldInfo().getAttribute( AnnotationsAttribute.visibleTag)).getAnnotation("java.lang.Integer").getMemberValue( "def")).getValue()); }
Example #4
Source File: JavassistUtilsTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testCopyClassAnnontations() { final CtClass fromClass = ClassPool.getDefault().makeClass("fromClass"); final CtClass toClass = ClassPool.getDefault().makeClass("toClass"); // Create class annotations final ConstPool fromPool = fromClass.getClassFile().getConstPool(); final AnnotationsAttribute attr = new AnnotationsAttribute(fromPool, AnnotationsAttribute.visibleTag); final Annotation anno = new Annotation("java.lang.Integer", fromPool); anno.addMemberValue("copyClassName", new IntegerMemberValue(fromPool, 246)); attr.addAnnotation(anno); fromClass.getClassFile().addAttribute(attr); JavassistUtils.copyClassAnnotations(fromClass, toClass); final Annotation toAnno = ((AnnotationsAttribute) toClass.getClassFile().getAttribute( AnnotationsAttribute.visibleTag)).getAnnotation("java.lang.Integer"); Assert.assertEquals( 246, ((IntegerMemberValue) toAnno.getMemberValue("copyClassName")).getValue()); }
Example #5
Source File: JavassistUtilsTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testCloneAnnotationsAttribute() { final CtClass clz = ClassPool.getDefault().makeClass("testCloneAnnotationsAttribute"); final CtMethod ctmethod = addNewMethod(clz, "origMethod"); final AnnotationsAttribute attr = annotateMethod(ctmethod, "origAnno", 135); final AnnotationsAttribute clonedAttr = JavassistUtils.cloneAnnotationsAttribute( ctmethod.getMethodInfo().getConstPool(), attr, java.lang.annotation.ElementType.METHOD); Assert.assertEquals( 135, ((IntegerMemberValue) clonedAttr.getAnnotation("java.lang.Integer").getMemberValue( "origAnno")).getValue()); }
Example #6
Source File: JavassistDynamicBean.java From gecco with MIT License | 5 votes |
@Override public JavassistDynamicBean gecco(String[] matchUrl, String downloader, int timeout, String... pipelines) { AnnotationsAttribute attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag); Annotation annot = new Annotation(Gecco.class.getName(), cpool); // matchUrl //annot.addMemberValue("matchUrl", new StringMemberValue(matchUrl, cpool)); ArrayMemberValue arrayMemberValueMatchUrl = new ArrayMemberValue(cpool); MemberValue[] elementMatchUrls = new StringMemberValue[matchUrl.length]; for (int i = 0; i < matchUrl.length; i++) { elementMatchUrls[i] = new StringMemberValue(matchUrl[i], cpool); } arrayMemberValueMatchUrl.setValue(elementMatchUrls); annot.addMemberValue("matchUrl", arrayMemberValueMatchUrl); // downloader annot.addMemberValue("downloader", new StringMemberValue(downloader, cpool)); // timeout annot.addMemberValue("timeout", new IntegerMemberValue(cpool, timeout)); // pipelines ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cpool); MemberValue[] elements = new StringMemberValue[pipelines.length]; for (int i = 0; i < pipelines.length; i++) { elements[i] = new StringMemberValue(pipelines[i], cpool); } arrayMemberValue.setValue(elements); annot.addMemberValue("pipelines", arrayMemberValue); attr.addAnnotation(annot); cfile.addAttribute(attr); return this; }
Example #7
Source File: AbstractMethodCreator.java From minnal with Apache License 2.0 | 5 votes |
/** * Returns the 400 bad request response annotation * * @param responseClass * @return */ protected Annotation getBadRequestResponseAnnotation() { ConstPool constPool = ctClass.getClassFile().getConstPool(); Annotation annotation = new Annotation(ApiResponse.class.getCanonicalName(), constPool); IntegerMemberValue code = new IntegerMemberValue(constPool); code.setValue(Response.Status.BAD_REQUEST.getStatusCode()); annotation.addMemberValue("code", code); annotation.addMemberValue("message", new StringMemberValue(Response.Status.BAD_REQUEST.getReasonPhrase(), constPool)); return annotation; }
Example #8
Source File: AbstractMethodCreator.java From minnal with Apache License 2.0 | 5 votes |
/** * Returns the 204 no content response annotation * * @param responseClass * @return */ protected Annotation getNoContentResponseAnnotation() { ConstPool constPool = ctClass.getClassFile().getConstPool(); Annotation annotation = new Annotation(ApiResponse.class.getCanonicalName(), constPool); IntegerMemberValue code = new IntegerMemberValue(constPool); code.setValue(Response.Status.NO_CONTENT.getStatusCode()); annotation.addMemberValue("code", code); annotation.addMemberValue("message", new StringMemberValue(Response.Status.NO_CONTENT.getReasonPhrase(), constPool)); return annotation; }
Example #9
Source File: AbstractMethodCreator.java From minnal with Apache License 2.0 | 5 votes |
/** * Returns the 404 not found response annotation * * @param responseClass * @return */ protected Annotation getNotFoundResponseAnnotation() { ConstPool constPool = ctClass.getClassFile().getConstPool(); Annotation annotation = new Annotation(ApiResponse.class.getCanonicalName(), constPool); IntegerMemberValue code = new IntegerMemberValue(constPool); code.setValue(Response.Status.NOT_FOUND.getStatusCode()); annotation.addMemberValue("code", code); annotation.addMemberValue("message", new StringMemberValue(Response.Status.NOT_FOUND.getReasonPhrase(), constPool)); return annotation; }
Example #10
Source File: AbstractMethodCreator.java From minnal with Apache License 2.0 | 5 votes |
/** * Returns the 200 ok response annotation * * @param responseClass * @return */ protected Annotation getOkResponseAnnotation(Class<?> responseClass) { ConstPool constPool = ctClass.getClassFile().getConstPool(); Annotation annotation = new Annotation(ApiResponse.class.getCanonicalName(), constPool); IntegerMemberValue code = new IntegerMemberValue(constPool); code.setValue(Response.Status.OK.getStatusCode()); annotation.addMemberValue("code", code); annotation.addMemberValue("message", new StringMemberValue(Response.Status.OK.getReasonPhrase(), constPool)); annotation.addMemberValue("response", new ClassMemberValue(responseClass.getCanonicalName(), constPool)); return annotation; }
Example #11
Source File: JValidator.java From dubbox with Apache License 2.0 | 5 votes |
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; }
Example #12
Source File: JValidator.java From dubbox with Apache License 2.0 | 5 votes |
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; }
Example #13
Source File: JValidator.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
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; }
Example #14
Source File: JValidator.java From dubbox with Apache License 2.0 | 5 votes |
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; }
Example #15
Source File: ClassGenerator.java From flower with Apache License 2.0 | 5 votes |
private MemberValue getMemberValue(Object obj, ConstPool cp) { if (obj == null) { return null; } if (obj instanceof Integer) { return new IntegerMemberValue(cp, (Integer) obj); } else if (obj instanceof Boolean) { return new BooleanMemberValue((Boolean) obj, cp); } else if (obj instanceof Double) { return new DoubleMemberValue((Double) obj, cp); } else if (obj instanceof Float) { return new FloatMemberValue((Float) obj, cp); } else if (obj instanceof Short) { return new ShortMemberValue((Short) obj, cp); } else if (obj instanceof String) { return new StringMemberValue((String) obj, cp); } else if (obj instanceof String[]) { String[] oo = (String[]) obj; MemberValue[] memberValues = new MemberValue[oo.length]; ArrayMemberValue value = new ArrayMemberValue(cp); for (int i = 0; i < oo.length; i++) { memberValues[i] = getMemberValue(oo[i], cp); } value.setValue(memberValues); return value; } else if (obj instanceof Byte) { return new ByteMemberValue((Byte) obj, cp); } else if (obj instanceof Annotation) { return new AnnotationMemberValue((Annotation) obj, cp); } else if (obj instanceof ArrayMemberValue) { return new ArrayMemberValue((MemberValue) obj, cp); } else if (obj instanceof Character) { return new CharMemberValue((char) obj, cp); } else if (obj instanceof Long) { return new LongMemberValue((Long) obj, cp); } return null; }
Example #16
Source File: JValidator.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
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; }
Example #17
Source File: ClassPathScanner.java From Bats with Apache License 2.0 | 4 votes |
@Override public void visitIntegerMemberValue(IntegerMemberValue node) { values.add(String.valueOf(node.getValue())); }
Example #18
Source File: ClassPathScanner.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public void visitIntegerMemberValue(IntegerMemberValue node) { values.add(String.valueOf(node.getValue())); }
Example #19
Source File: ClassExtractorAnnotationMemberValue.java From smart-testing with Apache License 2.0 | 4 votes |
@Override public void visitIntegerMemberValue(IntegerMemberValue node) { }
Example #20
Source File: ServiceDelegateBuilder.java From jweb-cms with GNU Affero General Public License v3.0 | 4 votes |
private MemberValue memberValue(Class<?> type, Object value) { if (type.isArray()) { Object[] array = (Object[]) value; MemberValue[] memberValues = new MemberValue[array.length]; Class<?> componentType = type.getComponentType(); for (int i = 0; i < array.length; i++) { memberValues[i] = memberValue(componentType, array[i]); } ArrayMemberValue arrayMemberValue = new ArrayMemberValue(constPool); arrayMemberValue.setValue(memberValues); return arrayMemberValue; } else { if (type == int.class) { return new IntegerMemberValue(constPool, (int) value); } else if (long.class.equals(type)) { return new LongMemberValue((long) value, constPool); } else if (short.class.equals(type)) { return new ShortMemberValue((short) value, constPool); } else if (byte.class.equals(type)) { return new ByteMemberValue((byte) value, constPool); } else if (char.class.equals(type)) { return new CharMemberValue((char) value, constPool); } else if (float.class.equals(type)) { return new FloatMemberValue((float) value, constPool); } else if (double.class.equals(type)) { return new DoubleMemberValue((double) value, constPool); } else if (String.class.equals(type)) { return new StringMemberValue((String) value, constPool); } else if (boolean.class.equals(type)) { return new BooleanMemberValue((boolean) value, constPool); } else if (Class.class.equals(type)) { return new ClassMemberValue(((Class) value).getName(), constPool); } else if (Enum.class.isAssignableFrom(type)) { EnumMemberValue enumMemberValue = new EnumMemberValue(constPool); enumMemberValue.setType(type.getName()); enumMemberValue.setValue(((Enum) value).name()); return enumMemberValue; } else { throw new ApplicationException("unsupported annotation method type, type={}", type); } } }