本文整理汇总了Java中javassist.bytecode.FieldInfo类的典型用法代码示例。如果您正苦于以下问题:Java FieldInfo类的具体用法?Java FieldInfo怎么用?Java FieldInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldInfo类属于javassist.bytecode包,在下文中一共展示了FieldInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassFields
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
public List<FieldInfo> getClassFields(String classname, ConstPool cp) {
ClassPathList list = pathList;
List<FieldInfo> fields = null;
while (list != null) {
if (!(list.path instanceof DalvikClassPath)) {
list = list.next;
continue;
}
fields = ((DalvikClassPath)list.path).getClassFields(classname, cp);
if (fields == null)
list = list.next;
else
return fields;
}
return null; // not found
}
示例2: scan
import javassist.bytecode.FieldInfo; //导入依赖的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));
}
}
}
示例3: addReadWriteMethods
import javassist.bytecode.FieldInfo; //导入依赖的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());
}
}
}
}
示例4: getDeclaredFields
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
private ArrayList<Signature> getDeclaredFields(boolean areStatic) {
if ((areStatic ? this.fieldsStatic : this.fieldsObject) == null) {
final ArrayList<Signature> fields = new ArrayList<Signature>();
@SuppressWarnings("unchecked")
final List<FieldInfo> fieldsJA = this.cf.getFields();
for (FieldInfo fld : fieldsJA) {
if (Modifier.isStatic(AccessFlag.toModifier(fld.getAccessFlags())) == areStatic) {
final Signature sig = new Signature(getClassName(), fld.getDescriptor(), fld.getName());
fields.add(sig);
}
}
if (areStatic) {
this.fieldsStatic = fields;
} else {
this.fieldsObject = fields;
}
}
return (areStatic ? this.fieldsStatic : this.fieldsObject);
}
示例5: getFields
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
public List<JField> getFields() {
boolean isJavaLangThrowable = "java.lang.Throwable".equals(this.getName());
boolean isJavaLangSystem = "java.lang.System".equals(this.getName());
final List<JField> retVal = new ArrayList<JField>();
@SuppressWarnings("unchecked")
final List<FieldInfo> fields = (List<FieldInfo>) getClassFile().getFields();
for (FieldInfo next : fields) {
if (isJavaLangThrowable && ("backtrace".equals(next.getName()))) {
// See http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=d7621f5189c86f127fe5737490903?bug_id=4496456
continue;
}
if (isJavaLangSystem && ("security".equals(next.getName()))) {
continue;
}
retVal.add(JField.getJField(next, this, getResolver()));
}
return retVal;
}
示例6: isConfigPropertyAnnotationPresent
import javassist.bytecode.FieldInfo; //导入依赖的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;
}
示例7: addReadWriteMethods
import javassist.bytecode.FieldInfo; //导入依赖的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 );
}
}
}
}
示例8: scan
import javassist.bytecode.FieldInfo; //导入依赖的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));
}
}
}
示例9: getClassFields
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
@Override
public List<FieldInfo> getClassFields(String classname, ConstPool cp) {
final Field[] fields = clazz.getDeclaredFields();
if (null == fields || 0 == fields.length) {
return null;
}
final ArrayList<FieldInfo> ret = new ArrayList<FieldInfo>();
for (Field f : fields) {
final FieldInfo fi = new FieldInfo(cp, f.getName(), Descriptor.of(f.getClass()));
ret.add(fi);
fi.setAccessFlags(f.getModifiers());
}
return ret;
}
示例10: addFields
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
private void addFields(ClassFile cfile, Class<?> clazz) {
final Field[] fields = clazz.getDeclaredFields();
if (null != fields && 0 < fields.length) {
for (Field f : fields) {
try {
final FieldInfo fi = new FieldInfo(cfile.getConstPool(), f.getName(), Descriptor.of(f.getType()));
fi.setAccessFlags(f.getModifiers());
cfile.addField(fi);
} catch (DuplicateMemberException e) {
e.printStackTrace();
}
}
}
}
示例11: makeFieldCache
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
private void makeFieldCache(CtMember.Cache cache) {
List<FieldInfo> list = getClassFile2().getFields();
if (null == list) {
return;
}
int n = list.size();
for (int i = 0; i < n; ++i) {
FieldInfo finfo = (FieldInfo)list.get(i);
CtField newField = new CtField(finfo, this);
cache.addField(newField);
}
}
示例12: removeField
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
public void removeField(CtField f) throws NotFoundException {
checkModify();
FieldInfo fi = f.getFieldInfo2();
ClassFile cf = getClassFile2();
if (cf.getFields().remove(fi)) {
getMembers().remove(f);
gcConstPool = true;
}
else
throw new NotFoundException(f.toString());
}
示例13: addFieldHandlerField
import javassist.bytecode.FieldInfo; //导入依赖的package包/类
private void addFieldHandlerField(ClassFile classfile)
throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
FieldInfo finfo = new FieldInfo(cp, HANDLER_FIELD_NAME,
HANDLER_FIELD_DESCRIPTOR);
finfo.setAccessFlags(AccessFlag.PRIVATE | AccessFlag.TRANSIENT);
classfile.addField(finfo);
}
示例14: discoverAndIntimateForFieldAnnotations
import javassist.bytecode.FieldInfo; //导入依赖的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());
}
}
}
}
示例15: scanFields
import javassist.bytecode.FieldInfo; //导入依赖的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());
}
}