@SuppressWarnings("all") public static MemberValue createMemberValue(Object value, ConstPool constPool) { MemberValue memberValue = null; if (value instanceof Integer) { memberValue = new IntegerMemberValue(constPool, ((Integer) value)); } else if (value instanceof Boolean) { memberValue = new BooleanMemberValue((Boolean) value, constPool); } else if (value instanceof Long) { memberValue = new LongMemberValue((Long) value, constPool); } else if (value instanceof String) { memberValue = new StringMemberValue((String) value, constPool); } else if (value instanceof Class) { memberValue = new ClassMemberValue(((Class) value).getName(), constPool); } else if (value instanceof Object[]) { Object[] arr = ((Object[]) value); ArrayMemberValue arrayMemberValue = new ArrayMemberValue(new ClassMemberValue(arr[0].getClass().getName(), constPool), constPool); arrayMemberValue.setValue(Arrays.stream(arr) .map(o -> createMemberValue(o, constPool)) .toArray(MemberValue[]::new)); memberValue = arrayMemberValue; } return memberValue; }
/** * Constructs an int constant value. The initial value is 0. */ public IntegerMemberValue(ConstPool cp) { super('I', cp); setValue(0); }
/** * Obtains the string representation of this object. */ public String toString() { return Integer.toString(getValue()); }
discriminatorType.setValue(myInfo.getDiscriminatorType().name()); discriminator.addMemberValue("discriminatorType", discriminatorType); IntegerMemberValue length = new IntegerMemberValue(constantPool); length.setValue(myInfo.getDiscriminatorLength()); discriminator.addMemberValue("length", length);
@Override public void visitIntegerMemberValue(IntegerMemberValue node) { array[index] = new IntegerMemberValue(constPool, node.getValue()); }
/** * 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; }
@Override public void visitIntegerMemberValue(IntegerMemberValue node) { array[index] = new IntegerMemberValue(constPool, node.getValue()); }
break; case 'I' : m = new IntegerMemberValue(index, cp); break; case 'J' :
/** * Constructs an int constant value. * Note that this constructor receives <b>the initial value * as the second parameter</b> * unlike the corresponding constructors in the sibling classes. * This is for making a difference from the constructor that receives * an index into the constant pool table as the first parameter. * Note that the index is also int type. * * @param value the initial value. */ public IntegerMemberValue(ConstPool cp, int value) { super('I', cp); setValue(value); }
/** * 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; }
Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Integer(getValue()); }
return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp);
/** * Constructs an int constant value. The initial value is 0. */ public IntegerMemberValue(ConstPool cp) { super('I', cp); setValue(0); }
/** * 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; } }
/** * Obtains the string representation of this object. */ @Override public String toString() { return Integer.toString(getValue()); }
return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp);
/** * Constructs an int constant value. * Note that this constructor receives <b>the initial value * as the second parameter</b> * unlike the corresponding constructors in the sibling classes. * This is for making a difference from the constructor that receives * an index into the constant pool table as the first parameter. * Note that the index is also int type. * * @param value the initial value. */ public IntegerMemberValue(ConstPool cp, int value) { super('I', cp); setValue(value); }
/** * 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; }
@Override Object getValue(ClassLoader cl, ClassPool cp, Method m) { return Integer.valueOf(getValue()); }
break; case 'I' : m = new IntegerMemberValue(index, cp); break; case 'J' :