本文整理了Java中javassist.bytecode.Bytecode.addInvokestatic()
方法的一些代码示例,展示了Bytecode.addInvokestatic()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytecode.addInvokestatic()
方法的具体详情如下:
包路径:javassist.bytecode.Bytecode
类名称:Bytecode
方法名:addInvokestatic
[英]Appends INVOKESTATIC.
[中]附加调用属性。
代码示例来源:origin: redisson/redisson
private void callGetType(String method) {
bytecode.addInvokestatic("javassist/runtime/Desc", method,
"(Ljava/lang/String;)Ljava/lang/Class;");
exprType = CLASS;
arrayDim = 0;
className = "java/lang/Class";
}
代码示例来源:origin: redisson/redisson
/**
* Appends INVOKESTATIC.
*
* @param clazz the index of <code>CONSTANT_Class_info</code>
* structure. It must not be an interface type.
* @param name the method name
* @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(int clazz, String name, String desc) {
addInvokestatic(clazz, name, desc, false);
}
代码示例来源:origin: org.javassist/javassist
private void callGetType(String method) {
bytecode.addInvokestatic("javassist/runtime/Desc", method,
"(Ljava/lang/String;)Ljava/lang/Class;");
exprType = CLASS;
arrayDim = 0;
className = "java/lang/Class";
}
代码示例来源:origin: org.javassist/javassist
/**
* Appends INVOKESTATIC.
*
* @param clazz the index of <code>CONSTANT_Class_info</code>
* structure. It must not be an interface type.
* @param name the method name
* @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(int clazz, String name, String desc) {
addInvokestatic(clazz, name, desc, false);
}
代码示例来源:origin: redisson/redisson
private void convToString(int type, int dim) throws CompileError {
final String method = "valueOf";
if (isRefType(type) || dim > 0)
bytecode.addInvokestatic(javaLangString, method,
"(Ljava/lang/Object;)Ljava/lang/String;");
else if (type == DOUBLE)
bytecode.addInvokestatic(javaLangString, method,
"(D)Ljava/lang/String;");
else if (type == FLOAT)
bytecode.addInvokestatic(javaLangString, method,
"(F)Ljava/lang/String;");
else if (type == LONG)
bytecode.addInvokestatic(javaLangString, method,
"(J)Ljava/lang/String;");
else if (type == BOOLEAN)
bytecode.addInvokestatic(javaLangString, method,
"(Z)Ljava/lang/String;");
else if (type == CHAR)
bytecode.addInvokestatic(javaLangString, method,
"(C)Ljava/lang/String;");
else if (type == VOID)
throw new CompileError("void type expression");
else /* INT, BYTE, SHORT */
bytecode.addInvokestatic(javaLangString, method,
"(I)Ljava/lang/String;");
}
代码示例来源:origin: redisson/redisson
/**
* Appends INVOKESTATIC.
*
* @param clazz the target class.
* @param name the method name
* @param returnType the return type.
* @param paramTypes the parameter types.
*/
public void addInvokestatic(CtClass clazz, String name,
CtClass returnType, CtClass[] paramTypes) {
String desc = Descriptor.ofMethod(returnType, paramTypes);
addInvokestatic(clazz, name, desc);
}
代码示例来源:origin: redisson/redisson
/**
* Appends INVOKESTATIC.
*
* @param classname the fully-qualified class name.
* It must not be an interface-type name.
* @param name the method name
* @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(String classname, String name, String desc) {
addInvokestatic(constPool.addClassInfo(classname), name, desc);
}
代码示例来源:origin: org.javassist/javassist
/**
* Appends INVOKESTATIC.
*
* @param clazz the target class.
* @param name the method name
* @param returnType the return type.
* @param paramTypes the parameter types.
*/
public void addInvokestatic(CtClass clazz, String name,
CtClass returnType, CtClass[] paramTypes) {
String desc = Descriptor.ofMethod(returnType, paramTypes);
addInvokestatic(clazz, name, desc);
}
代码示例来源:origin: org.javassist/javassist
/**
* Appends INVOKESTATIC.
*
* @param classname the fully-qualified class name.
* It must not be an interface-type name.
* @param name the method name
* @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(String classname, String name, String desc) {
addInvokestatic(constPool.addClassInfo(classname), name, desc);
}
代码示例来源:origin: redisson/redisson
/**
* Appends INVOKESTATIC.
*
* @param clazz the target class.
* @param name the method name
* @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(CtClass clazz, String name, String desc) {
boolean isInterface;
if (clazz == THIS)
isInterface = false;
else
isInterface = clazz.isInterface();
addInvokestatic(constPool.addClassInfo(clazz), name, desc, isInterface);
}
代码示例来源:origin: redisson/redisson
/**
* Produces codes for a static field.
*/
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
String desc;
int stacksize = 1;
if (stringParams == null)
desc = "()";
else {
desc = "([Ljava/lang/String;)";
stacksize += compileStringParameter(code);
}
String typeDesc = Descriptor.of(type);
code.addInvokestatic(objectType, methodName, desc + typeDesc);
code.addPutstatic(Bytecode.THIS, name, typeDesc);
return stacksize;
}
}
代码示例来源:origin: redisson/redisson
/**
* @param thisMethod might be null.
*/
private static void callFind2Methods(Bytecode code, String superMethod, String thisMethod,
int index, String desc, int classVar, int arrayVar) {
String findClass = RuntimeSupport.class.getName();
String findDesc
= "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/reflect/Method;)V";
code.addAload(classVar);
code.addLdc(superMethod);
if (thisMethod == null)
code.addOpcode(Opcode.ACONST_NULL);
else
code.addLdc(thisMethod);
code.addIconst(index);
code.addLdc(desc);
code.addAload(arrayVar);
code.addInvokestatic(findClass, "find2Methods", findDesc);
}
代码示例来源:origin: redisson/redisson
bytecode.addInvokestatic("javassist/runtime/Desc", "getParams",
"(Ljava/lang/String;)[Ljava/lang/Class;");
exprType = CLASS;
代码示例来源:origin: redisson/redisson
protected void atClassObject2(String cname) throws CompileError {
int start = bytecode.currentPc();
bytecode.addLdc(cname);
bytecode.addInvokestatic("java.lang.Class", "forName",
"(Ljava/lang/String;)Ljava/lang/Class;");
int end = bytecode.currentPc();
bytecode.addInvokestatic("javassist.runtime.DotClass", "fail",
"(Ljava/lang/ClassNotFoundException;)"
+ "Ljava/lang/NoClassDefFoundError;");
代码示例来源:origin: redisson/redisson
/**
* Produces codes in which a new object is created and assigned to
* the field as the initial value.
*/
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
{
int stacksize;
code.addAload(0);
code.addAload(0);
if (stringParams == null)
stacksize = 2;
else
stacksize = compileStringParameter(code) + 2;
if (withConstructorParams)
stacksize += CtNewWrappedMethod.compileParameterList(code,
parameters, 1);
String typeDesc = Descriptor.of(type);
String mDesc = getDescriptor() + typeDesc;
code.addInvokestatic(objectType, methodName, mDesc);
code.addPutfield(Bytecode.THIS, name, typeDesc);
return stacksize;
}
代码示例来源: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 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
private void atFieldAssignCore(CtField f, boolean is_static, int fi,
boolean is2byte) throws CompileError {
if (fi != 0) {
if (is_static) {
bytecode.add(PUTSTATIC);
bytecode.growStack(is2byte ? -2 : -1);
}
else {
bytecode.add(PUTFIELD);
bytecode.growStack(is2byte ? -3 : -2);
}
bytecode.addIndex(fi);
}
else {
CtClass declClass = f.getDeclaringClass();
AccessorMaker maker = declClass.getAccessorMaker();
// make should be non null.
FieldInfo finfo = f.getFieldInfo2();
MethodInfo minfo = maker.getFieldSetter(finfo, is_static);
bytecode.addInvokestatic(declClass, minfo.getName(),
minfo.getDescriptor());
}
}
代码示例来源:origin: redisson/redisson
/**
* Generates bytecode for reading a field value.
* It returns a fieldref_info index or zero if the field is a private
* one declared in an enclosing class.
*/
private int atFieldRead(CtField f, boolean isStatic) throws CompileError {
FieldInfo finfo = f.getFieldInfo2();
boolean is2byte = setFieldType(finfo);
AccessorMaker maker = isAccessibleField(f, finfo);
if (maker != null) {
MethodInfo minfo = maker.getFieldGetter(finfo, isStatic);
bytecode.addInvokestatic(f.getDeclaringClass(), minfo.getName(),
minfo.getDescriptor());
return 0;
}
else {
int fi = addFieldrefInfo(f, finfo);
if (isStatic) {
bytecode.add(GETSTATIC);
bytecode.growStack(is2byte ? 2 : 1);
}
else {
bytecode.add(GETFIELD);
bytecode.growStack(is2byte ? 1 : 0);
}
bytecode.addIndex(fi);
return fi;
}
}
代码示例来源:origin: redisson/redisson
if (isStatic) {
s = code.addLoadParameters(params, 0);
code.addInvokestatic(deleClass, methodName, desc);
内容来源于网络,如有侵权,请联系作者删除!