@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())); } }); } }
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 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())); } }); } }
public void visitArrayMemberValue(ArrayMemberValue node) { MemberValue[] values = node.getValue(); value = node.getValue(); Object vals = Array.newInstance(getAttributeType(), values.length); for (int i = 0 ; i < values.length ; i++) { values[i].accept(this); Array.set(vals, i, value); } value = vals; }
public Object visit(ASTIdentifier node, Object data) { MemberValue mv = (MemberValue) data; MemberValuePopulate mvc = new MemberValuePopulate(node.getValue()); mv.accept(mvc); return null; }
public void visitArrayMemberValue(ArrayMemberValue node) { MemberValue[] values = node.getValue(); value = node.getValue(); Object vals = Array.newInstance(getAttributeType(), values.length); for (int i = 0 ; i < values.length ; i++) { values[i].accept(this); Array.set(vals, i, value); } value = vals; }
@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())); } }); } }
/** * @param classPool class pool to use * @param constPool constants pool * @param ann annotation to copy * @return javassist annotation object (copy of original annotation) * @throws Exception on errors */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public static Annotation copyAnnotation(final ClassPool classPool, final ConstPool constPool, final java.lang.annotation.Annotation ann) throws Exception { final Class<? extends java.lang.annotation.Annotation> annotationType = ann.annotationType(); final Annotation copy = new Annotation(annotationType.getName(), constPool); final Method[] methods = annotationType.getDeclaredMethods(); for (final Method method : methods) { final CtClass ctType = classPool.get(method.getReturnType().getName()); final MemberValue memberValue = Annotation.createMemberValue(constPool, ctType); final Object value = method.invoke(ann); memberValue.accept(new AnnotationMemberValueVisitor(classPool, constPool, value)); copy.addMemberValue(method.getName(), memberValue); } return copy; }
public static Map<String, Object> createProxyMap(Class annotation, javassist.bytecode.annotation.Annotation info) { Map<String, Object> map = new HashMap<String, Object>(); if (info.getMemberNames() == null) return map; Set members = info.getMemberNames(); Iterator it = members.iterator(); while (it.hasNext()) { String name = (String) it.next(); MemberValue mv = info.getMemberValue(name); ProxyMapCreator creator = new ProxyMapCreator(getMemberType(annotation, name)); mv.accept(creator); map.put(name, creator.value); } return map; } }
@SuppressWarnings("unchecked") public static Map<String, Object> createProxyMap(Class<?> annotation, javassist.bytecode.annotation.Annotation info) { Map<String, Object> map = new HashMap<String, Object>(); if (info.getMemberNames() == null) return map; Set members = info.getMemberNames(); Iterator it = members.iterator(); while (it.hasNext()) { String name = (String) it.next(); MemberValue mv = info.getMemberValue(name); ProxyMapCreator creator = new ProxyMapCreator(getMemberType(annotation, name)); mv.accept(creator); map.put(name, creator.value); } return map; } }
public void visitArrayMemberValue(ArrayMemberValue arrayMemberValue) { Class baseType = type.getComponentType(); int size = 0; if (arrayMemberValue.getValue() != null) { size = arrayMemberValue.getValue().length; } value = Array.newInstance(baseType, size); MemberValue[] elements = arrayMemberValue.getValue(); for (int i = 0; i < size; i++) { ProxyMapCreator creator = new ProxyMapCreator(baseType); elements[i].accept(creator); Array.set(value, i, creator.value); } }
public void visitArrayMemberValue(ArrayMemberValue arrayMemberValue) { Class<?> baseType = type.getComponentType(); int size = 0; if (arrayMemberValue.getValue() != null) { size = arrayMemberValue.getValue().length; } value = Array.newInstance(baseType, size); MemberValue[] elements = arrayMemberValue.getValue(); for (int i = 0; i < size; i++) { ProxyMapCreator creator = new ProxyMapCreator(baseType); elements[i].accept(creator); Array.set(value, i, creator.value); } }
private Collection<String> addSubtypes(Annotation each, String memberName) { final ClassExtractorAnnotationMemberValue classExtractorAnnotationMemberValue = new ClassExtractorAnnotationMemberValue(); each.getMemberValue(memberName).accept(classExtractorAnnotationMemberValue); return classExtractorAnnotationMemberValue.getImports(); }
private MemberValue createValue(final Object value) throws Exception { final MemberValue memberValue = Annotation.createMemberValue( this.constPool, getCtClass(classPool, getClass(value))); memberValue.accept(new AnnotationMemberValueVisitor(this.classPool, this.constPool, value)); return memberValue; }
private List<AnnotationDescriptor> getAnnotationDescriptors(AnnotationsAttribute annotationsAttr) { 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; } }
public Object visit(ASTMemberValueArrayInitializer node, Object data) { ArrayMemberValue mv = (ArrayMemberValue) data; int size = node.jjtGetNumChildren(); MemberValue[] elements = new MemberValue[size]; MemberValueCreation mvc = new MemberValueCreation(cp); for (int i = 0; i < size; i++) { mv.getType().accept(mvc); elements[i] = mvc.value; node.jjtGetChild(i).jjtAccept(this, elements[i]); } mv.setValue(elements); return null; }
@Override public void visitArrayMemberValue(ArrayMemberValue node) { ArrayMemberValue val = new ArrayMemberValue(node.getType(), constPool); MemberValue[] newVals = new MemberValue[node.getValue().length]; for (int i = 0; i < node.getValue().length; ++i) { node.getValue()[i].accept(new ArrayIndexAssigningVisitor(newVals, i, constPool)); } val.setValue(newVals); array[index] = val; }
@Override public void visitArrayMemberValue(ArrayMemberValue node) { ArrayMemberValue val = new ArrayMemberValue(node.getType(), constPool); MemberValue[] newVals = new MemberValue[node.getValue().length]; for (int i = 0; i < node.getValue().length; ++i) { node.getValue()[i].accept(new ArrayIndexAssigningVisitor(newVals, i, constPool)); } val.setValue(newVals); array[index] = val; }
/** * Copies the provided annotation into the provided const pool. * * @param annotation {@link Annotation} * @param constPool {@link ConstPool} * @return {@link Annotation} * @throws NotFoundException If Not Found */ public static Annotation cloneAnnotation(Annotation annotation, final ConstPool constPool) throws NotFoundException { Annotation ret = new Annotation(annotation.getTypeName(), constPool); if (annotation.getMemberNames() != null) { for (Object m : annotation.getMemberNames()) { final String memberName = (String) m; MemberValue origValue = annotation.getMemberValue(memberName); final MemberValue[] newValue = new MemberValue[1]; origValue.accept(new ArrayIndexAssigningVisitor(newValue, 0, constPool)); ret.addMemberValue(memberName, newValue[0]); } } return ret; }
/** * Copies the provided annotation into the provided const pool. * * @param annotation * @param constPool * @return * @throws NotFoundException */ private static Annotation cloneAnnotation(Annotation annotation, final ConstPool constPool) throws NotFoundException { Annotation ret = new Annotation(annotation.getTypeName(), constPool); if (annotation.getMemberNames() != null) { for (Object m : annotation.getMemberNames()) { final String memberName = (String) m; MemberValue origValue = annotation.getMemberValue(memberName); final MemberValue[] newValue = new MemberValue[1]; origValue.accept(new ArrayIndexAssigningVisitor(newValue, 0, constPool)); ret.addMemberValue(memberName, newValue[0]); } } return ret; }