當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodInfo類代碼示例

本文整理匯總了Java中scouter.javassist.bytecode.MethodInfo的典型用法代碼示例。如果您正苦於以下問題:Java MethodInfo類的具體用法?Java MethodInfo怎麽用?Java MethodInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MethodInfo類屬於scouter.javassist.bytecode包,在下文中一共展示了MethodInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wrapped

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
public static CtMethod wrapped(CtClass returnType, String mname,
                               CtClass[] parameterTypes,
                               CtClass[] exceptionTypes,
                               CtMethod body, ConstParameter constParam,
                               CtClass declaring)
    throws CannotCompileException
{
    CtMethod mt = new CtMethod(returnType, mname, parameterTypes,
                               declaring);
    mt.setModifiers(body.getModifiers());
    try {
        mt.setExceptionTypes(exceptionTypes);
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }

    Bytecode code = makeBody(declaring, declaring.getClassFile2(), body,
                             parameterTypes, returnType, constParam);
    MethodInfo minfo = mt.getMethodInfo2();
    minfo.setCodeAttribute(code.toCodeAttribute());
    // a stack map has been already created. 
    return mt;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:25,代碼來源:CtNewWrappedMethod.java

示例2: scan

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
public Subroutine[] scan(MethodInfo method) throws BadBytecode {
    CodeAttribute code = method.getCodeAttribute();
    CodeIterator iter = code.iterator();

    subroutines = new Subroutine[code.getCodeLength()];
    subTable.clear();
    done.clear();

    scan(0, iter, null);

    ExceptionTable exceptions = code.getExceptionTable();
    for (int i = 0; i < exceptions.size(); i++) {
        int handler = exceptions.handlerPc(i);
        // If an exception is thrown in subroutine, the handler
        // is part of the same subroutine.
        scan(handler, iter, subroutines[exceptions.startPc(i)]);
    }

    return subroutines;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:21,代碼來源:SubroutineScanner.java

示例3: buildExceptionInfo

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
    ConstPool constPool = method.getConstPool();
    ClassPool classes = clazz.getClassPool();

    ExceptionTable table = method.getCodeAttribute().getExceptionTable();
    ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
    for (int i = 0; i < table.size(); i++) {
        int index = table.catchType(i);
        Type type;
        try {
            type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
        } catch (NotFoundException e) {
            throw new IllegalStateException(e.getMessage());
        }

        exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
    }

    return exceptions;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:21,代碼來源:Analyzer.java

示例4: firstFrame

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
private Frame firstFrame(MethodInfo method, int maxLocals, int maxStack) {
    int pos = 0;

    Frame first = new Frame(maxLocals, maxStack);
    if ((method.getAccessFlags() & AccessFlag.STATIC) == 0) {
        first.setLocal(pos++, Type.get(clazz));
    }

    CtClass[] parameters;
    try {
        parameters = Descriptor.getParameterTypes(method.getDescriptor(), clazz.getClassPool());
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }

    for (int i = 0; i < parameters.length; i++) {
        Type type = zeroExtend(Type.get(parameters[i]));
        first.setLocal(pos++, type);
        if (type.getSize() == 2)
            first.setLocal(pos++, Type.TOP);
    }

    return first;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:25,代碼來源:Analyzer.java

示例5: makeBlocks

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
/**
 * Divides the method body into basic blocks.
 * The type information of the first block is initialized.
 *
 * @param optimize       if it is true and the method does not include
 *                      branches, this method returns null.
 */
public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca,
                                      boolean optimize)
    throws BadBytecode
{
    TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo);
    if (optimize && blocks.length < 2)
        if (blocks.length == 0 || blocks[0].incoming == 0)
            return null;

    ConstPool pool = minfo.getConstPool();
    boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0;
    blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(),
                             pool.getClassName(), minfo.getDescriptor(),
                             isStatic, minfo.isConstructor());
    return blocks;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:24,代碼來源:TypedBlock.java

示例6: override

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
private void override(String thisClassname, Method meth, String prefix,
                      int index, String desc, ClassFile cf, ConstPool cp, ArrayList forwarders)
    throws CannotCompileException
{
    Class declClass = meth.getDeclaringClass();
    String delegatorName = prefix + index + meth.getName();
    if (Modifier.isAbstract(meth.getModifiers()))
        delegatorName = null;
    else {
        MethodInfo delegator
            = makeDelegator(meth, desc, cp, declClass, delegatorName);
        // delegator is not a bridge method.  See Sec. 15.12.4.5 of JLS 3rd Ed.
        delegator.setAccessFlags(delegator.getAccessFlags() & ~AccessFlag.BRIDGE);
        cf.addMethod(delegator);
    }

    MethodInfo forwarder
        = makeForwarder(thisClassname, meth, desc, cp, declClass,
                        delegatorName, index, forwarders);
    cf.addMethod(forwarder);
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:22,代碼來源:ProxyFactory.java

示例7: makeConstructors

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
private void makeConstructors(String thisClassName, ClassFile cf,
        ConstPool cp, String classname) throws CannotCompileException
{
    Constructor[] cons = SecurityActions.getDeclaredConstructors(superClass);
    // legacy: if we are not caching then we need to initialise the default handler
    boolean doHandlerInit = !factoryUseCache;
    for (int i = 0; i < cons.length; i++) {
        Constructor c = cons[i];
        int mod = c.getModifiers();
        if (!Modifier.isFinal(mod) && !Modifier.isPrivate(mod)
                && isVisible(mod, basename, c)) {
            MethodInfo m = makeConstructor(thisClassName, c, cp, superClass, doHandlerInit);
            cf.addMethod(m);
        }
    }
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:17,代碼來源:ProxyFactory.java

示例8: makeDelegator

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
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;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:22,代碼來源:ProxyFactory.java

示例9: makeWriteReplace

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
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("RuntimeSupport",
                         "makeSerializedProxy",
                         "(Ljava/lang/Object;)Ljavassist/util/proxy/SerializedProxy;");
    code.addOpcode(Opcode.ARETURN);
    minfo.setCodeAttribute(code.toCodeAttribute());
    return minfo;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:17,代碼來源:ProxyFactory.java

示例10: getEnclosingBehavior

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
public CtBehavior getEnclosingBehavior() throws NotFoundException {
    ClassFile cf = getClassFile2();
    EnclosingMethodAttribute ema
            = (EnclosingMethodAttribute)cf.getAttribute(
                                            EnclosingMethodAttribute.tag);
    if (ema == null)
        return null;
    else {
        CtClass enc = classPool.get(ema.className());
        String name = ema.methodName();
        if (MethodInfo.nameInit.equals(name))
            return enc.getConstructor(ema.methodDescriptor());
        else if(MethodInfo.nameClinit.equals(name))
            return enc.getClassInitializer();
        else
            return enc.getMethod(name, ema.methodDescriptor());
    }
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:19,代碼來源:CtClassType.java

示例11: doit

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
/**
 * Visits each bytecode in the given range. 
 */
boolean doit(CtClass clazz, MethodInfo minfo, LoopContext context,
             CodeIterator iterator, int endPos)
    throws CannotCompileException
{
    boolean edited = false;
    while (iterator.hasNext() && iterator.lookAhead() < endPos) {
        int size = iterator.getCodeLength();
        if (loopBody(iterator, clazz, minfo, context)) {
            edited = true;
            int size2 = iterator.getCodeLength();
            if (size != size2)  // the body was modified.
                endPos += size2 - size;
        }
    }

    return edited;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:21,代碼來源:ExprEditor.java

示例12: atNewExpr

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
public void atNewExpr(NewExpr expr) throws CompileError {
    if (expr.isArray())
        atNewArrayExpr(expr);
    else {
        CtClass clazz = resolver.lookupClassByName(expr.getClassName());
        String cname = clazz.getName();
        ASTList args = expr.getArguments();
        bytecode.addNew(cname);
        bytecode.addOpcode(DUP);

        atMethodCallCore(clazz, MethodInfo.nameInit, args,
                         false, true, -1, null);

        exprType = CLASS;
        arrayDim = 0;
        className = MemberResolver.javaToJvmName(cname);
    }
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:19,代碼來源:MemberCodeGen.java

示例13: atFieldAssignCore

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
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());
    }
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:25,代碼來源:MemberCodeGen.java

示例14: atFieldRead

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
/**
 * 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;
    }
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:31,代碼來源:MemberCodeGen.java

示例15: getDefault

import scouter.javassist.bytecode.MethodInfo; //導入依賴的package包/類
private Object getDefault(String name, Method method)
    throws ClassNotFoundException, RuntimeException
{
    String classname = annotation.getTypeName();
    if (pool != null) {
        try {
            CtClass cc = pool.get(classname);
            ClassFile cf = cc.getClassFile2();
            MethodInfo minfo = cf.getMethod(name);
            if (minfo != null) {
                AnnotationDefaultAttribute ainfo
                    = (AnnotationDefaultAttribute)
                      minfo.getAttribute(AnnotationDefaultAttribute.tag);
                if (ainfo != null) {
                    MemberValue mv = ainfo.getDefaultValue();
                    return mv.getValue(classLoader, pool, method);
                }
            }
        }
        catch (NotFoundException e) {
            throw new RuntimeException("cannot find a class file: "
                                       + classname);
        }
    }

    throw new RuntimeException("no default value: " + classname + "."
                               + name + "()");
}
 
開發者ID:scouter-project,項目名稱:bytescope,代碼行數:29,代碼來源:AnnotationImpl.java


注:本文中的scouter.javassist.bytecode.MethodInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。