本文整理汇总了Java中javassist.bytecode.FieldInfo.getName方法的典型用法代码示例。如果您正苦于以下问题:Java FieldInfo.getName方法的具体用法?Java FieldInfo.getName怎么用?Java FieldInfo.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.FieldInfo
的用法示例。
在下文中一共展示了FieldInfo.getName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
}
示例2: 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);
}
示例3: 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));
}
}
}
示例4: generateFieldWriter
import javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
private CtMethod generateFieldWriter(
CtClass managedCtClass,
CtField persistentField,
AttributeTypeDescriptor typeDescriptor) {
final FieldInfo fieldInfo = persistentField.getFieldInfo();
final String fieldName = fieldInfo.getName();
final String writerName = EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + fieldName;
final CtMethod writer;
try {
if ( !enhancementContext.isLazyLoadable( persistentField ) ) {
// not lazy-loadable...
writer = CtNewMethod.setter( writerName, persistentField );
}
else {
final String methodBody = typeDescriptor.buildWriteInterceptionBodyFragment( fieldName );
writer = CtNewMethod.make(
Modifier.PRIVATE,
CtClass.voidType,
writerName,
new CtClass[] {persistentField.getType()},
null,
"{" + methodBody + "}",
managedCtClass
);
}
if ( enhancementContext.doDirtyCheckingInline( managedCtClass ) && !isComposite ) {
writer.insertBefore( typeDescriptor.buildInLineDirtyCheckingBodyFragment( persistentField ) );
}
if ( isComposite ) {
StringBuilder builder = new StringBuilder();
builder.append( " if( " )
.append( EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME )
.append( " != null) " )
.append( EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME )
.append( ".callOwner(\"." )
.append( persistentField.getName() )
.append( "\");" );
writer.insertBefore( builder.toString() );
}
//composite types
if ( persistentField.getAnnotation( Embedded.class ) != null ) {
//make sure to add the CompositeOwner interface
if ( !doClassInheritCompositeOwner( managedCtClass ) ) {
managedCtClass.addInterface( classPool.get( "org.hibernate.engine.spi.CompositeOwner" ) );
}
//if a composite have a embedded field we need to implement the method as well
if ( isComposite ) {
createTrackChangeCompositeMethod( managedCtClass );
}
writer.insertBefore( cleanupPreviousOwner( persistentField ) );
writer.insertAfter( compositeMethodBody( persistentField ) );
}
managedCtClass.addMethod( writer );
return writer;
}
catch (Exception e) {
throw new EnhancementException(
String.format(
"Could not enhance entity class [%s] to add field writer method [%s]",
managedCtClass.getName(),
writerName
),
e
);
}
}
示例5: addReadMethod
import javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
private void addReadMethod(ClassFile classfile, FieldInfo finfo) throws CannotCompileException, BadBytecode {
final ConstPool constPool = classfile.getConstPool();
final int thisClassInfo = constPool.getThisClassInfo();
final String readMethodDescriptor = "()" + finfo.getDescriptor();
final MethodInfo readMethodInfo = new MethodInfo(
constPool,
EACH_READ_METHOD_PREFIX + finfo.getName(),
readMethodDescriptor
);
/* local variables | target obj | each oldvalue | */
final Bytecode code = new Bytecode(constPool, 5, 3);
// aload_0
code.addAload( 0 );
// getfield // get each field
code.addOpcode( Opcode.GETFIELD );
final int baseFieldIndex = constPool.addFieldrefInfo( thisClassInfo, finfo.getName(), finfo.getDescriptor() );
code.addIndex( baseFieldIndex );
// aload_0
code.addAload( 0 );
// invokeinterface : invoke Enabled.getInterceptFieldCallback()
final int enabledClassIndex = constPool.addClassInfo( FIELD_HANDLED_TYPE_NAME );
code.addInvokeinterface(
enabledClassIndex,
GETFIELDHANDLER_METHOD_NAME,
GETFIELDHANDLER_METHOD_DESCRIPTOR,
1
);
// ifnonnull
code.addOpcode( Opcode.IFNONNULL );
code.addIndex( 4 );
// *return // each type
addTypeDependDataReturn( code, finfo.getDescriptor() );
// *store_1 // each type
addTypeDependDataStore( code, finfo.getDescriptor(), 1 );
// aload_0
code.addAload( 0 );
// invokeinterface // invoke Enabled.getInterceptFieldCallback()
code.addInvokeinterface(
enabledClassIndex,
GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
1
);
// aload_0
code.addAload( 0 );
// ldc // name of the field
code.addLdc( finfo.getName() );
// *load_1 // each type
addTypeDependDataLoad( code, finfo.getDescriptor(), 1 );
// invokeinterface // invoke Callback.read*() // each type
addInvokeFieldHandlerMethod(
classfile, code, finfo.getDescriptor(),
true
);
// *return // each type
addTypeDependDataReturn( code, finfo.getDescriptor() );
readMethodInfo.setCodeAttribute( code.toCodeAttribute() );
readMethodInfo.setAccessFlags( AccessFlag.PUBLIC );
final CodeAttribute codeAttribute = readMethodInfo.getCodeAttribute();
if ( codeAttribute != null ) {
final StackMapTable smt = MapMaker.make( classPool, readMethodInfo );
codeAttribute.setAttribute( smt );
}
classfile.addMethod( readMethodInfo );
}
示例6: addWriteMethod
import javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
private void addWriteMethod(ClassFile classfile, FieldInfo finfo) throws CannotCompileException, BadBytecode {
final ConstPool constPool = classfile.getConstPool();
final int thisClassInfo = constPool.getThisClassInfo();
final String writeMethodDescriptor = "(" + finfo.getDescriptor() + ")V";
final MethodInfo writeMethodInfo = new MethodInfo(
constPool,
EACH_WRITE_METHOD_PREFIX+ finfo.getName(),
writeMethodDescriptor
);
/* local variables | target obj | each oldvalue | */
final Bytecode code = new Bytecode(constPool, 6, 3);
// aload_0
code.addAload( 0 );
// invokeinterface : enabled.getInterceptFieldCallback()
final int enabledClassIndex = constPool.addClassInfo( FIELD_HANDLED_TYPE_NAME );
code.addInvokeinterface(
enabledClassIndex,
GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
1
);
// ifnonnull (label1)
code.addOpcode( Opcode.IFNONNULL );
code.addIndex( 9 );
// aload_0
code.addAload( 0 );
// *load_1
addTypeDependDataLoad( code, finfo.getDescriptor(), 1 );
// putfield
code.addOpcode( Opcode.PUTFIELD );
final int baseFieldIndex = constPool.addFieldrefInfo( thisClassInfo, finfo.getName(), finfo.getDescriptor() );
code.addIndex( baseFieldIndex );
code.growStack( -Descriptor.dataSize( finfo.getDescriptor() ) );
// return ;
code.addOpcode( Opcode.RETURN );
// aload_0
code.addAload( 0 );
// dup
code.addOpcode( Opcode.DUP );
// invokeinterface // enabled.getInterceptFieldCallback()
code.addInvokeinterface(
enabledClassIndex,
GETFIELDHANDLER_METHOD_NAME,
GETFIELDHANDLER_METHOD_DESCRIPTOR,
1
);
// aload_0
code.addAload( 0 );
// ldc // field name
code.addLdc( finfo.getName() );
// aload_0
code.addAload( 0 );
// getfield // old value of the field
code.addOpcode( Opcode.GETFIELD );
code.addIndex( baseFieldIndex );
code.growStack( Descriptor.dataSize( finfo.getDescriptor() ) - 1 );
// *load_1
addTypeDependDataLoad( code, finfo.getDescriptor(), 1 );
// invokeinterface // callback.write*(..)
addInvokeFieldHandlerMethod( classfile, code, finfo.getDescriptor(), false );
// putfield // new value of the field
code.addOpcode( Opcode.PUTFIELD );
code.addIndex( baseFieldIndex );
code.growStack( -Descriptor.dataSize( finfo.getDescriptor() ) );
// return
code.addOpcode( Opcode.RETURN );
writeMethodInfo.setCodeAttribute( code.toCodeAttribute() );
writeMethodInfo.setAccessFlags( AccessFlag.PUBLIC );
final CodeAttribute codeAttribute = writeMethodInfo.getCodeAttribute();
if ( codeAttribute != null ) {
final StackMapTable smt = MapMaker.make( classPool, writeMethodInfo );
codeAttribute.setAttribute( smt );
}
classfile.addMethod( writeMethodInfo );
}
示例7: addReadMethod
import javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
private void addReadMethod(ClassFile classfile, FieldInfo finfo)
throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
String desc = "()" + finfo.getDescriptor();
MethodInfo minfo = new MethodInfo(cp, EACH_READ_METHOD_PREFIX
+ finfo.getName(), desc);
/* local variables | target obj | each oldvalue | */
Bytecode code = new Bytecode(cp, 5, 3);
// aload_0
code.addAload(0);
// getfield // get each field
code.addOpcode(Opcode.GETFIELD);
int base_field_index = cp.addFieldrefInfo(this_class_index, finfo
.getName(), finfo.getDescriptor());
code.addIndex(base_field_index);
// aload_0
code.addAload(0);
// invokeinterface // invoke Enabled.getInterceptFieldCallback()
int enabled_class_index = cp.addClassInfo(FIELD_HANDLED_TYPE_NAME);
code.addInvokeinterface(enabled_class_index,
GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
1);
// ifnonnull
code.addOpcode(Opcode.IFNONNULL);
code.addIndex(4);
// *return // each type
addTypeDependDataReturn(code, finfo.getDescriptor());
// *store_1 // each type
addTypeDependDataStore(code, finfo.getDescriptor(), 1);
// aload_0
code.addAload(0);
// invokeinterface // invoke Enabled.getInterceptFieldCallback()
code.addInvokeinterface(enabled_class_index,
GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
1);
// aload_0
code.addAload(0);
// ldc // name of the field
code.addLdc(finfo.getName());
// *load_1 // each type
addTypeDependDataLoad(code, finfo.getDescriptor(), 1);
// invokeinterface // invoke Callback.read*() // each type
addInvokeFieldHandlerMethod(classfile, code, finfo.getDescriptor(),
true);
// *return // each type
addTypeDependDataReturn(code, finfo.getDescriptor());
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
classfile.addMethod(minfo);
}
示例8: addWriteMethod
import javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
private void addWriteMethod(ClassFile classfile, FieldInfo finfo)
throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
String desc = "(" + finfo.getDescriptor() + ")V";
MethodInfo minfo = new MethodInfo(cp, EACH_WRITE_METHOD_PREFIX
+ finfo.getName(), desc);
/* local variables | target obj | each oldvalue | */
Bytecode code = new Bytecode(cp, 6, 3);
// aload_0
code.addAload(0);
// invokeinterface // enabled.getInterceptFieldCallback()
int enabled_class_index = cp.addClassInfo(FIELD_HANDLED_TYPE_NAME);
code.addInvokeinterface(enabled_class_index,
GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
1);
// ifnonnull (label1)
code.addOpcode(Opcode.IFNONNULL);
code.addIndex(9);
// aload_0
code.addAload(0);
// *load_1
addTypeDependDataLoad(code, finfo.getDescriptor(), 1);
// putfield
code.addOpcode(Opcode.PUTFIELD);
int base_field_index = cp.addFieldrefInfo(this_class_index, finfo
.getName(), finfo.getDescriptor());
code.addIndex(base_field_index);
code.growStack(-Descriptor.dataSize(finfo.getDescriptor()));
// return ;
code.addOpcode(Opcode.RETURN);
// aload_0
code.addAload(0);
// dup
code.addOpcode(Opcode.DUP);
// invokeinterface // enabled.getInterceptFieldCallback()
code.addInvokeinterface(enabled_class_index,
GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
1);
// aload_0
code.addAload(0);
// ldc // field name
code.addLdc(finfo.getName());
// aload_0
code.addAload(0);
// getfield // old value of the field
code.addOpcode(Opcode.GETFIELD);
code.addIndex(base_field_index);
code.growStack(Descriptor.dataSize(finfo.getDescriptor()) - 1);
// *load_1
addTypeDependDataLoad(code, finfo.getDescriptor(), 1);
// invokeinterface // callback.write*(..)
addInvokeFieldHandlerMethod(classfile, code, finfo.getDescriptor(),
false);
// putfield // new value of the field
code.addOpcode(Opcode.PUTFIELD);
code.addIndex(base_field_index);
code.growStack(-Descriptor.dataSize(finfo.getDescriptor()));
// return
code.addOpcode(Opcode.RETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
classfile.addMethod(minfo);
}
示例9: JField
import javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
protected JField(FieldInfo fieldInfo, JClass jClass, ClasspathResolver resolver) {
super(fieldInfo.getName(), resolver);
this.fieldInfo = fieldInfo;
this.jClass = jClass;
}