Java Code Examples for javassist.bytecode.FieldInfo#getAttribute()
The following examples show how to use
javassist.bytecode.FieldInfo#getAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassPathScanner.java From Bats with Apache License 2.0 | 6 votes |
@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)); } } }
Example 2
Source File: ClassPathScanner.java From dremio-oss with Apache License 2.0 | 5 votes |
@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); @SuppressWarnings("unchecked") 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)); final List<AnnotationDescriptor> annotationDescriptors = (fieldAnnotations != null) ? getAnnotationDescriptors(fieldAnnotations) : Collections.<AnnotationDescriptor>emptyList(); fieldDescriptors.add(new FieldDescriptor(fieldName, field.getDescriptor(), annotationDescriptors)); } functions.add(new AnnotatedClassDescriptor(classFile.getName(), classAnnotations, fieldDescriptors)); } } }
Example 3
Source File: AnnotationDB.java From audit4j-core with Apache License 2.0 | 5 votes |
protected void scanFields(ClassFile cf) { List<ClassFile> fields = cf.getFields(); if (fields == null) return; for (Object obj : fields) { FieldInfo field = (FieldInfo) obj; AnnotationsAttribute visible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.visibleTag); AnnotationsAttribute invisible = (AnnotationsAttribute) field .getAttribute(AnnotationsAttribute.invisibleTag); if (visible != null) populate(visible.getAnnotations(), cf.getName()); if (invisible != null) populate(invisible.getAnnotations(), cf.getName()); } }
Example 4
Source File: ClassFileJavassist.java From jbse with GNU General Public License v3.0 | 5 votes |
@Override public String getFieldGenericSignatureType(Signature fieldSignature) throws FieldNotFoundException { final FieldInfo fld = findField(fieldSignature); if (fld == null) { throw new FieldNotFoundException(fieldSignature.toString()); } SignatureAttribute sa = (SignatureAttribute) fld.getAttribute(SignatureAttribute.tag); return (sa == null ? null : sa.getSignature()); }
Example 5
Source File: ClassFileJavassist.java From jbse with GNU General Public License v3.0 | 5 votes |
@Override public byte[] getFieldAnnotationsRaw(Signature fieldSignature) throws FieldNotFoundException { final FieldInfo fld = findField(fieldSignature); if (fld == null) { throw new FieldNotFoundException(fieldSignature.toString()); } final AttributeInfo attrVisible = fld.getAttribute(AnnotationsAttribute.visibleTag); final AttributeInfo attrInvisible = fld.getAttribute(AnnotationsAttribute.invisibleTag); return mergeVisibleAndInvisibleAttributes(attrVisible, attrInvisible); }
Example 6
Source File: ClassScanner.java From startup-os with Apache License 2.0 | 4 votes |
private ImmutableList<Field> getPackageFields(String packageName) throws IOException { ImmutableList.Builder<Field> result = ImmutableList.builder(); Set<String> classes = new HashSet<>(); String resourceName = resourceName(packageName); Enumeration<URL> urls = ClassLoader.getSystemClassLoader().getResources(resourceName); while (urls.hasMoreElements()) { URL url = urls.nextElement(); JarFile jarFile = getJarFile(url); Enumeration<? extends ZipEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { ClassFile classFile = getClassFile(jarFile, entries.nextElement()); if (classFile == null) { continue; } if (!classes.add(classFile.getName())) { // We've already gone through this class - skip continue; } for (Object fieldInfoObject : classFile.getFields()) { FieldInfo fieldInfo = (FieldInfo) fieldInfoObject; AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag); if (annotationsAttribute != null) { for (Annotation annotation : annotationsAttribute.getAnnotations()) { try { if (FlagDesc.class.getName().equals(annotation.getTypeName())) { Class clazz = ClassLoader.getSystemClassLoader().loadClass(classFile.getName()); Field field = clazz.getDeclaredField(fieldInfo.getName()); if (Flag.class.isAssignableFrom(field.getType())) { result.add(field); } else { throw new IllegalArgumentException( "Field annotated with FlagDesc does not inherit from Flag " + field); } } } catch (Exception e) { e.printStackTrace(); } } } } } } return result.build(); }
Example 7
Source File: JavassistAnnotationsHelper.java From jadira with Apache License 2.0 | 3 votes |
public static Annotation[] getAnnotationsForFieldInfo(FieldInfo fieldInfo) { AnnotationsAttribute visible = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag); AnnotationsAttribute invisible = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.invisibleTag); Set<Annotation> retVal = new HashSet<Annotation>(); retVal.addAll(findAnnotationsForAnnotationsAttribute(visible)); retVal.addAll(findAnnotationsForAnnotationsAttribute(invisible)); return retVal.toArray(new Annotation[retVal.size()]); }