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; } }
String typeName = annotation.getTypeName(); if (typeName.equals(Table.class.getName())) { Set<String> keys = annotation.getMemberNames(); for (String key : keys) { if (key.equalsIgnoreCase("name")) {
@SuppressWarnings( "unchecked" ) AnnotationMetadata( Annotation annotation ) { this.annotationClassName = annotation.getTypeName(); Set<Object> memberNames = annotation.getMemberNames(); if (memberNames != null) { Map<String, String> members = new HashMap<String, String>(memberNames.size()); for (Object rawMemberName : memberNames) { String memberName = (String)rawMemberName; members.put(memberName, annotation.getMemberValue(memberName).toString()); } this.memberValues = Collections.unmodifiableMap(members); } else { this.memberValues = Collections.emptyMap(); } }
@SuppressWarnings( "unchecked" ) AnnotationMetadata( Annotation annotation ) { this.annotationClassName = annotation.getTypeName(); Set<Object> memberNames = annotation.getMemberNames(); if (memberNames != null) { Map<String, String> members = new HashMap<String, String>(memberNames.size()); for (Object rawMemberName : memberNames) { String memberName = (String)rawMemberName; members.put(memberName, annotation.getMemberValue(memberName).toString()); } this.memberValues = Collections.unmodifiableMap(members); } else { this.memberValues = Collections.emptyMap(); } }
public Object visit(ASTSingleMemberValue node, Object data) { if (base.getMemberNames().size() > 1) throw new RuntimeException("single value expected from annotation: " + base.getTypeName()); Set<String> set = base.getMemberNames(); MemberValue mv = base.getMemberValue(set.iterator().next()); node.getValue().jjtAccept(this, mv); return data; }
@SuppressWarnings( "unchecked" ) AnnotationMetadata( Annotation annotation ) { this.annotationClassName = annotation.getTypeName(); Set<Object> memberNames = annotation.getMemberNames(); if (memberNames != null) { Map<String, String> members = new HashMap<String, String>(memberNames.size()); for (Object rawMemberName : memberNames) { String memberName = (String)rawMemberName; members.put(memberName, annotation.getMemberValue(memberName).toString()); } this.memberValues = Collections.unmodifiableMap(members); } else { this.memberValues = Collections.emptyMap(); } }
public static void printAnnotation(Annotation info) { System.out.print("@" + info.getTypeName()); Set<String> members = info.getMemberNames(); if (members != null) { System.out.print("("); Iterator<String> mit = members.iterator(); while (mit.hasNext()) { String name = mit.next(); System.out.print(name + "=" + info.getMemberValue(name).toString()); if (mit.hasNext()) System.out.print(", "); } System.out.print(")"); } System.out.println(""); } }
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; } }
private Map<String, Optional<MemberValue>> buildMemberValueMap(Annotation annotation) { Map<String, Optional<MemberValue>> map = new HashMap<>(); @SuppressWarnings("unchecked") Set<String> memberNames = annotation.getMemberNames(); if (memberNames != null) { for (String memberName : memberNames) { MemberValue memberValue = annotation.getMemberValue(memberName); if (memberValue == null) { map.put(memberName, Optional.<MemberValue>absent()); } else { map.put(memberName, Optional.of(memberValue)); } } } return map; }
private void addAnnotations(Collection<String> imports, AnnotationsAttribute annotations) { if (annotations != null) { for (Annotation each : annotations.getAnnotations()) { imports.add(each.getTypeName()); final Set<String> memberNames = each.getMemberNames(); if (memberNames != null) { for (String memberName : memberNames) { imports.addAll(addSubtypes(each, memberName)); } } } } }
private Map<String, Optional<MemberValue>> buildMemberValueMap(Annotation annotation) { Map<String, Optional<MemberValue>> map = new HashMap<>(); @SuppressWarnings("unchecked") Set<String> memberNames = annotation.getMemberNames(); if (memberNames != null) { for (String memberName : memberNames) { MemberValue memberValue = annotation.getMemberValue(memberName); if (memberValue == null) { map.put(memberName, Optional.<MemberValue>absent()); } else { map.put(memberName, Optional.of(memberValue)); } } } return map; }
@XmlElementWrapper(name = "values") @XmlElement(name = "value") public List<JApiAnnotationElementValue> getValues() { List<JApiAnnotationElementValue> values = new ArrayList<>(); if (type == Type.Array) { if (value instanceof MemberValue[]) { MemberValue[] memberValues = (MemberValue[]) value; for (MemberValue memberValue : memberValues) { JApiAnnotationElementValue elementValue = JApiAnnotationElement.getMemberValue(memberValue); values.add(elementValue); } } } else if (type == Type.Annotation) { if (value instanceof Annotation) { Annotation annotation = (Annotation) value; @SuppressWarnings("unchecked") Set<String> memberNames = annotation.getMemberNames(); if (memberNames != null) { for (String memberName : memberNames) { MemberValue memberValue = annotation.getMemberValue(memberName); JApiAnnotationElementValue elementValue = JApiAnnotationElement.getMemberValue(memberValue); elementValue.setName(Optional.of(memberName)); values.add(elementValue); } } } } return values; }
@XmlElementWrapper(name = "values") @XmlElement(name = "value") public List<JApiAnnotationElementValue> getValues() { List<JApiAnnotationElementValue> values = new ArrayList<>(); if (type == Type.Array) { if (value instanceof MemberValue[]) { MemberValue[] memberValues = (MemberValue[]) value; for (MemberValue memberValue : memberValues) { JApiAnnotationElementValue elementValue = JApiAnnotationElement.getMemberValue(memberValue); values.add(elementValue); } } } else if (type == Type.Annotation) { if (value instanceof Annotation) { Annotation annotation = (Annotation) value; @SuppressWarnings("unchecked") Set<String> memberNames = annotation.getMemberNames(); if (memberNames != null) { for (String memberName : memberNames) { MemberValue memberValue = annotation.getMemberValue(memberName); JApiAnnotationElementValue elementValue = JApiAnnotationElement.getMemberValue(memberValue); elementValue.setName(Optional.of(memberName)); values.add(elementValue); } } } } return values; }
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; } }
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; } }
/** * 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; }
/** * 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; }
if (annotation.getMemberNames() != null) { for (Object memberName : annotation.getMemberNames()) { MemberValue memberValue = annotation.getMemberValue((String) memberName); if (memberValue != null) {
private static void inheritAnnotations(final CtClass theClass, final CtMethod theMethod) throws NotFoundException { if (hasMethod(theClass, theMethod)) { CtMethod aOtherMethod = theClass.getMethod(theMethod.getName(), theMethod.getSignature()); // method we're probably overriding or implementing in the case of an abstract method. AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) aOtherMethod.getMethodInfo().getAttribute(AnnotationsAttribute.visibleTag); if (annotationsAttribute != null) { ConstPool cp = theClass.getClassFile().getConstPool(); AnnotationsAttribute attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag); for (Object obj : annotationsAttribute.getAnnotations()) { Annotation a = (Annotation) obj; Annotation theAnnotation = new Annotation(a.getTypeName(), cp); if (a.getMemberNames() != null) { for (Object aName : a.getMemberNames()) { theAnnotation.addMemberValue(aName.toString(), a.getMemberValue(aName.toString())); } } attr.addAnnotation(theAnnotation); } theMethod.getMethodInfo().addAttribute(attr); } } }