@Override public void visitArrayMemberValue(ArrayMemberValue node) { MemberValue[] nestedValues = node.getValue(); for (MemberValue v : nestedValues) { v.accept(new ListingMemberValueVisitor(values) { @Override public void visitArrayMemberValue(ArrayMemberValue node) { values.add(Arrays.toString(node.getValue())); } }); } }
Object getValue(ClassLoader cl, ClassPool cp, Method method) throws ClassNotFoundException { if (values == null) throw new ClassNotFoundException( "no array elements found: " + method.getName()); int size = values.length; Class clazz; if (type == null) { clazz = method.getReturnType().getComponentType(); if (clazz == null || size > 0) throw new ClassNotFoundException("broken array type: " + method.getName()); } else clazz = type.getType(cl); Object a = Array.newInstance(clazz, size); for (int i = 0; i < size; i++) Array.set(a, i, values[i].getValue(cl, cp, method)); return a; }
/** * Constructs an annotation-type object representing this annotation. * For example, if this annotation represents <code>@Author</code>, * this method returns an <code>Author</code> object. * * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation * @throws ClassNotFoundException if the class cannot found. * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError { return AnnotationImpl.make(cl, MemberValue.loadClass(cl, getTypeName()), cp, this); }
return getDefault(name, method); else return mv.getValue(classLoader, pool, method);
/** * Writes the value. */ public void write(AnnotationsWriter writer) throws IOException { int num = values == null ? 0 : values.length; writer.arrayValue(num); for (int i = 0; i < num; ++i) values[i].write(writer); }
Class getType(ClassLoader cl) throws ClassNotFoundException { if (type == null) throw new ClassNotFoundException("no array type specified"); Object a = Array.newInstance(type.getType(cl), 0); return a.getClass(); }
static Class loadClass(ClassLoader cl, String classname) throws ClassNotFoundException, NoSuchClassError { try { return Class.forName(convertFromArray(classname), true, cl); } catch (LinkageError e) { throw new NoSuchClassError(classname, e); } }
try { if (mv != null) value = mv.getValue(classLoader, pool, methods[i]); if (value == null) value = getDefault(name, methods[i]);
/** * Writes the value. */ @Override public void write(AnnotationsWriter writer) throws IOException { int num = values == null ? 0 : values.length; writer.arrayValue(num); for (int i = 0; i < num; ++i) values[i].write(writer); }
@Override Class<?> getType(ClassLoader cl) throws ClassNotFoundException { if (type == null) throw new ClassNotFoundException("no array type specified"); Object a = Array.newInstance(type.getType(cl), 0); return a.getClass(); }
static Class<?> loadClass(ClassLoader cl, String classname) throws ClassNotFoundException, NoSuchClassError { try { return Class.forName(convertFromArray(classname), true, cl); } catch (LinkageError e) { throw new NoSuchClassError(classname, e); } }
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?) @SuppressWarnings("unchecked") 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; } }
@Override Object getValue(ClassLoader cl, ClassPool cp, Method method) throws ClassNotFoundException { if (values == null) throw new ClassNotFoundException( "no array elements found: " + method.getName()); int size = values.length; Class<?> clazz; if (type == null) { clazz = method.getReturnType().getComponentType(); if (clazz == null || size > 0) throw new ClassNotFoundException("broken array type: " + method.getName()); } else clazz = type.getType(cl); Object a = Array.newInstance(clazz, size); for (int i = 0; i < size; i++) Array.set(a, i, values[i].getValue(cl, cp, method)); return a; }
try { if (mv != null) value = mv.getValue(classLoader, pool, methods[i]); if (value == null) value = getDefault(name, methods[i]);
/** * Changes the default value represented by this attribute. * * @param value the new value. * @see javassist.bytecode.annotation.Annotation#createMemberValue(ConstPool, CtClass) */ public void setDefaultValue(MemberValue value) { ByteArrayOutputStream output = new ByteArrayOutputStream(); AnnotationsWriter writer = new AnnotationsWriter(output, constPool); try { value.write(writer); writer.close(); } catch (IOException e) { throw new RuntimeException(e); // should never reach here. } set(output.toByteArray()); }
Class getType(ClassLoader cl) throws ClassNotFoundException { if (type == null) throw new ClassNotFoundException("no array type specified"); Object a = Array.newInstance(type.getType(cl), 0); return a.getClass(); }
/** * Constructs an annotation-type object representing this annotation. * For example, if this annotation represents <code>@Author</code>, * this method returns an <code>Author</code> object. * * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation * @throws ClassNotFoundException if the class cannot found. * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError { Class<?> clazz = MemberValue.loadClass(cl, getTypeName()); try { return AnnotationImpl.make(cl, clazz, cp, this); } catch (IllegalArgumentException e) { /* AnnotationImpl.make() may throw this exception * when it fails to make a proxy object for some * reason. */ throw new ClassNotFoundException(clazz.getName(), e); } catch (IllegalAccessError e2) { // also IllegalAccessError throw new ClassNotFoundException(clazz.getName(), e2); } }
static Class loadClass(ClassLoader cl, String classname) throws ClassNotFoundException, NoSuchClassError { try { return Class.forName(convertFromArray(classname), true, cl); } catch (LinkageError e) { throw new NoSuchClassError(classname, e); } }
@Override public void visitArrayMemberValue(ArrayMemberValue node) { MemberValue[] nestedValues = node.getValue(); for (MemberValue v : nestedValues) { v.accept(new ListingMemberValueVisitor(values) { @Override public void visitArrayMemberValue(ArrayMemberValue node) { values.add(Arrays.toString(node.getValue())); } }); } }
Object getValue(ClassLoader cl, ClassPool cp, Method method) throws ClassNotFoundException { if (values == null) throw new ClassNotFoundException( "no array elements found: " + method.getName()); int size = values.length; Class clazz; if (type == null) { clazz = method.getReturnType().getComponentType(); if (clazz == null || size > 0) throw new ClassNotFoundException("broken array type: " + method.getName()); } else clazz = type.getType(cl); Object a = Array.newInstance(clazz, size); for (int i = 0; i < size; i++) Array.set(a, i, values[i].getValue(cl, cp, method)); return a; }