本文整理汇总了Java中scouter.javassist.bytecode.Bytecode.addPutstatic方法的典型用法代码示例。如果您正苦于以下问题:Java Bytecode.addPutstatic方法的具体用法?Java Bytecode.addPutstatic怎么用?Java Bytecode.addPutstatic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scouter.javassist.bytecode.Bytecode
的用法示例。
在下文中一共展示了Bytecode.addPutstatic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compileIfStatic
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
* Produces codes for a static field.
*/
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
String desc;
code.addNew(objectType);
code.add(Bytecode.DUP);
int stacksize = 2;
if (stringParams == null)
desc = "()V";
else {
desc = "([Ljava/lang/String;)V";
stacksize += compileStringParameter(code);
}
code.addInvokespecial(objectType, "<init>", desc);
code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type));
return stacksize;
}
示例2: setter
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
* Creates a public setter method. The setter method assigns the
* value of the first parameter to the specified field
* in the class to which this method is added.
* The created method is not static even if the field is
* static. You may not change it to be static
* by <code>setModifiers()</code> in <code>CtBehavior</code>.
*
* @param methodName the name of the setter
* @param field the field accessed.
*/
public static CtMethod setter(String methodName, CtField field)
throws CannotCompileException
{
FieldInfo finfo = field.getFieldInfo2();
String fieldType = finfo.getDescriptor();
String desc = "(" + fieldType + ")V";
ConstPool cp = finfo.getConstPool();
MethodInfo minfo = new MethodInfo(cp, methodName, desc);
minfo.setAccessFlags(AccessFlag.PUBLIC);
Bytecode code = new Bytecode(cp, 3, 3);
try {
String fieldName = finfo.getName();
if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0) {
code.addAload(0);
code.addLoad(1, field.getType());
code.addPutfield(Bytecode.THIS, fieldName, fieldType);
}
else {
code.addLoad(1, field.getType());
code.addPutstatic(Bytecode.THIS, fieldName, fieldType);
}
code.addReturn(null);
}
catch (NotFoundException e) {
throw new CannotCompileException(e);
}
minfo.setCodeAttribute(code.toCodeAttribute());
CtClass cc = field.getDeclaringClass();
// a stack map is not needed.
return new CtMethod(minfo, cc);
}
示例3: addClassInitializer
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static void addClassInitializer(ClassFile cf, ConstPool cp,
String classname, int size, ArrayList forwarders)
throws CannotCompileException
{
FieldInfo finfo = new FieldInfo(cp, HOLDER, HOLDER_TYPE);
finfo.setAccessFlags(AccessFlag.PRIVATE | AccessFlag.STATIC);
cf.addField(finfo);
MethodInfo minfo = new MethodInfo(cp, "<clinit>", "()V");
minfo.setAccessFlags(AccessFlag.STATIC);
setThrows(minfo, cp, new Class[] { ClassNotFoundException.class });
Bytecode code = new Bytecode(cp, 0, 2);
code.addIconst(size * 2);
code.addAnewarray("java.lang.reflect.Method");
final int varArray = 0;
code.addAstore(varArray);
// forName() must be called here. Otherwise, the class might be
// invisible.
code.addLdc(classname);
code.addInvokestatic("java.lang.Class",
"forName", "(Ljava/lang/String;)Ljava/lang/Class;");
final int varClass = 1;
code.addAstore(varClass);
Iterator it = forwarders.iterator();
while (it.hasNext()) {
Find2MethodsArgs args = (Find2MethodsArgs)it.next();
callFind2Methods(code, args.methodName, args.delegatorName,
args.origIndex, args.descriptor, varClass, varArray);
}
code.addAload(varArray);
code.addPutstatic(classname, HOLDER, HOLDER_TYPE);
code.addLconst(SERIAL_VERSION_UID_VALUE);
code.addPutstatic(classname, SERIAL_VERSION_UID_FIELD, SERIAL_VERSION_UID_TYPE);
code.addOpcode(Bytecode.RETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(minfo);
}