本文整理了Java中javassist.bytecode.Bytecode.<init>()
方法的一些代码示例,展示了Bytecode.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytecode.<init>()
方法的具体详情如下:
包路径:javassist.bytecode.Bytecode
类名称:Bytecode
方法名:<init>
[英]Constructs a Bytecode
object with an empty bytecode sequence. The initial values of max_stack
and max_locals
are zero.
[中]用空字节码序列构造Bytecode
对象。max_stack
和max_locals
的初始值为零。
代码示例来源:origin: redisson/redisson
/**
* Constructs a compiler.
*
* @param thisClass the class that a compiled method/field
* belongs to.
*/
public Javac(CtClass thisClass) {
this(new Bytecode(thisClass.getClassFile2().getConstPool(), 0, 0),
thisClass);
}
代码示例来源:origin: redisson/redisson
protected void makeCode(CtClass[] paramTypes, ConstPool cp) {
Bytecode save = new Bytecode(cp, 0, 0);
Bytecode load = new Bytecode(cp, 0, 0);
int var = maxLocals;
int len = (paramTypes == null) ? 0 : paramTypes.length;
load.addAload(var);
makeCode2(save, load, 0, len, paramTypes, var + 1);
save.addAstore(var);
saveCode = save.get();
loadCode = load.get();
}
代码示例来源:origin: org.javassist/javassist
/**
* Constructs a compiler.
*
* @param thisClass the class that a compiled method/field
* belongs to.
*/
public Javac(CtClass thisClass) {
this(new Bytecode(thisClass.getClassFile2().getConstPool(), 0, 0),
thisClass);
}
代码示例来源:origin: org.javassist/javassist
protected void makeCode(CtClass[] paramTypes, ConstPool cp) {
Bytecode save = new Bytecode(cp, 0, 0);
Bytecode load = new Bytecode(cp, 0, 0);
int var = maxLocals;
int len = (paramTypes == null) ? 0 : paramTypes.length;
load.addAload(var);
makeCode2(save, load, 0, len, paramTypes, var + 1);
save.addAstore(var);
saveCode = save.get();
loadCode = load.get();
}
代码示例来源:origin: redisson/redisson
private MethodInfo makeDelegator(Method meth, String desc,
ConstPool cp, Class declClass, String delegatorName) {
MethodInfo delegator = new MethodInfo(cp, delegatorName, desc);
delegator.setAccessFlags(Modifier.FINAL | Modifier.PUBLIC
| (meth.getModifiers() & ~(Modifier.PRIVATE
| Modifier.PROTECTED
| Modifier.ABSTRACT
| Modifier.NATIVE
| Modifier.SYNCHRONIZED)));
setThrows(delegator, cp, meth);
Bytecode code = new Bytecode(cp, 0, 0);
code.addAload(0);
int s = addLoadParameters(code, meth.getParameterTypes(), 1);
Class targetClass = invokespecialTarget(declClass);
code.addInvokespecial(targetClass.isInterface(), cp.addClassInfo(targetClass.getName()),
meth.getName(), desc);
addReturn(code, meth.getReturnType());
code.setMaxLocals(++s);
delegator.setCodeAttribute(code.toCodeAttribute());
return delegator;
}
代码示例来源:origin: redisson/redisson
public CtConstructor makeClassInitializer()
throws CannotCompileException
{
CtConstructor clinit = getClassInitializer();
if (clinit != null)
return clinit;
checkModify();
ClassFile cf = getClassFile2();
Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
modifyClassConstructor(cf, code, 0, 0);
return getClassInitializer();
}
代码示例来源:origin: redisson/redisson
static Bytecode makeBody(CtClass clazz, ClassFile classfile,
CtMethod wrappedBody,
CtClass[] parameters,
CtClass returnType,
ConstParameter cparam)
throws CannotCompileException
{
boolean isStatic = Modifier.isStatic(wrappedBody.getModifiers());
Bytecode code = new Bytecode(classfile.getConstPool(), 0, 0);
int stacksize = makeBody0(clazz, classfile, wrappedBody, isStatic,
parameters, returnType, cparam, code);
code.setMaxStack(stacksize);
code.setMaxLocals(isStatic, parameters, 0);
return code;
}
代码示例来源:origin: redisson/redisson
private static void addGetter(String classname, ClassFile cf, ConstPool cp)
throws CannotCompileException
{
MethodInfo minfo = new MethodInfo(cp, HANDLER_GETTER,
HANDLER_GETTER_TYPE);
minfo.setAccessFlags(AccessFlag.PUBLIC);
Bytecode code = new Bytecode(cp, 1, 1);
code.addAload(0);
code.addGetfield(classname, HANDLER, HANDLER_TYPE);
code.addOpcode(Bytecode.ARETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(minfo);
}
代码示例来源:origin: org.javassist/javassist
@Override
public CtConstructor makeClassInitializer()
throws CannotCompileException
{
CtConstructor clinit = getClassInitializer();
if (clinit != null)
return clinit;
checkModify();
ClassFile cf = getClassFile2();
Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
modifyClassConstructor(cf, code, 0, 0);
return getClassInitializer();
}
代码示例来源:origin: redisson/redisson
private void modifyConstructors(ClassFile cf)
throws CannotCompileException, NotFoundException
{
if (fieldInitializers == null)
return;
ConstPool cp = cf.getConstPool();
List list = cf.getMethods();
int n = list.size();
for (int i = 0; i < n; ++i) {
MethodInfo minfo = (MethodInfo)list.get(i);
if (minfo.isConstructor()) {
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr != null)
try {
Bytecode init = new Bytecode(cp, 0,
codeAttr.getMaxLocals());
CtClass[] params
= Descriptor.getParameterTypes(
minfo.getDescriptor(),
classPool);
int stacksize = makeFieldInitializer(init, params);
insertAuxInitializer(codeAttr, init, stacksize);
minfo.rebuildStackMapIf6(classPool, cf);
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
}
}
代码示例来源:origin: org.javassist/javassist
static Bytecode makeBody(CtClass clazz, ClassFile classfile,
CtMethod wrappedBody,
CtClass[] parameters,
CtClass returnType,
ConstParameter cparam)
throws CannotCompileException
{
boolean isStatic = Modifier.isStatic(wrappedBody.getModifiers());
Bytecode code = new Bytecode(classfile.getConstPool(), 0, 0);
int stacksize = makeBody0(clazz, classfile, wrappedBody, isStatic,
parameters, returnType, cparam, code);
code.setMaxStack(stacksize);
code.setMaxLocals(isStatic, parameters, 0);
return code;
}
代码示例来源:origin: redisson/redisson
private static void addSetter(String classname, ClassFile cf, ConstPool cp)
throws CannotCompileException
{
MethodInfo minfo = new MethodInfo(cp, HANDLER_SETTER,
HANDLER_SETTER_TYPE);
minfo.setAccessFlags(AccessFlag.PUBLIC);
Bytecode code = new Bytecode(cp, 2, 2);
code.addAload(0);
code.addAload(1);
code.addPutfield(classname, HANDLER, HANDLER_TYPE);
code.addOpcode(Bytecode.RETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(minfo);
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Declares a constructor that takes no parameter.
*
* @param classfile The class descriptor
*
* @throws CannotCompileException Indicates trouble with the underlying Javassist calls
*/
private void addDefaultConstructor(ClassFile classfile) throws CannotCompileException {
final ConstPool constPool = classfile.getConstPool();
final String constructorSignature = "()V";
final MethodInfo constructorMethodInfo = new MethodInfo( constPool, MethodInfo.nameInit, constructorSignature );
final Bytecode code = new Bytecode( constPool, 0, 1 );
// aload_0
code.addAload( 0 );
// invokespecial
code.addInvokespecial( BulkAccessor.class.getName(), MethodInfo.nameInit, constructorSignature );
// return
code.addOpcode( Opcode.RETURN );
constructorMethodInfo.setCodeAttribute( code.toCodeAttribute() );
constructorMethodInfo.setAccessFlags( AccessFlag.PUBLIC );
classfile.addMethod( constructorMethodInfo );
}
代码示例来源:origin: redisson/redisson
private void modifyClassConstructor(ClassFile cf)
throws CannotCompileException, NotFoundException
{
if (fieldInitializers == null)
return;
Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
Javac jv = new Javac(code, this);
int stacksize = 0;
boolean doInit = false;
for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) {
CtField f = fi.field;
if (Modifier.isStatic(f.getModifiers())) {
doInit = true;
int s = fi.init.compileIfStatic(f.getType(), f.getName(),
code, jv);
if (stacksize < s)
stacksize = s;
}
}
if (doInit) // need an initializer for static fileds.
modifyClassConstructor(cf, code, stacksize, 0);
}
代码示例来源:origin: redisson/redisson
private static MethodInfo makeWriteReplace(ConstPool cp) {
MethodInfo minfo = new MethodInfo(cp, "writeReplace", "()Ljava/lang/Object;");
String[] list = new String[1];
list[0] = "java.io.ObjectStreamException";
ExceptionsAttribute ea = new ExceptionsAttribute(cp);
ea.setExceptions(list);
minfo.setExceptionsAttribute(ea);
Bytecode code = new Bytecode(cp, 0, 1);
code.addAload(0);
code.addInvokestatic("javassist.util.proxy.RuntimeSupport",
"makeSerializedProxy",
"(Ljava/lang/Object;)Ljavassist/util/proxy/SerializedProxy;");
code.addOpcode(Opcode.ARETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
return minfo;
}
}
代码示例来源:origin: org.javassist/javassist
private static void addGetter(String classname, ClassFile cf, ConstPool cp)
throws CannotCompileException
{
MethodInfo minfo = new MethodInfo(cp, HANDLER_GETTER,
HANDLER_GETTER_TYPE);
minfo.setAccessFlags(AccessFlag.PUBLIC);
Bytecode code = new Bytecode(cp, 1, 1);
code.addAload(0);
code.addGetfield(classname, HANDLER, HANDLER_TYPE);
code.addOpcode(Bytecode.ARETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(minfo);
}
代码示例来源:origin: org.javassist/javassist
private static void addSetter(String classname, ClassFile cf, ConstPool cp)
throws CannotCompileException
{
MethodInfo minfo = new MethodInfo(cp, HANDLER_SETTER,
HANDLER_SETTER_TYPE);
minfo.setAccessFlags(AccessFlag.PUBLIC);
Bytecode code = new Bytecode(cp, 2, 2);
code.addAload(0);
code.addAload(1);
code.addPutfield(classname, HANDLER, HANDLER_TYPE);
code.addOpcode(Bytecode.RETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(minfo);
}
代码示例来源:origin: org.javassist/javassist
private static MethodInfo makeWriteReplace(ConstPool cp) {
MethodInfo minfo = new MethodInfo(cp, "writeReplace", "()Ljava/lang/Object;");
String[] list = new String[1];
list[0] = "java.io.ObjectStreamException";
ExceptionsAttribute ea = new ExceptionsAttribute(cp);
ea.setExceptions(list);
minfo.setExceptionsAttribute(ea);
Bytecode code = new Bytecode(cp, 0, 1);
code.addAload(0);
code.addInvokestatic("javassist.util.proxy.RuntimeSupport",
"makeSerializedProxy",
"(Ljava/lang/Object;)Ljavassist/util/proxy/SerializedProxy;");
code.addOpcode(Opcode.ARETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
return minfo;
}
}
代码示例来源:origin: redisson/redisson
/**
* Creates a default (public) constructor.
*
* <p>The created constructor takes no parameter. It calls
* <code>super()</code>.
*/
public static CtConstructor defaultConstructor(CtClass declaring)
throws CannotCompileException
{
CtConstructor cons = new CtConstructor((CtClass[])null, declaring);
ConstPool cp = declaring.getClassFile2().getConstPool();
Bytecode code = new Bytecode(cp, 1, 1);
code.addAload(0);
try {
code.addInvokespecial(declaring.getSuperclass(),
"<init>", "()V");
}
catch (NotFoundException e) {
throw new CannotCompileException(e);
}
code.add(Bytecode.RETURN);
// no need to construct a stack map table.
cons.getMethodInfo2().setCodeAttribute(code.toCodeAttribute());
return cons;
}
代码示例来源:origin: redisson/redisson
(ExceptionsAttribute)eattr.copy(cp, null));
Bytecode code = new Bytecode(cp, 0, 0);
boolean isStatic = Modifier.isStatic(delegate.getModifiers());
CtClass deleClass = delegate.getDeclaringClass();
内容来源于网络,如有侵权,请联系作者删除!