当前位置: 首页>>代码示例>>Java>>正文


Java CtBehavior类代码示例

本文整理汇总了Java中scouter.javassist.CtBehavior的典型用法代码示例。如果您正苦于以下问题:Java CtBehavior类的具体用法?Java CtBehavior怎么用?Java CtBehavior使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CtBehavior类属于scouter.javassist包,在下文中一共展示了CtBehavior类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compile

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Compiles a method, constructor, or field declaration
 * to a class.
 * A field declaration can declare only one field.
 *
 * <p>In a method or constructor body, $0, $1, ... and $_
 * are not available.
 *
 * @return          a <code>CtMethod</code>, <code>CtConstructor</code>,
 *                  or <code>CtField</code> object.
 * @see #recordProceed(String,String)
 */
public CtMember compile(String src) throws CompileError {
    Parser p = new Parser(new Lex(src));
    ASTList mem = p.parseMember1(stable);
    try {
        if (mem instanceof FieldDecl)
            return compileField((FieldDecl)mem);
        else {
            CtBehavior cb = compileMethod(p, (MethodDecl)mem);
            CtClass decl = cb.getDeclaringClass();
            cb.getMethodInfo2()
              .rebuildStackMapIf6(decl.getClassPool(),
                                  decl.getClassFile2());
            return cb;
        }
    }
    catch (BadBytecode bb) {
        throw new CompileError(bb.getMessage());
    }
    catch (CannotCompileException e) {
        throw new CompileError(e.getMessage());
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:35,代码来源:Javac.java

示例2: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the constructor or method containing the expression.
 */
public CtBehavior where() {
    MethodInfo mi = thisMethod;
    CtBehavior[] cb = thisClass.getDeclaredBehaviors();
    for (int i = cb.length - 1; i >= 0; --i)
        if (cb[i].getMethodInfo2() == mi)
            return cb[i];

    CtConstructor init = thisClass.getClassInitializer();
    if (init != null && init.getMethodInfo2() == mi)
        return init;

    /* getDeclaredBehaviors() returns a list of methods/constructors.
     * Although the list is cached in a CtClass object, it might be
     * recreated for some reason.  Thus, the member name and the signature
     * must be also checked.
     */
    for (int i = cb.length - 1; i >= 0; --i) {
        if (thisMethod.getName().equals(cb[i].getMethodInfo2().getName())
            && thisMethod.getDescriptor()
                         .equals(cb[i].getMethodInfo2().getDescriptor())) {
            return cb[i];
        }
    }

    throw new RuntimeException("fatal: not found");
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:30,代码来源:Expr.java

示例3: compileMethod

import scouter.javassist.CtBehavior; //导入依赖的package包/类
private CtBehavior compileMethod(Parser p, MethodDecl md)
    throws CompileError
{
    int mod = MemberResolver.getModifiers(md.getModifiers());
    CtClass[] plist = gen.makeParamList(md);
    CtClass[] tlist = gen.makeThrowsList(md);
    recordParams(plist, Modifier.isStatic(mod));
    md = p.parseMethod2(stable, md);
    try {
        if (md.isConstructor()) {
            CtConstructor cons = new CtConstructor(plist,
                                               gen.getThisClass());
            cons.setModifiers(mod);
            md.accept(gen);
            cons.getMethodInfo().setCodeAttribute(
                                    bytecode.toCodeAttribute());
            cons.setExceptionTypes(tlist);
            return cons;
        }
        else {
            Declarator r = md.getReturn();
            CtClass rtype = gen.resolver.lookupClass(r);
            recordReturnType(rtype, false);
            CtMethod method = new CtMethod(rtype, r.getVariable().get(),
                                       plist, gen.getThisClass());
            method.setModifiers(mod);
            gen.setThisMethod(method);
            md.accept(gen);
            if (md.getBody() != null)
                method.getMethodInfo().setCodeAttribute(
                                    bytecode.toCodeAttribute());
            else
                method.setModifiers(mod | Modifier.ABSTRACT);

            method.setExceptionTypes(tlist);
            return method;
        }
    }
    catch (NotFoundException e) {
        throw new CompileError(e.toString());
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:43,代码来源:Javac.java

示例4: compileBody

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Compiles a method (or constructor) body.
 *
 * @param src	a single statement or a block.
 *              If null, this method produces a body returning zero or null.
 */
public Bytecode compileBody(CtBehavior method, String src)
    throws CompileError
{
    try {
        int mod = method.getModifiers();
        recordParams(method.getParameterTypes(), Modifier.isStatic(mod));

        CtClass rtype;
        if (method instanceof CtMethod) {
            gen.setThisMethod((CtMethod)method);
            rtype = ((CtMethod)method).getReturnType();
        }
        else
            rtype = CtClass.voidType;

        recordReturnType(rtype, false);
        boolean isVoid = rtype == CtClass.voidType;

        if (src == null)
            makeDefaultBody(bytecode, rtype);
        else {
            Parser p = new Parser(new Lex(src));
            SymbolTable stb = new SymbolTable(stable);
            Stmnt s = p.parseStatement(stb);
            if (p.hasMore())
                throw new CompileError(
                    "the method/constructor body must be surrounded by {}");

            boolean callSuper = false;
            if (method instanceof CtConstructor)
                callSuper = !((CtConstructor)method).isClassInitializer();

            gen.atMethodBody(s, callSuper, isVoid);
        }

        return bytecode;
    }
    catch (NotFoundException e) {
        throw new CompileError(e.toString());
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:48,代码来源:Javac.java

示例5: insertBefore

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Utility method to insert callback at the beginning of the body.
 *
 * @param callback  The callback
 *
 * @see CtBehavior#insertBefore(String)
 */
public static void insertBefore(CtBehavior behavior, Callback callback)
        throws CannotCompileException
{
    behavior.insertBefore(callback.toString());
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:13,代码来源:Callback.java

示例6: insertAfter

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Utility method to inserts callback at the end of the body.
 * The callback is inserted just before every return instruction.
 * It is not executed when an exception is thrown.
 *
 * @param behavior  The behaviour to insert callback in
 * @param callback  The callback
 *
 * @see CtBehavior#insertAfter(String, boolean)
 */
public static void insertAfter(CtBehavior behavior,Callback callback)
        throws CannotCompileException
{
    behavior.insertAfter(callback.toString(), false);
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:16,代码来源:Callback.java

示例7: insertAt

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Utility method to inserts callback at the specified line in the body.
 *
 * @param behavior  The behaviour to insert callback in
 * @param callback  The callback representing.
 * @param lineNum   The line number.  The callback is inserted at the
 *                  beginning of the code at the line specified by this
 *                  line number.
 *
 * @return      The line number at which the callback has been inserted.
 *
 * @see CtBehavior#insertAt(int, String)
 */
public static int insertAt(CtBehavior behavior, Callback callback, int lineNum)
        throws CannotCompileException
{
    return behavior.insertAt(lineNum, callback.toString());
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:19,代码来源:Callback.java

示例8: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the method or constructor containing the catch clause.
 */
public CtBehavior where() { return super.where(); }
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:5,代码来源:Handler.java

示例9: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the method or constructor containing the type cast
 * expression represented by this object.
 */
public CtBehavior where() { return super.where(); }
 
开发者ID:scouter-project,项目名称:scouter,代码行数:6,代码来源:Cast.java

示例10: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the method or constructor containing the method-call
 * expression represented by this object.
 */
public CtBehavior where() { return super.where(); }
 
开发者ID:scouter-project,项目名称:scouter,代码行数:6,代码来源:MethodCall.java

示例11: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the method or constructor containing the field-access
 * expression represented by this object.
 */
public CtBehavior where() { return super.where(); }
 
开发者ID:scouter-project,项目名称:scouter,代码行数:6,代码来源:FieldAccess.java

示例12: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the method or constructor containing the array creation
 * represented by this object.
 */
public CtBehavior where() { return super.where(); }
 
开发者ID:scouter-project,项目名称:scouter,代码行数:6,代码来源:NewArray.java

示例13: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the method or constructor containing the instanceof
 * expression represented by this object.
 */
public CtBehavior where() { return super.where(); }
 
开发者ID:scouter-project,项目名称:scouter,代码行数:6,代码来源:Instanceof.java

示例14: where

import scouter.javassist.CtBehavior; //导入依赖的package包/类
/**
 * Returns the method or constructor containing the <tt>new</tt>
 * expression represented by this object.
 */
public CtBehavior where() { return super.where(); }
 
开发者ID:scouter-project,项目名称:scouter,代码行数:6,代码来源:NewExpr.java


注:本文中的scouter.javassist.CtBehavior类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。