本文整理了Java中javassist.bytecode.Bytecode.addInvokevirtual()
方法的一些代码示例,展示了Bytecode.addInvokevirtual()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytecode.addInvokevirtual()
方法的具体详情如下:
包路径:javassist.bytecode.Bytecode
类名称:Bytecode
方法名:addInvokevirtual
[英]Appends INVOKEVIRTUAL.
The specified method must not be an inherited method. It must be directly declared in the class specified by clazz
.
[中]
代码示例来源:origin: redisson/redisson
/**
* Appends INVOKEVIRTUAL.
*
* <p>The specified method must not be an inherited method.
* It must be directly declared in the class specified
* in <code>clazz</code>.
*
* @param clazz the target class.
* @param name the method name
* @param returnType the return type.
* @param paramTypes the parameter types.
*/
public void addInvokevirtual(CtClass clazz, String name,
CtClass returnType, CtClass[] paramTypes) {
String desc = Descriptor.ofMethod(returnType, paramTypes);
addInvokevirtual(clazz, name, desc);
}
代码示例来源:origin: redisson/redisson
/**
* Appends INVOKEVIRTUAL.
*
* <p>The specified method must not be an inherited method.
* It must be directly declared in the class specified
* in <code>clazz</code>.
*
* @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 addInvokevirtual(CtClass clazz, String name, String desc) {
addInvokevirtual(constPool.addClassInfo(clazz), name, desc);
}
代码示例来源:origin: redisson/redisson
/**
* Appends INVOKEVIRTUAL.
*
* <p>The specified method must not be an inherited method.
* It must be directly declared in the class specified
* in <code>classname</code>.
*
* @param classname the fully-qualified class name.
* @param name the method name
* @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokevirtual(String classname, String name, String desc) {
addInvokevirtual(constPool.addClassInfo(classname), name, desc);
}
代码示例来源:origin: org.javassist/javassist
/**
* Appends INVOKEVIRTUAL.
*
* <p>The specified method must not be an inherited method.
* It must be directly declared in the class specified
* in <code>clazz</code>.
*
* @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 addInvokevirtual(CtClass clazz, String name, String desc) {
addInvokevirtual(constPool.addClassInfo(clazz), name, desc);
}
代码示例来源:origin: org.javassist/javassist
/**
* Appends INVOKEVIRTUAL.
*
* <p>The specified method must not be an inherited method.
* It must be directly declared in the class specified
* in <code>classname</code>.
*
* @param classname the fully-qualified class name.
* @param name the method name
* @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokevirtual(String classname, String name, String desc) {
addInvokevirtual(constPool.addClassInfo(classname), name, desc);
}
代码示例来源:origin: org.javassist/javassist
/**
* Appends INVOKEVIRTUAL.
*
* <p>The specified method must not be an inherited method.
* It must be directly declared in the class specified
* in <code>clazz</code>.
*
* @param clazz the target class.
* @param name the method name
* @param returnType the return type.
* @param paramTypes the parameter types.
*/
public void addInvokevirtual(CtClass clazz, String name,
CtClass returnType, CtClass[] paramTypes) {
String desc = Descriptor.ofMethod(returnType, paramTypes);
addInvokevirtual(clazz, name, desc);
}
代码示例来源:origin: redisson/redisson
/**
* Appends instructions for executing
* <code>java.lang.System.println(<i>message</i>)</code>.
*
* @param message printed message.
*/
public void addPrintln(String message) {
addGetstatic("java.lang.System", "err", "Ljava/io/PrintStream;");
addLdc(message);
addInvokevirtual("java.io.PrintStream",
"println", "(Ljava/lang/String;)V");
}
}
代码示例来源:origin: hibernate/hibernate-orm
private void addUnwrapper(Bytecode code, Class type) {
final int index = FactoryHelper.typeIndex( type );
final String wrapperType = FactoryHelper.wrapperTypes[index];
// checkcast
code.addCheckcast( wrapperType );
// invokevirtual
code.addInvokevirtual( wrapperType, FactoryHelper.unwarpMethods[index], FactoryHelper.unwrapDesc[index] );
}
代码示例来源:origin: redisson/redisson
private static void addUnwrapper(Bytecode code, Class type) {
if (type.isPrimitive()) {
if (type == Void.TYPE)
code.addOpcode(Opcode.POP);
else {
int index = FactoryHelper.typeIndex(type);
String wrapper = FactoryHelper.wrapperTypes[index];
code.addCheckcast(wrapper);
code.addInvokevirtual(wrapper,
FactoryHelper.unwarpMethods[index],
FactoryHelper.unwrapDesc[index]);
}
}
else
code.addCheckcast(type.getName());
}
代码示例来源:origin: org.javassist/javassist
/**
* Appends instructions for executing
* <code>java.lang.System.println(<i>message</i>)</code>.
*
* @param message printed message.
*/
public void addPrintln(String message) {
addGetstatic("java.lang.System", "err", "Ljava/io/PrintStream;");
addLdc(message);
addInvokevirtual("java.io.PrintStream",
"println", "(Ljava/lang/String;)V");
}
}
代码示例来源:origin: redisson/redisson
private void atStringPlusEq(Expr expr, int type, int dim, String cname,
ASTree right)
throws CompileError
{
if (!jvmJavaLangString.equals(cname))
badAssign(expr);
convToString(type, dim); // the value might be null.
right.accept(this);
convToString(exprType, arrayDim);
bytecode.addInvokevirtual(javaLangString, "concat",
"(Ljava/lang/String;)Ljava/lang/String;");
exprType = CLASS;
arrayDim = 0;
className = jvmJavaLangString;
}
代码示例来源:origin: org.javassist/javassist
private static void addUnwrapper(Bytecode code, Class<?> type) {
if (type.isPrimitive()) {
if (type == Void.TYPE)
code.addOpcode(Opcode.POP);
else {
int index = FactoryHelper.typeIndex(type);
String wrapper = FactoryHelper.wrapperTypes[index];
code.addCheckcast(wrapper);
code.addInvokevirtual(wrapper,
FactoryHelper.unwarpMethods[index],
FactoryHelper.unwrapDesc[index]);
}
}
else
code.addCheckcast(type.getName());
}
代码示例来源:origin: org.javassist/javassist
private void atStringPlusEq(Expr expr, int type, int dim, String cname,
ASTree right)
throws CompileError
{
if (!jvmJavaLangString.equals(cname))
badAssign(expr);
convToString(type, dim); // the value might be null.
right.accept(this);
convToString(exprType, arrayDim);
bytecode.addInvokevirtual(javaLangString, "concat",
"(Ljava/lang/String;)Ljava/lang/String;");
exprType = CLASS;
arrayDim = 0;
className = jvmJavaLangString;
}
代码示例来源:origin: redisson/redisson
protected void atCflow(ASTList cname) throws CompileError {
StringBuffer sbuf = new StringBuffer();
if (cname == null || cname.tail() != null)
throw new CompileError("bad " + cflowName);
makeCflowName(sbuf, cname.head());
String name = sbuf.toString();
Object[] names = resolver.getClassPool().lookupCflow(name);
if (names == null)
throw new CompileError("no such " + cflowName + ": " + name);
bytecode.addGetstatic((String)names[0], (String)names[1],
"Ljavassist/runtime/Cflow;");
bytecode.addInvokevirtual("javassist.runtime.Cflow",
"value", "()I");
exprType = INT;
arrayDim = 0;
className = null;
}
代码示例来源:origin: org.javassist/javassist
protected void atCflow(ASTList cname) throws CompileError {
StringBuffer sbuf = new StringBuffer();
if (cname == null || cname.tail() != null)
throw new CompileError("bad " + cflowName);
makeCflowName(sbuf, cname.head());
String name = sbuf.toString();
Object[] names = resolver.getClassPool().lookupCflow(name);
if (names == null)
throw new CompileError("no such " + cflowName + ": " + name);
bytecode.addGetstatic((String)names[0], (String)names[1],
"Ljavassist/runtime/Cflow;");
bytecode.addInvokevirtual("javassist.runtime.Cflow",
"value", "()I");
exprType = INT;
arrayDim = 0;
className = null;
}
代码示例来源:origin: redisson/redisson
private void atStringConcatExpr(Expr expr, int type1, int dim1,
String cname1) throws CompileError
{
int type2 = exprType;
int dim2 = arrayDim;
boolean type2Is2 = is2word(type2, dim2);
boolean type2IsString
= (type2 == CLASS && jvmJavaLangString.equals(className));
if (type2Is2)
convToString(type2, dim2);
if (is2word(type1, dim1)) {
bytecode.addOpcode(DUP_X2);
bytecode.addOpcode(POP);
}
else
bytecode.addOpcode(SWAP);
// even if type1 is String, the left operand might be null.
convToString(type1, dim1);
bytecode.addOpcode(SWAP);
if (!type2Is2 && !type2IsString)
convToString(type2, dim2);
bytecode.addInvokevirtual(javaLangString, "concat",
"(Ljava/lang/String;)Ljava/lang/String;");
exprType = CLASS;
arrayDim = 0;
className = jvmJavaLangString;
}
代码示例来源:origin: redisson/redisson
private static void compileReturn(Bytecode code, CtClass type) {
if (type.isPrimitive()) {
CtPrimitiveType pt = (CtPrimitiveType)type;
if (pt != CtClass.voidType) {
String wrapper = pt.getWrapperName();
code.addCheckcast(wrapper);
code.addInvokevirtual(wrapper, pt.getGetMethodName(),
pt.getGetMethodDescriptor());
}
code.addOpcode(pt.getReturnOp());
}
else {
code.addCheckcast(type);
code.addOpcode(Bytecode.ARETURN);
}
}
}
代码示例来源:origin: redisson/redisson
protected void compileUnwrapValue(CtClass type, Bytecode code)
throws CompileError
{
if (type == CtClass.voidType) {
addNullIfVoid();
return;
}
if (exprType == VOID)
throw new CompileError("invalid type for " + returnCastName);
if (type instanceof CtPrimitiveType) {
CtPrimitiveType pt = (CtPrimitiveType)type;
// pt is not voidType.
String wrapper = pt.getWrapperName();
code.addCheckcast(wrapper);
code.addInvokevirtual(wrapper, pt.getGetMethodName(),
pt.getGetMethodDescriptor());
setType(type);
}
else {
code.addCheckcast(type);
setType(type);
}
}
代码示例来源:origin: org.javassist/javassist
private static void compileReturn(Bytecode code, CtClass type) {
if (type.isPrimitive()) {
CtPrimitiveType pt = (CtPrimitiveType)type;
if (pt != CtClass.voidType) {
String wrapper = pt.getWrapperName();
code.addCheckcast(wrapper);
code.addInvokevirtual(wrapper, pt.getGetMethodName(),
pt.getGetMethodDescriptor());
}
code.addOpcode(pt.getReturnOp());
}
else {
code.addCheckcast(type);
code.addOpcode(Bytecode.ARETURN);
}
}
}
代码示例来源:origin: org.javassist/javassist
protected void compileUnwrapValue(CtClass type, Bytecode code)
throws CompileError
{
if (type == CtClass.voidType) {
addNullIfVoid();
return;
}
if (exprType == VOID)
throw new CompileError("invalid type for " + returnCastName);
if (type instanceof CtPrimitiveType) {
CtPrimitiveType pt = (CtPrimitiveType)type;
// pt is not voidType.
String wrapper = pt.getWrapperName();
code.addCheckcast(wrapper);
code.addInvokevirtual(wrapper, pt.getGetMethodName(),
pt.getGetMethodDescriptor());
setType(type);
}
else {
code.addCheckcast(type);
setType(type);
}
}
内容来源于网络,如有侵权,请联系作者删除!