public JavassistDynamicField(DynamicBean dynamicBean, CtClass clazz, ConstPool cpool, String fieldName) { try { this.dynamicBean = dynamicBean; this.cpool = cpool; this.cfield = clazz.getField(fieldName); attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag); } catch (NotFoundException e) { log.error(fieldName + " not found"); } }
protected AnnotationsAttribute stripAnnotation(ConstPool constantPool, List<?> attributes) { Iterator<?> itr = attributes.iterator(); AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag); while (itr.hasNext()) { Object object = itr.next(); if (AnnotationsAttribute.class.isAssignableFrom(object.getClass())) { AnnotationsAttribute attr = (AnnotationsAttribute) object; Annotation[] items = attr.getAnnotations(); for (Annotation annotation : items) { String typeName = annotation.getTypeName(); if (typeName.equals(annotationClass)) { logger.debug(String.format("Stripping out %s annotation", annotationClass)); continue; } annotationsAttribute.addAnnotation(annotation); } itr.remove(); } } return annotationsAttribute; }
/** * Copies this attribute and returns a new copy. */ public AttributeInfo copy(ConstPool newCp, Map classnames) { Copier copier = new Copier(info, constPool, newCp, classnames); try { copier.annotationArray(); return new AnnotationsAttribute(newCp, getName(), copier.close()); } catch (Exception e) { throw new RuntimeException(e); } }
Class<?> type = parameterTypes[i]; Annotation[] annotations = parameterAnnotations[i]; AnnotationsAttribute attribute = new AnnotationsAttribute(classFile.getConstPool(), AnnotationsAttribute.visibleTag); for (Annotation annotation : annotations) { if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
Class<?> type = parameterTypes[i]; Annotation[] annotations = parameterAnnotations[i]; AnnotationsAttribute attribute = new AnnotationsAttribute(classFile.getConstPool(), AnnotationsAttribute.visibleTag); for (Annotation annotation : annotations) { if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
/** * Copies this attribute and returns a new copy. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { Copier copier = new Copier(info, constPool, newCp, classnames); try { copier.annotationArray(); return new AnnotationsAttribute(newCp, getName(), copier.close()); } catch (Exception e) { throw new RuntimeException(e); } }
|| nameStr.equals(AnnotationsAttribute.invisibleTag)) { return new AnnotationsAttribute(cp, name, in);
private static void addAnnotations(FieldInfo fieldInfo, Class<?>[] annotations) { AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) fieldInfo.getAttribute( AnnotationsAttribute.visibleTag ); if ( annotationsAttribute == null ) { annotationsAttribute = new AnnotationsAttribute( fieldInfo.getConstPool(), AnnotationsAttribute.visibleTag ); fieldInfo.addAttribute( annotationsAttribute ); } for (Class<?> annotation : annotations) { annotationsAttribute.addAnnotation( new Annotation( annotation.getName(), fieldInfo.getConstPool() ) ); } }
AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag); List<?> attributes = classFile.getAttributes(); Iterator<?> itr = attributes.iterator();
|| nameStr.equals(AnnotationsAttribute.invisibleTag)) return new AnnotationsAttribute(cp, name, in); else if (nameStr.equals(ParameterAnnotationsAttribute.visibleTag) || nameStr.equals(ParameterAnnotationsAttribute.invisibleTag))
@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); }); }
List<?> attributes = myField.getAttributes(); Iterator<?> itr = attributes.iterator(); AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag); while (itr.hasNext()) { Object object = itr.next();
ClassFile classFile = new ClassFile(new DataInputStream(new ByteArrayInputStream(classfileBuffer))); ConstPool constantPool = classFile.getConstPool(); AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag); List<?> attributes = classFile.getAttributes(); Iterator<?> itr = attributes.iterator();
AnnotationsAttribute attributeInfo = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); for (JSR303AnnotationInfo jsr303AnnotationInfo : jsr303) { Class<? extends java.lang.annotation.Annotation> jsr303Ann = jsr303AnnotationInfo.getAnnotation();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); Annotation annot = new Annotation("org.mengyun.tcctransaction.api.Compensable", constpool); EnumMemberValue enumMemberValue = new EnumMemberValue(constpool);
ConstPool constpool = ccFile.getConstPool(); AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); Annotation annot = new Annotation("org.junit.BeforeClass", constpool);
@Override public JavassistDynamicBean gecco(String[] matchUrl, String downloader, int timeout, String... pipelines) { AnnotationsAttribute attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag);
private static AnnotationsAttribute addSimplifiedMethodAnnotation(AnnotationsAttribute annotations, ConstPool constPool) { if (annotations == null) { annotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); } annotations.addAnnotation(new Annotation(SimplifiedMethod.class.getName(), constPool)); return annotations; } }
public static void addClassAnnotation(CtClass clazz, javassist.bytecode.annotation.Annotation annotation) { ClassFile classFile = clazz.getClassFile(); AnnotationsAttribute attribute = (AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag); if (attribute == null) attribute = new AnnotationsAttribute(classFile.getConstPool(), AnnotationsAttribute.visibleTag); attribute.addAnnotation(annotation); classFile.addAttribute(attribute); }
private static void annotateField(CtField field, Annotation annotation) { ClassFile clsFile = field.getDeclaringClass().getClassFile(); ConstPool constPool = clsFile.getConstPool(); FieldInfo fieldInfo = field.getFieldInfo2(); AnnotationsAttribute attr = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag); if (attr == null) { attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); fieldInfo.addAttribute(attr); } attr.addAnnotation(annotation); }