@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; }
discriminatorType.setValue(myInfo.getDiscriminatorType().name()); discriminator.addMemberValue("discriminatorType", discriminatorType); IntegerMemberValue length = new IntegerMemberValue(constantPool); length.setValue(myInfo.getDiscriminatorLength()); discriminator.addMemberValue("length", length);
break; case 'I' : m = new IntegerMemberValue(index, cp); break; case 'J' :
return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp);
return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp);
break; case 'I' : m = new IntegerMemberValue(index, cp); break; case 'J' :
annot.addMemberValue("timeout", new IntegerMemberValue(cpool, timeout));
public void visitIntegerMemberValue(IntegerMemberValue integerMemberValue) { value = new IntegerMemberValue(cp); }
public void visitIntegerMemberValue(IntegerMemberValue integerMemberValue) { value = new IntegerMemberValue(cp); }
@Override public void visitIntegerMemberValue(IntegerMemberValue node) { array[index] = new IntegerMemberValue(constPool, node.getValue()); }
@Override public void visitIntegerMemberValue(IntegerMemberValue node) { array[index] = new IntegerMemberValue(constPool, node.getValue()); }
public CtAnnotationBuilder addIntegerMember(String name, int value) { annotation.addMemberValue(name, new IntegerMemberValue(constPool, value)); return this; }
private MemberValue getFieldMemberValue(Object object, Method field) throws Exception { ConstPool cp = new ConstPool(this.getClass().getCanonicalName()); if (field.getReturnType().isArray()) { return getArrayMemberValue(object, field, cp); } if (field.getReturnType().equals(boolean.class)) { return new BooleanMemberValue((Boolean) field.invoke(object), cp); } if (field.getReturnType().equals(String.class)) { return new StringMemberValue((String) field.invoke(object), cp); } if (field.getReturnType().equals(int.class)) { return new IntegerMemberValue(cp, (int) field.invoke(object)); } return null; } public static String[] convertPluginPaths(String[] original, int index, boolean checkFormat) {
public Annotation createAndroidVersionsAnnotation(CtClass cls) { ClassFile clsFile = cls.getClassFile(); ConstPool constPool = clsFile.getConstPool(); Annotation annotation = new Annotation(AndroidVersions.class.getName(), constPool); List<Integer> versions = new ArrayList(this.versions.keySet()); IntegerMemberValue[] arrayMemberValues = new IntegerMemberValue[versions.size()]; for (int i=0; i<versions.size(); i++) { arrayMemberValues[i] = new IntegerMemberValue(constPool, versions.get(i)); } ArrayMemberValue arrayMemberValue = new ArrayMemberValue(constPool); arrayMemberValue.setValue(arrayMemberValues); annotation.addMemberValue("value", arrayMemberValue); return annotation; }
public CtAnnotationBuilder addIntegerMember(String name, int[] values) { ArrayMemberValue member = new ArrayMemberValue(constPool); IntegerMemberValue[] members = new IntegerMemberValue[values.length]; for (int i = 0; i < values.length; i++) { members[i] = new IntegerMemberValue(values[i], constPool); } member.setValue(members); annotation.addMemberValue(name, member); return this; }
@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; }
/** * 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; }
/** * 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; }
/** * 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; } }
/** * 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; }