本文整理汇总了Java中javassist.bytecode.ClassFile.getFields方法的典型用法代码示例。如果您正苦于以下问题:Java ClassFile.getFields方法的具体用法?Java ClassFile.getFields怎么用?Java ClassFile.getFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.ClassFile
的用法示例。
在下文中一共展示了ClassFile.getFields方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scan
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
@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));
fieldDescriptors.add(new FieldDescriptor(fieldName, field.getDescriptor(), getAnnotationDescriptors(fieldAnnotations)));
}
functions.add(new AnnotatedClassDescriptor(classFile.getName(), classAnnotations, fieldDescriptors));
}
}
}
示例2: addReadWriteMethods
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void addReadWriteMethods(ClassFile classfile)
throws CannotCompileException {
List fields = classfile.getFields();
for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
FieldInfo finfo = (FieldInfo) field_iter.next();
if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0
&& (!finfo.getName().equals(HANDLER_FIELD_NAME))) {
// case of non-static field
if (filter.handleRead(finfo.getDescriptor(), finfo
.getName())) {
addReadMethod(classfile, finfo);
readableFields.put(finfo.getName(), finfo
.getDescriptor());
}
if (filter.handleWrite(finfo.getDescriptor(), finfo
.getName())) {
addWriteMethod(classfile, finfo);
writableFields.put(finfo.getName(), finfo
.getDescriptor());
}
}
}
}
示例3: isConfigPropertyAnnotationPresent
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private static boolean isConfigPropertyAnnotationPresent(ClassFile cf, Log log) {
AttributeInfo classAttribute = cf.getAttribute(AnnotationsAttribute.visibleTag);
if (classAttribute != null) {
if (findAnnotation(cf, log, classAttribute, "com.avast.syringe.config.ConfigBean")) {
return true;
}
}
List<FieldInfo> fields = cf.getFields();
for (FieldInfo field : fields) {
AttributeInfo fieldAttribute = field.getAttribute(AnnotationsAttribute.visibleTag);
if (fieldAttribute != null) {
if (findAnnotation(cf, log, fieldAttribute, "com.avast.syringe.config.ConfigProperty")) {
return true;
}
}
}
return false;
}
示例4: addReadWriteMethods
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void addReadWriteMethods(ClassFile classfile) throws CannotCompileException, BadBytecode {
final List fields = classfile.getFields();
for ( Object field : fields ) {
final FieldInfo finfo = (FieldInfo) field;
if ( (finfo.getAccessFlags() & AccessFlag.STATIC) == 0 && (!finfo.getName().equals( HANDLER_FIELD_NAME )) ) {
// case of non-static field
if ( filter.handleRead( finfo.getDescriptor(), finfo.getName() ) ) {
addReadMethod( classfile, finfo );
}
if ( filter.handleWrite( finfo.getDescriptor(), finfo.getName() ) ) {
addWriteMethod( classfile, finfo );
}
}
}
}
示例5: scan
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
@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));
}
}
}
示例6: discoverAndIntimateForFieldAnnotations
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
/**
* Discovers Field Annotations
*
* @param classFile
*/
private void discoverAndIntimateForFieldAnnotations (ClassFile classFile) {
@SuppressWarnings("unchecked")
List<FieldInfo> fields = classFile.getFields();
if (fields == null) {
return;
}
for (FieldInfo fieldInfo : fields) {
Set<Annotation> annotations = new HashSet<Annotation>();
AnnotationsAttribute visible = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag);
AnnotationsAttribute invisible = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.invisibleTag);
if (visible != null) {
annotations.addAll(Arrays.asList(visible.getAnnotations()));
}
if (invisible != null) {
annotations.addAll(Arrays.asList(invisible.getAnnotations()));
}
// now tell listeners
for (Annotation annotation : annotations) {
Set<FieldAnnotationDiscoveryListener> listeners = fieldAnnotationListeners.get(annotation.getTypeName());
if (null == listeners) {
continue;
}
for (FieldAnnotationDiscoveryListener listener : listeners) {
listener.discovered(classFile.getName(), fieldInfo.getName(), annotation.getTypeName());
}
}
}
}
示例7: scanFields
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
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());
}
}
示例8: renameClasses
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void renameClasses(CtClass c, ClassNameReplacer replacer) {
// sadly, we can't use CtClass.renameClass() because SignatureAttribute.renameClass() is extremely buggy =(
ReplacerClassMap map = new ReplacerClassMap(replacer);
ClassFile classFile = c.getClassFile();
// rename the constant pool (covers ClassInfo, MethodTypeInfo, and NameAndTypeInfo)
ConstPool constPool = c.getClassFile().getConstPool();
constPool.renameClass(map);
// rename class attributes
renameAttributes(classFile.getAttributes(), map, SignatureType.Class);
// rename methods
for (MethodInfo methodInfo : (List<MethodInfo>)classFile.getMethods()) {
methodInfo.setDescriptor(Descriptor.rename(methodInfo.getDescriptor(), map));
renameAttributes(methodInfo.getAttributes(), map, SignatureType.Method);
}
// rename fields
for (FieldInfo fieldInfo : (List<FieldInfo>)classFile.getFields()) {
fieldInfo.setDescriptor(Descriptor.rename(fieldInfo.getDescriptor(), map));
renameAttributes(fieldInfo.getAttributes(), map, SignatureType.Field);
}
// rename the class name itself last
// NOTE: don't use the map here, because setName() calls the buggy SignatureAttribute.renameClass()
// we only want to replace exactly this class name
String newName = renameClassName(c.getName(), map);
if (newName != null) {
c.setName(newName);
}
// replace simple names in the InnerClasses attribute too
InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute(InnerClassesAttribute.tag);
if (attr != null) {
for (int i = 0; i < attr.tableLength(); i++) {
// get the inner class full name (which has already been translated)
ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(attr.innerClass(i)));
if (attr.innerNameIndex(i) != 0) {
// update the inner name
attr.setInnerNameIndex(i, constPool.addUtf8Info(classEntry.getInnermostClassName()));
}
/* DEBUG
System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i)));
*/
}
}
}