Example usage for org.objectweb.asm Type getDescriptor

List of usage examples for org.objectweb.asm Type getDescriptor

Introduction

In this page you can find the example usage for org.objectweb.asm Type getDescriptor.

Prototype

public String getDescriptor() 

Source Link

Document

Returns the descriptor corresponding to this type.

Usage

From source file:ca.weblite.asm.JavaSourceMirrorLoader.java

@Override
public MirrorType findMirror(Type type) {
    MirrorType out = super.findMirror(type);
    if (out != null) {
        return out;
    }//from  w w  w .  ja va 2s  .  c o  m

    if (type.getSort() == Type.ARRAY) {
        return findArrayMirror(Type.getType(type.getDescriptor().substring(1)));
    }

    ClassNode node = loader.findClass(type);
    if (node != null) {
        BytecodeMirror mirror = new BytecodeMirror(context, node, ancestorLoader);
        return mirror;
    }
    return null;

}

From source file:ca.weblite.mirah.ant.mirrors.JavaSourceMirrorLoader.java

@Override
public MirrorType findMirror(Type type) {
    MirrorType out = null;//from   www.j  a v a  2  s . com
    if ((out = super.findMirror(type)) == null) {
        if (type.getSort() == Type.ARRAY) {
            return findArrayMirror(Type.getType(type.getDescriptor().substring(1)));
        }
        String path = null;
        String[] parts = type.getInternalName().split("/");
        int len = parts.length;
        while (path == null && len > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < len; i++) {
                sb.append(parts[i]).append("/");
            }
            String test = sb.substring(0, sb.length() - 1) + ".java";
            path = findInClassPath(test);
        }
        ClassNode node = new ClassNode();

    }
    return out;
}

From source file:ch.eiafr.cojac.instrumenters.FloatProxyMethod.java

License:Apache License

public void proxyCallBetterWithVars(MethodVisitor mv, ConversionContext cc) {
    final String pm = "possibleMethod";
    final String pmDesc = "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/reflect/Method;";
    final String myInvoke = "myInvoke";
    final String myInvokeDesc = "(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;";
    // checkNotNullStack();
    // int paramArrayVar = mla.paramArrayVar();
    // int targetVar = mla.targetVar();
    // Label lEndTry = new Label(); 
    Label lBeginHandler = new Label(), lEndHandler = new Label();
    Type cojReturnType = Type.getReturnType(cc.cDesc);
    // stack >> target prm0 prm1 prm2...
    convertArgumentsToReal(mv, cc);//from  w  w w. ja v a 2s. c  o  m
    // stack >> target allParamsArr target allParamsArr
    // {
    //            mv.visitVarInsn(ASTORE, paramArrayVar);
    //            // stack >> target allParamsArr target
    //            //--------- String targetType=stackTopClass();
    //            mv.visitVarInsn(ASTORE, targetVar);
    // }
    mv.visitInsn(POP);
    mv.visitInsn(POP);
    // stack >> target allParamsArr
    Object[] localsInFrame = aaAfter.locals.toArray();
    mv.visitInsn(SWAP);
    // stack >> allParamsArr target
    mv.visitInsn(DUP_X1);
    // stack >> target allParamsArr target
    mv.visitLdcInsn(cc.name);
    // stack >> target allParamsArr target methName
    mv.visitLdcInsn(cc.cDesc);
    // stack >> target allParamsArr target methName methDesc
    mv.visitMethodInsn(INVOKESTATIC, DN_NAME, pm, pmDesc, false);
    // stack >> target allParamsArr nullOrMeth
    mv.visitInsn(DUP);
    // stack >> target allParamsArr nullOrMeth nullOrMeth

    ArrayList<Object> scl = new ArrayList<Object>(aaAfter.stack);
    scl.remove(scl.size() - 1); // remove the last nullOrMeth
    Object[] stackContent = scl.toArray(); //target allParamsArr nullOrMeth

    mv.visitJumpInsn(IFNULL, lBeginHandler);
    aaAfter.visitFrame(F_NEW, localsInFrame.length, localsInFrame, stackContent.length, stackContent);
    // stack >> target allParamsArr meth
    mv.visitInsn(DUP_X2);
    // stack >> meth target allParamsArr meth
    mv.visitInsn(POP);
    // stack >> meth target allParamsArr
    mv.visitLdcInsn(cc.inArgs.length);
    // stack >> meth target allParamsArr n
    mv.visitInsn(AALOAD);
    // stack >> meth target asObjPrm
    mv.visitTypeInsn(CHECKCAST, "[" + OBJ_TYPE.getDescriptor());
    // stack >> meth target appropriatePrmArr 
    mv.visitMethodInsn(INVOKESTATIC, DN_NAME, myInvoke, myInvokeDesc, false);
    // stack >> [ResultOrNull]
    if (cc.hasReturn()) {
        if (cc.hasPrimitiveResultInCojacVersion()) {
            String jWrapperName = getJWrapper(cojReturnType).getInternalName();
            mv.visitTypeInsn(CHECKCAST, jWrapperName);
            mv.visitMethodInsn(INVOKEVIRTUAL, jWrapperName, getWrapperToPrimitiveMethod(cojReturnType),
                    "()" + cojReturnType.getDescriptor(), false);
        } else {
            mv.visitTypeInsn(CHECKCAST, cojReturnType.getInternalName());
        }
    } else {
        mv.visitInsn(POP); // discard the dummy null result
    }
    // stack >> [possibleResult]
    //;; mv.visitLabel(lEndTry);
    mv.visitJumpInsn(GOTO, lEndHandler); // and we're done !

    ;
    ;
    mv.visitLabel(lBeginHandler);
    // stack >> target allParamsArr null
    // CAUTION: we bypass 'mv' and directly talk to the AnalyzerAdapter!
    aaAfter.visitFrame(F_NEW, localsInFrame.length, localsInFrame, stackContent.length, stackContent);
    //checkNotNullStack();  //was during debugging - removed
    mv.visitInsn(POP); // we drop the null (no-method) slot
    maybeConvertTarget(mv, cc.opcode, cc.owner);
    // stack >> newTarget allParamsArr
    mv.visitInsn(DUP_X1);
    // stack >> allParamsArr newTarget allParamsArr
    explodeOnStack(mv, cc, true);
    // stack >> allParamsArr newTarget nprm0 nprm1 nprm2...
    mv.visitMethodInsn(cc.opcode, cc.owner, cc.name, cc.jDesc, (cc.opcode == INVOKEINTERFACE));
    // stack >> allParamsArr [possibleResult]
    checkArraysAfterCall(mv, cc.convertedArrays, cc.jDesc);
    // stack >> [possibleResult]
    convertReturnType(mv, cc.jDesc);
    // stack >> [newPossibleResult]
    ;
    ;
    mv.visitLabel(lEndHandler);
    scl.remove(scl.size() - 1); // remove 3 slots: target allParamsArr nullOrMeth
    scl.remove(scl.size() - 1);
    scl.remove(scl.size() - 1);
    stackContent = scl.toArray();
    stackContent = addReturnTypeTo(stackContent, cojReturnType);
    aaAfter.visitFrame(F_NEW, localsInFrame.length, localsInFrame, stackContent.length, stackContent);
}

From source file:ch.eiafr.cojac.instrumenters.FloatProxyMethod.java

License:Apache License

private static void explodeOnStack(MethodVisitor mv, ConversionContext cc, boolean wantTheConversion) {
    Type[] args = wantTheConversion ? cc.outArgs : cc.inArgs;
    // stack >> ... allParamsArr
    for (int i = 0; i < args.length; i++) {
        // stack >> ... allParamsArr
        Type oa = args[i];
        int oaSort = oa.getSort();
        mv.visitInsn(DUP);//from   w  w w .jav a 2 s .  c  o  m
        mv.visitLdcInsn(i);
        mv.visitInsn(AALOAD);
        boolean keepBothVersions = (oa.getSort() == Type.ARRAY);
        if (keepBothVersions) {
            mv.visitTypeInsn(CHECKCAST, "[" + OBJ_TYPE.getDescriptor());
            mv.visitLdcInsn(wantTheConversion ? 1 : 0);
            mv.visitInsn(AALOAD);
        }

        if (oaSort == Type.ARRAY || oaSort == Type.OBJECT) { // else: primitive type
            mv.visitTypeInsn(CHECKCAST, oa.getInternalName());
        } else {
            String jWrapperName = getJWrapper(oa).getInternalName();
            mv.visitTypeInsn(CHECKCAST, jWrapperName);
            mv.visitMethodInsn(INVOKEVIRTUAL, jWrapperName, getWrapperToPrimitiveMethod(oa),
                    "()" + oa.getDescriptor(), false);
        }

        if (oa.getSize() == 2) { //    Object DD  Swap when double or long
            mv.visitInsn(DUP2_X1); // DD Object DD
            mv.visitInsn(POP2); // DD Object
        } else {
            mv.visitInsn(SWAP);
        }
        // stack >> ... nprmI allParamsArr
    }
    mv.visitInsn(POP);
    // stack >> ... nprm0 nprm1 nprm2...
}

From source file:ch.eiafr.cojac.instrumenters.FloatProxyMethod.java

License:Apache License

private static void convertPrimitiveToObject(MethodVisitor newMv, Type type) {
    if (type.getSort() == Type.ARRAY || type.getSort() == Type.OBJECT)
        return;/*from ww  w  .  j av  a 2 s .  co  m*/
    Type wrapper = getJWrapper(type);
    newMv.visitMethodInsn(INVOKESTATIC, wrapper.getInternalName(), "valueOf",
            "(" + type.getDescriptor() + ")" + wrapper.getDescriptor(), false);
}

From source file:ch.eiafr.cojac.instrumenters.InvokableMethod.java

License:Apache License

/** Float|float|Double|double [array] -> CojacWrapper */
public static Type afterFloatReplacement(Type type) {
    if (type.equals(Type.getType(Float.class)))
        return COJAC_FLOAT_WRAPPER_TYPE;
    if (type.equals(Type.FLOAT_TYPE))
        return COJAC_FLOAT_WRAPPER_TYPE;
    if (type.equals(Type.getType(Double.class)))
        return COJAC_DOUBLE_WRAPPER_TYPE;
    if (type.equals(Type.DOUBLE_TYPE))
        return COJAC_DOUBLE_WRAPPER_TYPE;
    if (type.getSort() == Type.ARRAY) {
        Type newType = afterFloatReplacement(type.getElementType());
        if (type.equals(newType))
            return type;
        String desc = "";
        for (int i = 0; i < type.getDimensions(); i++)
            desc += "[";
        desc += newType.getDescriptor();
        return Type.getType(desc);
    }/*from w  w  w. j a v a2s.c o m*/
    return type;
}

From source file:cl.inria.stiq.db.structure.impl.PrimitiveTypeInfo.java

License:Open Source License

public PrimitiveTypeInfo(String aName, Type aAsmType, int aSize, int aId) {
    super(null, aId, aName);
    itsJvmName = aAsmType.getDescriptor();
    itsSize = aSize;/*  w ww.  j av a  2  s.  c o  m*/
}

From source file:cl.inria.stiq.tools.LocationUtils.java

License:Open Source License

/**
 * Returns the argument types that correspond to the given behavior signature. 
 *//*from w  ww.jav a 2s .  c  o m*/
public static ITypeInfo[] getArgumentTypes(IStructureDatabase aDatabase, String aSignature) {
    Type[] theASMArgumentTypes = Type.getArgumentTypes(aSignature);
    ITypeInfo[] theArgumentTypes = new ITypeInfo[theASMArgumentTypes.length];

    for (int i = 0; i < theASMArgumentTypes.length; i++) {
        Type theASMType = theASMArgumentTypes[i];
        theArgumentTypes[i] = aDatabase.getType(theASMType.getDescriptor(), true);
    }

    return theArgumentTypes;
}

From source file:cl.inria.stiq.tools.LocationUtils.java

License:Open Source License

/**
 * Returns the argument types that correspond to the given behavior signature. 
 * If some type is not found in the database it is created.
 *//*from   w ww. java 2 s  .  c  om*/
public static ITypeInfo[] getArgumentTypes(IMutableStructureDatabase aDatabase, String aSignature) {
    Type[] theASMArgumentTypes = Type.getArgumentTypes(aSignature);
    ITypeInfo[] theArgumentTypes = new ITypeInfo[theASMArgumentTypes.length];

    for (int i = 0; i < theASMArgumentTypes.length; i++) {
        Type theASMType = theASMArgumentTypes[i];
        theArgumentTypes[i] = aDatabase.getNewType(theASMType.getDescriptor());

    }

    return theArgumentTypes;
}

From source file:cl.inria.stiq.tools.LocationUtils.java

License:Open Source License

/**
 * Determines a TOD return type given a method signature
 *//*from  w w  w  . ja va2 s . c  o  m*/
public static ITypeInfo getReturnType(IStructureDatabase aDatabase, String aSignature) {
    Type theASMType = Type.getReturnType(aSignature);
    return aDatabase.getType(theASMType.getDescriptor(), true);
}