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


Java CtPrimitiveType类代码示例

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


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

示例1: toDescriptor

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
private static void toDescriptor(StringBuffer desc, CtClass type) {
    if (type.isArray()) {
        desc.append('[');
        try {
            toDescriptor(desc, type.getComponentType());
        }
        catch (NotFoundException e) {
            desc.append('L');
            String name = type.getName();
            desc.append(toJvmName(name.substring(0, name.length() - 2)));
            desc.append(';');
        }
    }
    else if (type.isPrimitive()) {
        CtPrimitiveType pt = (CtPrimitiveType)type;
        desc.append(pt.getDescriptor());
    }
    else { // class type
        desc.append('L');
        desc.append(type.getName().replace('.', '/'));
        desc.append(';');
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:24,代码来源:Descriptor.java

示例2: setType

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
private void setType(CtClass type, int dim) throws CompileError {
    if (type.isPrimitive()) {
        CtPrimitiveType pt = (CtPrimitiveType)type;
        exprType = MemberResolver.descToType(pt.getDescriptor());
        arrayDim = dim;
        className = null;
    }
    else if (type.isArray())
        try {
            setType(type.getComponentType(), dim + 1);
        }
        catch (NotFoundException e) {
            throw new CompileError("undefined type: " + type.getName());
        }
    else {
        exprType = CLASS;
        arrayDim = dim;
        className = MemberResolver.javaToJvmName(type.getName());
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:21,代码来源:JvstTypeChecker.java

示例3: atCastToRtype

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
/**
 * Inserts a cast operator to the return type.
 * If the return type is void, this does nothing.
 */
protected void atCastToRtype(CastExpr expr) throws CompileError {
    expr.getOprand().accept(this);
    if (exprType == VOID || isRefType(exprType) || arrayDim > 0)
        compileUnwrapValue(returnType, bytecode);
    else if (returnType instanceof CtPrimitiveType) {
        CtPrimitiveType pt = (CtPrimitiveType)returnType;
        int destType = MemberResolver.descToType(pt.getDescriptor());
        atNumCastExpr(exprType, destType);
        exprType = destType;
        arrayDim = 0;
        className = null;
    }
    else
        throw new CompileError("invalid cast");
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:20,代码来源:JvstCodeGen.java

示例4: atCastToWrapper

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
protected void atCastToWrapper(CastExpr expr) throws CompileError {
    expr.getOprand().accept(this);
    if (isRefType(exprType) || arrayDim > 0)
        return;     // Object type.  do nothing.

    CtClass clazz = resolver.lookupClass(exprType, arrayDim, className);
    if (clazz instanceof CtPrimitiveType) {
        CtPrimitiveType pt = (CtPrimitiveType)clazz;
        String wrapper = pt.getWrapperName();
        bytecode.addNew(wrapper);           // new <wrapper>
        bytecode.addOpcode(DUP);            // dup
        if (pt.getDataSize() > 1)
            bytecode.addOpcode(DUP2_X2);    // dup2_x2
        else
            bytecode.addOpcode(DUP2_X1);    // dup2_x1

        bytecode.addOpcode(POP2);           // pop2
        bytecode.addInvokespecial(wrapper, "<init>",
                                  "(" + pt.getDescriptor() + ")V");
                                            // invokespecial
        exprType = CLASS;
        arrayDim = 0;
        className = jvmJavaLangObject;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:26,代码来源:JvstCodeGen.java

示例5: compileUnwrapValue

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
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);
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:26,代码来源:JvstCodeGen.java

示例6: doit

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
    throws CompileError
{
    if (args != null && !gen.isParamListName(args))
        throw new CompileError(Javac.proceedName
                + "() cannot take a parameter for field reading");

    int stack;
    if (isStatic(opcode))
        stack = 0;
    else {
        stack = -1;
        bytecode.addAload(targetVar);
    }

    if (fieldType instanceof CtPrimitiveType)
        stack += ((CtPrimitiveType)fieldType).getDataSize();
    else
        ++stack;

    bytecode.add(opcode);
    bytecode.addIndex(index);
    bytecode.growStack(stack);
    gen.setType(fieldType);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:26,代码来源:FieldAccess.java

示例7: storeStack0

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
private static void storeStack0(int i, int n, CtClass[] params, int regno,
        Bytecode bytecode) {
    if (i >= n)
        return;
    else {
        CtClass c = params[i];
        int size;
        if (c instanceof CtPrimitiveType)
            size = ((CtPrimitiveType)c).getDataSize();
        else
            size = 1;

        storeStack0(i + 1, n, params, regno + size, bytecode);
        bytecode.addStore(regno, c);
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:17,代码来源:Expr.java

示例8: addReturn

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
/**
 * Appends ARETURN, IRETURN, .., or RETURN.
 *
 * @param type      the return type.
 */
public void addReturn(CtClass type) {
    if (type == null)
        addOpcode(RETURN);
    else if (type.isPrimitive()) {
        CtPrimitiveType ptype = (CtPrimitiveType)type;
        addOpcode(ptype.getReturnOp());
    }
    else
        addOpcode(ARETURN);
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:16,代码来源:Bytecode.java

示例9: atCastToRtype

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
/**
 * Inserts a cast operator to the return type.
 * If the return type is void, this does nothing.
 */
protected void atCastToRtype(CastExpr expr) throws CompileError {
    CtClass returnType = codeGen.returnType;
    expr.getOprand().accept(this);
    if (exprType == VOID || CodeGen.isRefType(exprType) || arrayDim > 0)
        compileUnwrapValue(returnType);
    else if (returnType instanceof CtPrimitiveType) {
        CtPrimitiveType pt = (CtPrimitiveType)returnType;
        int destType = MemberResolver.descToType(pt.getDescriptor());
        exprType = destType;
        arrayDim = 0;
        className = null;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:18,代码来源:JvstTypeChecker.java

示例10: atCastToWrapper

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
protected void atCastToWrapper(CastExpr expr) throws CompileError {
    expr.getOprand().accept(this);
    if (CodeGen.isRefType(exprType) || arrayDim > 0)
        return;     // Object type.  do nothing.

    CtClass clazz = resolver.lookupClass(exprType, arrayDim, className);
    if (clazz instanceof CtPrimitiveType) {
        exprType = CLASS;
        arrayDim = 0;
        className = jvmJavaLangObject;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:13,代码来源:JvstTypeChecker.java

示例11: compileParameterList

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
public static int compileParameterList(Bytecode code,
                            CtClass[] params, int regno) {
    if (params == null) {
        code.addIconst(0);                          // iconst_0
        code.addAnewarray(javaLangObject);          // anewarray Object
        return 1;
    }
    else {
        CtClass[] args = new CtClass[1];
        int n = params.length;
        code.addIconst(n);                          // iconst_<n>
        code.addAnewarray(javaLangObject);          // anewarray Object
        for (int i = 0; i < n; ++i) {
            code.addOpcode(Bytecode.DUP);           // dup
            code.addIconst(i);                      // iconst_<i>
            if (params[i].isPrimitive()) {
                CtPrimitiveType pt = (CtPrimitiveType)params[i];
                String wrapper = pt.getWrapperName();
                code.addNew(wrapper);               // new <wrapper>
                code.addOpcode(Bytecode.DUP);       // dup
                int s = code.addLoad(regno, pt);    // ?load <regno>
                regno += s;
                args[0] = pt;
                code.addInvokespecial(wrapper, "<init>",
                            Descriptor.ofMethod(CtClass.voidType, args));
                                                    // invokespecial
            }
            else {
                code.addAload(regno);               // aload <regno>
                ++regno;
            }

            code.addOpcode(Bytecode.AASTORE);       // aastore
        }

        return 8;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:39,代码来源:JvstCodeGen.java

示例12: doNumCast

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
public void doNumCast(CtClass type) throws CompileError {
    if (arrayDim == 0 && !isRefType(exprType))
        if (type instanceof CtPrimitiveType) {
            CtPrimitiveType pt = (CtPrimitiveType)type;
            atNumCastExpr(exprType,
                          MemberResolver.descToType(pt.getDescriptor()));
        }
        else
            throw new CompileError("type mismatch");
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:11,代码来源:JvstCodeGen.java

示例13: makeDefaultBody

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
private static void makeDefaultBody(Bytecode b, CtClass type) {
    int op;
    int value;
    if (type instanceof CtPrimitiveType) {
        CtPrimitiveType pt = (CtPrimitiveType)type;
        op = pt.getReturnOp();
        if (op == Opcode.DRETURN)
            value = Opcode.DCONST_0;
        else if (op == Opcode.FRETURN)
            value = Opcode.FCONST_0;
        else if (op == Opcode.LRETURN)
            value = Opcode.LCONST_0;
        else if (op == Opcode.RETURN)
            value = Opcode.NOP;
        else
            value = Opcode.ICONST_0;
    }
    else {
        op = Opcode.ARETURN;
        value = Opcode.ACONST_NULL;
    }

    if (value != Opcode.NOP)
        b.addOpcode(value);

    b.addOpcode(op);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:28,代码来源:Javac.java

示例14: replace2

import scouter.javassist.CtPrimitiveType; //导入依赖的package包/类
private void replace2(String statement)
    throws CompileError, NotFoundException, BadBytecode,
           CannotCompileException
{
    thisClass.getClassFile();   // to call checkModify().
    ConstPool constPool = getConstPool();
    int pos = currentPos;
    CtClass retType;
    int codeLength;
    int index = 0;
    int dim = 1;
    String desc;
    if (opcode == Opcode.NEWARRAY) {
        index = iterator.byteAt(currentPos + 1);    // atype
        CtPrimitiveType cpt = (CtPrimitiveType)getPrimitiveType(index);
        desc = "[" + cpt.getDescriptor();
        codeLength = 2;
    }
    else if (opcode == Opcode.ANEWARRAY) {
        index = iterator.u16bitAt(pos + 1);
        desc = constPool.getClassInfo(index);
        if (desc.startsWith("["))
            desc = "[" + desc;
        else
            desc = "[L" + desc + ";";

        codeLength = 3;
    }
    else if (opcode == Opcode.MULTIANEWARRAY) {
        index = iterator.u16bitAt(currentPos + 1);
        desc = constPool.getClassInfo(index);
        dim = iterator.byteAt(currentPos + 3);
        codeLength = 4;
    }
    else
        throw new RuntimeException("bad opcode: " + opcode);

    retType = Descriptor.toCtClass(desc, thisClass.getClassPool());

    Javac jc = new Javac(thisClass);
    CodeAttribute ca = iterator.get();

    CtClass[] params = new CtClass[dim];
    for (int i = 0; i < dim; ++i)
        params[i] = CtClass.intType;

    int paramVar = ca.getMaxLocals();
    jc.recordParams(javaLangObject, params,
                    true, paramVar, withinStatic());

    /* Is $_ included in the source code?
     */
    checkResultValue(retType, statement);
    int retVar = jc.recordReturnType(retType, true);
    jc.recordProceed(new ProceedForArray(retType, opcode, index, dim));

    Bytecode bytecode = jc.getBytecode();
    storeStack(params, true, paramVar, bytecode);
    jc.recordLocalVariables(ca, pos);

    bytecode.addOpcode(Opcode.ACONST_NULL);        // initialize $_
    bytecode.addAstore(retVar);

    jc.compileStmnt(statement);
    bytecode.addAload(retVar);

    replace0(pos, bytecode, codeLength);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:69,代码来源:NewArray.java


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