下面列出了javax.validation.Constraint#javassist.bytecode.AnnotationsAttribute 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void scan(final Object cls) {
final ClassFile classFile = (ClassFile)cls;
AnnotationsAttribute annotations = ((AnnotationsAttribute)classFile.getAttribute(AnnotationsAttribute.visibleTag));
if (annotations != null) {
boolean isAnnotated = false;
for (javassist.bytecode.annotation.Annotation a : annotations.getAnnotations()) {
if (annotationsToScan.contains(a.getTypeName())) {
isAnnotated = true;
}
}
if (isAnnotated) {
List<AnnotationDescriptor> classAnnotations = getAnnotationDescriptors(annotations);
List<FieldInfo> classFields = classFile.getFields();
List<FieldDescriptor> fieldDescriptors = new ArrayList<>(classFields.size());
for (FieldInfo field : classFields) {
String fieldName = field.getName();
AnnotationsAttribute fieldAnnotations = ((AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.visibleTag));
fieldDescriptors.add(new FieldDescriptor(fieldName, field.getDescriptor(), getAnnotationDescriptors(fieldAnnotations)));
}
functions.add(new AnnotatedClassDescriptor(classFile.getName(), classAnnotations, fieldDescriptors));
}
}
}
private List<AnnotationDescriptor> getAnnotationDescriptors(AnnotationsAttribute annotationsAttr) {
if (annotationsAttr == null) {
return Collections.emptyList();
}
List<AnnotationDescriptor> annotationDescriptors = new ArrayList<>(annotationsAttr.numAnnotations());
for (javassist.bytecode.annotation.Annotation annotation : annotationsAttr.getAnnotations()) {
// Sigh: javassist uses raw collections (is this 2002?)
Set<String> memberNames = annotation.getMemberNames();
List<AttributeDescriptor> attributes = new ArrayList<>();
if (memberNames != null) {
for (String name : memberNames) {
MemberValue memberValue = annotation.getMemberValue(name);
final List<String> values = new ArrayList<>();
memberValue.accept(new ListingMemberValueVisitor(values));
attributes.add(new AttributeDescriptor(name, values));
}
}
annotationDescriptors.add(new AnnotationDescriptor(annotation.getTypeName(), attributes));
}
return annotationDescriptors;
}
private static void annotateApiAnn(ApiInfo info, AnnotationsAttribute attr, ConstPool constPool) {
Annotation apiAnn = attr.getAnnotation(Api.class.getTypeName());
MemberValue value;
if (isNull(apiAnn)) {
apiAnn = new Annotation(Api.class.getName(), constPool);
}
if (isNull(value = apiAnn.getMemberValue(ApiInfo.HIDDEN)) || !((BooleanMemberValue) value).getValue()) {
apiAnn.addMemberValue(ApiInfo.HIDDEN, new BooleanMemberValue(info.hidden(), constPool));
}
ArrayMemberValue arrayMemberValue = (ArrayMemberValue) apiAnn.getMemberValue(TAGS);
if (isNull(arrayMemberValue)) {
arrayMemberValue = new ArrayMemberValue(constPool);
arrayMemberValue.setValue(new MemberValue[1]);
}
StringMemberValue tagMemberValue = (StringMemberValue) arrayMemberValue.getValue()[0];
if (isNull(tagMemberValue) || StringUtils.isEmpty(tagMemberValue.getValue())) {
tagMemberValue = new StringMemberValue(info.tag(), constPool);
}
tagMemberValue.setValue(info.tag());
arrayMemberValue.getValue()[0] = tagMemberValue;
apiAnn.addMemberValue(TAGS, arrayMemberValue);
attr.addAnnotation(apiAnn);
}
/**
* 添加方法
*/
private static void addProxyMethod(CtClass proxy, CtMethod parentMethod, String methodBody)
throws NotFoundException, CannotCompileException
{
int mod = Modifier.FINAL | parentMethod.getModifiers();
if (Modifier.isNative(mod)) {
mod = mod & ~Modifier.NATIVE;
}
CtMethod proxyMethod = new CtMethod(parentMethod.getReturnType(), parentMethod.getName(), parentMethod.getParameterTypes(), proxy);
proxyMethod.setModifiers(mod);
proxyMethod.setBody(methodBody);
//add Override
Annotation annotation = new Annotation(Override.class.getName(), proxyMethod.getMethodInfo().getConstPool());
AnnotationsAttribute attribute = new AnnotationsAttribute(proxyMethod.getMethodInfo().getConstPool(), AnnotationsAttribute.visibleTag);
attribute.addAnnotation(annotation);
proxyMethod.getMethodInfo().addAttribute(attribute);
try {
proxy.addMethod(proxyMethod);
}
catch (DuplicateMemberException e) {
//todo: Use a more elegant way
}
}
/**
* 代理缓存字段
*
* <pre>
* private final [clazz.name] _object;
* private final CacheManager _manager;
* </pre>
*
* @param clazz
* @param proxyClass
* @throws Exception
*/
private void proxyCacheFields(Class<?> clazz, CtClass proxyClass) throws Exception {
ConstPool constPool = proxyClass.getClassFile2().getConstPool();
CtField managerField = new CtField(classPool.get(ProxyManager.class.getName()), FIELD_MANAGER, proxyClass);
CtField informationField = new CtField(classPool.get(CacheInformation.class.getName()), FIELD_INFORMATION, proxyClass);
List<CtField> fields = Arrays.asList(managerField, informationField);
List<String> types = Arrays.asList("javax.persistence.Transient", "org.springframework.data.annotation.Transient");
for (CtField field : fields) {
field.setModifiers(Modifier.PRIVATE + Modifier.FINAL + Modifier.TRANSIENT);
FieldInfo fieldInfo = field.getFieldInfo();
for (String type : types) {
AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation annotation = new Annotation(type, constPool);
annotationsAttribute.addAnnotation(annotation);
fieldInfo.addAttribute(annotationsAttribute);
}
proxyClass.addField(field);
}
}
@SuppressWarnings("unchecked")
public Class<? extends Supplier<T>> build() {
ClassPool classPool = ClassPool.getDefault();
CtClass classBuilder = classPool.makeClass(providerClass.getCanonicalName() + "$Bride" + INDEX.incrementAndGet());
try {
classBuilder.addInterface(classPool.get(Supplier.class.getName()));
ConstPool constPool = classBuilder.getClassFile().getConstPool();
CtField field = CtField.make(String.format("%s provider;", Types.className(providerClass)), classBuilder);
Annotation ctAnnotation = new Annotation(Inject.class.getCanonicalName(), constPool);
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
attr.addAnnotation(ctAnnotation);
field.getFieldInfo().addAttribute(attr);
classBuilder.addField(field);
CtMethod ctMethod = CtMethod.make("public Object get() {return provider.get();}", classBuilder);
classBuilder.addMethod(ctMethod);
return classBuilder.toClass();
} catch (CannotCompileException | NotFoundException e) {
throw new ApplicationException("failed to create provider bride, providerType={}", providerClass, e);
}
}
private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) {
ClassDescriptor.Categorization categorization = ClassDescriptor.Categorization.OTHER;;
final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) classFile.getAttribute( AnnotationsAttribute.visibleTag );
if ( visibleAnnotations != null ) {
if ( visibleAnnotations.getAnnotation( Entity.class.getName() ) != null
|| visibleAnnotations.getAnnotation( MappedSuperclass.class.getName() ) != null
|| visibleAnnotations.getAnnotation( Embeddable.class.getName() ) != null ) {
categorization = ClassDescriptor.Categorization.MODEL;
}
else if ( visibleAnnotations.getAnnotation( Converter.class.getName() ) != null ) {
categorization = ClassDescriptor.Categorization.CONVERTER;
}
}
return new ClassDescriptorImpl( classFile.getName(), categorization, entry.getStreamAccess() );
}
@SneakyThrows
public Proxy<I> addField(String code, Class<? extends java.lang.annotation.Annotation> annotation, Map<String, Object> annotationProperties) {
return handleException(() -> {
CtField ctField = CtField.make(code, ctClass);
if (null != annotation) {
ConstPool constPool = ctClass.getClassFile().getConstPool();
AnnotationsAttribute attributeInfo = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation ann = new javassist.bytecode.annotation.Annotation(annotation.getName(), constPool);
if (null != annotationProperties) {
annotationProperties.forEach((key, value) -> {
MemberValue memberValue = createMemberValue(value, constPool);
if (memberValue != null) {
ann.addMemberValue(key, memberValue);
}
});
}
attributeInfo.addAnnotation(ann);
ctField.getFieldInfo().addAttribute(attributeInfo);
}
ctClass.addField(ctField);
});
}
private List<String> getAnnotationNames(AnnotationsAttribute... annotationsAttributes) {
List<String> result = new ArrayList<>();
if (annotationsAttributes == null) {
return result;
}
for (AnnotationsAttribute annotationsAttribute : annotationsAttributes) {
if (annotationsAttribute == null) {
continue;
}
for (Annotation annotation : annotationsAttribute.getAnnotations()) {
result.add(annotation.getTypeName());
}
}
return result;
}
public CtClass addToClassPool(ClassPool classPool) {
CtClass ctClass;
if (this.superclass.isPresent()) {
ctClass = classPool.makeClass(this.name, this.superclass.get());
} else {
ctClass = classPool.makeClass(this.name);
}
ctClass.setModifiers(this.modifier);
for (String annotation : annotations) {
ClassFile classFile = ctClass.getClassFile();
ConstPool constPool = classFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation annot = new Annotation(annotation, constPool);
attr.setAnnotation(annot);
ctClass.getClassFile2().addAttribute(attr);
}
for (CtClass interfaceCtClass : interfaces) {
ctClass.addInterface(interfaceCtClass);
}
return ctClass;
}
public CtMethod addToClass(CtClass declaringClass) throws CannotCompileException {
if (this.returnType == null) {
this.returnType = declaringClass;
}
CtMethod ctMethod = CtNewMethod.make(this.modifier, this.returnType, this.name, this.parameters, this.exceptions, this.body, declaringClass);
ctMethod.setModifiers(this.modifier);
declaringClass.addMethod(ctMethod);
for (String annotation : annotations) {
ClassFile classFile = declaringClass.getClassFile();
ConstPool constPool = classFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation annot = new Annotation(annotation, constPool);
attr.setAnnotation(annot);
ctMethod.getMethodInfo().addAttribute(attr);
}
return ctMethod;
}
private static boolean isAnnotated(ClassFile cfile, Class<? extends Annotation>[] annotated) {
List attributes = U.safe(cfile.getAttributes());
for (Object attribute : attributes) {
if (attribute instanceof AnnotationsAttribute) {
AnnotationsAttribute annotations = (AnnotationsAttribute) attribute;
for (Class<? extends Annotation> ann : annotated) {
if (annotations.getAnnotation(ann.getName()) != null) {
return true;
}
}
}
}
return false;
}
@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);
}
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);
}
/**
* Simple helper method to essentially clone the annotations from one class onto another.
*/
public static void copyClassAnnotations(final CtClass oldClass, final CtClass newClass) {
// Load the existing annotations attributes
final AnnotationsAttribute classAnnotations =
(AnnotationsAttribute) oldClass.getClassFile().getAttribute(
AnnotationsAttribute.visibleTag);
// Clone them
final AnnotationsAttribute copyClassAttribute =
JavassistUtils.cloneAnnotationsAttribute(
newClass.getClassFile2().getConstPool(),
classAnnotations,
ElementType.TYPE);
// Set the annotations on the new class
newClass.getClassFile().addAttribute(copyClassAttribute);
}
/**
* Simple helper method to take any FIELD targetable annotations from the method and copy them to
* the new field. All JCommander annotations can target fields as well as methods, so this should
* capture them all.
*/
public static void copyMethodAnnotationsToField(final CtMethod method, final CtField field) {
// Load the existing annotations attributes
final AnnotationsAttribute methodAnnotations =
(AnnotationsAttribute) method.getMethodInfo().getAttribute(AnnotationsAttribute.visibleTag);
// Clone them
final AnnotationsAttribute copyMethodAttribute =
JavassistUtils.cloneAnnotationsAttribute(
field.getFieldInfo2().getConstPool(),
methodAnnotations,
ElementType.FIELD);
// Set the annotations on the new class
field.getFieldInfo().addAttribute(copyMethodAttribute);
}
@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());
}
@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());
}
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;
}
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);
}
@Override
public Set<JAnnotation<?>> getAnnotations() {
AnnotationsAttribute visible = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.visibleTag);
AnnotationsAttribute invisible = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.invisibleTag);
Set<JAnnotation<?>> annotations = new HashSet<JAnnotation<?>>();
List<Annotation> annotationsList = new ArrayList<Annotation>();
if (visible != null) {
annotationsList.addAll(Arrays.asList(visible.getAnnotations()));
}
if (invisible != null) {
annotationsList.addAll(Arrays.asList(invisible.getAnnotations()));
}
for (Annotation nextAnnotation : annotationsList) {
annotations.add(JAnnotation.getJAnnotation(nextAnnotation, this, getResolver()));
}
return annotations;
}
@Override
public Set<JAnnotation<?>> getAnnotations() {
AnnotationsAttribute visible = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag);
AnnotationsAttribute invisible = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.invisibleTag);
Set<JAnnotation<?>> annotations = new HashSet<JAnnotation<?>>();
List<Annotation> annotationsList = new ArrayList<Annotation>();
if (visible != null) {
annotationsList.addAll(Arrays.asList(visible.getAnnotations()));
}
if (invisible != null) {
annotationsList.addAll(Arrays.asList(invisible.getAnnotations()));
}
for (Annotation nextAnnotation : annotationsList) {
annotations.add(JAnnotation.getJAnnotation(nextAnnotation, this, getResolver()));
}
return annotations;
}
@Override
public Set<JAnnotation<?>> getAnnotations() {
AnnotationsAttribute visible = (AnnotationsAttribute) getClassFile().getAttribute(AnnotationsAttribute.visibleTag);
AnnotationsAttribute invisible = (AnnotationsAttribute) getClassFile().getAttribute(AnnotationsAttribute.invisibleTag);
Set<JAnnotation<?>> annotations = new HashSet<JAnnotation<?>>();
List<Annotation> annotationsList = new ArrayList<Annotation>();
if (visible != null) {
annotationsList.addAll(Arrays.asList(visible.getAnnotations()));
}
if (invisible != null) {
annotationsList.addAll(Arrays.asList(invisible.getAnnotations()));
}
for (Annotation nextAnnotation : annotationsList) {
annotations.add(JAnnotation.getJAnnotation(nextAnnotation, this, getResolver()));
}
return annotations;
}
@Override
public Set<JAnnotation<?>> getAnnotations() throws ClasspathAccessException {
AnnotationsAttribute visible = (AnnotationsAttribute) getClassFile().getAttribute(AnnotationsAttribute.visibleTag);
AnnotationsAttribute invisible = (AnnotationsAttribute) getClassFile().getAttribute(AnnotationsAttribute.invisibleTag);
Set<JAnnotation<?>> annotations = new HashSet<JAnnotation<?>>();
List<Annotation> annotationsList = new ArrayList<Annotation>();
if (visible != null) {
annotationsList.addAll(Arrays.asList(visible.getAnnotations()));
}
if (invisible != null) {
annotationsList.addAll(Arrays.asList(invisible.getAnnotations()));
}
for (Annotation nextAnnotation : annotationsList) {
annotations.add(JAnnotation.getJAnnotation(nextAnnotation, this, getResolver()));
}
return annotations;
}
public CtMethod addToClass(CtClass declaringClass) throws CannotCompileException {
if (this.returnType == null) {
this.returnType = declaringClass;
}
CtMethod ctMethod = CtNewMethod.make(this.modifier, this.returnType, this.name, this.parameters, this.exceptions, this.body, declaringClass);
ctMethod.setModifiers(this.modifier);
declaringClass.addMethod(ctMethod);
for (String annotation : annotations) {
ClassFile classFile = declaringClass.getClassFile();
ConstPool constPool = classFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation annot = new Annotation(annotation, constPool);
attr.setAnnotation(annot);
ctMethod.getMethodInfo().addAttribute(attr);
}
return ctMethod;
}
private static CtField createField(Class aClass, String name, String value, CtClass ctClass) throws NotFoundException, CannotCompileException {
ClassPool.getDefault().insertClassPath(new ClassClassPath(aClass));
CtField field = new CtField(ClassPool.getDefault().get(aClass.getName()), name, ctClass);
field.setModifiers(javassist.Modifier.PUBLIC);
ConstPool constPool = ctClass.getClassFile().getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation ann = new Annotation(ApiModelProperty.class.getName(), constPool);
ann.addMemberValue("value", new StringMemberValue(value, constPool));
ann.addMemberValue("name", new StringMemberValue(name, constPool));
ann.addMemberValue("required", new BooleanMemberValue(true, constPool));
attr.addAnnotation(ann);
field.getFieldInfo().addAttribute(attr);
return field;
}
private static void annotateClassAnn(CtClass ctClass, ApiInfo apiInfo) {
ConstPool constPool = ctClass.getClassFile().getConstPool();
AnnotationsAttribute attr = getAnnotationAttr(ctClass);
annotateDeprecatedAnn(apiInfo, attr, constPool);
annotateApiAnn(apiInfo, attr, constPool);
ctClass.getClassFile().addAttribute(attr);
}
private static void annotateMethodAnn(CtClass ctClass,
ApiMethodInfo methodInfo) throws NotFoundException {
ConstPool constPool = ctClass.getClassFile().getConstPool();
for (CtMethod ctMethod : ctClass.getDeclaredMethods(methodInfo.methodName())) {
if (Stream.of(ctMethod.getParameterTypes()).map(CtClass::getSimpleName).collect(joining(", ")).equals(methodInfo.parameterNames())) {
AnnotationsAttribute attr = getAnnotationAttr(ctMethod);
annotateDeprecatedAnn(methodInfo, attr, constPool);
annotateApiMethodAnn(methodInfo, attr, constPool);
ctMethod.getMethodInfo().addAttribute(attr);
}
}
}
private static void annotateApiMethodAnn(ApiMethodInfo methodInfo, AnnotationsAttribute attr, ConstPool constPool) {
Annotation apiMethodAnn = attr.getAnnotation(ApiMethod.class.getTypeName());
MemberValue value;
if (isNull(apiMethodAnn)) {
apiMethodAnn = new Annotation(ApiMethod.class.getName(), constPool);
}
if (isNull(value = apiMethodAnn.getMemberValue(ApiMethodInfo.VALUE)) || StringUtils.isEmpty(((StringMemberValue) value).getValue())) {
apiMethodAnn.addMemberValue(ApiMethodInfo.VALUE, new StringMemberValue(methodInfo.value(), constPool));
}
if (isNull(value = apiMethodAnn.getMemberValue(HIDDEN)) || !((BooleanMemberValue) value).getValue()) {
apiMethodAnn.addMemberValue(HIDDEN, new BooleanMemberValue(methodInfo.hidden(), constPool));
}
if (isNull(value = apiMethodAnn.getMemberValue(NOTES)) || StringUtils.isEmpty(((StringMemberValue) value).getValue())) {
apiMethodAnn.addMemberValue(NOTES, new StringMemberValue(methodInfo.notes(), constPool));
}
ArrayMemberValue arrayMemberValue = (ArrayMemberValue) apiMethodAnn.getMemberValue("params");
if (isNull(arrayMemberValue)) {
arrayMemberValue = new ArrayMemberValue(constPool);
arrayMemberValue.setValue(new MemberValue[methodInfo.parameterCount()]);
}
AnnotationMemberValue annotationMemberValue;
for (int i = 0; i < methodInfo.parameterCount(); i++) {
if (isNull(annotationMemberValue = (AnnotationMemberValue) arrayMemberValue.getValue()[i])) {
annotationMemberValue = new AnnotationMemberValue(new Annotation(ApiParam.class.getName(), constPool), constPool);
}
Annotation apiParamAnn = annotationMemberValue.getValue();
if (isNull(value = apiParamAnn.getMemberValue(NAME)) || StringUtils.isEmpty(((StringMemberValue) value).getValue())) {
apiParamAnn.addMemberValue(NAME, new StringMemberValue(methodInfo.param(i).name(), constPool));
}
if (isNull(value = apiParamAnn.getMemberValue(ApiMethodInfo.VALUE)) || StringUtils.isEmpty(((StringMemberValue) value).getValue())) {
apiParamAnn.addMemberValue(ApiMethodInfo.VALUE, new StringMemberValue(methodInfo.param(i).value(), constPool));
}
arrayMemberValue.getValue()[i] = annotationMemberValue;
}
apiMethodAnn.addMemberValue(PARAMS, arrayMemberValue);
attr.addAnnotation(apiMethodAnn);
}
private static AnnotationsAttribute getAnnotationAttr(CtClass ctClass) {
for (Object o : ctClass.getClassFile().getAttributes()) {
if (o instanceof AnnotationsAttribute) {
return (AnnotationsAttribute) o;
}
}
return new AnnotationsAttribute(ctClass.getClassFile().getConstPool(), AnnotationsAttribute.visibleTag);
}