Package org.objectweb.asm

Examples of org.objectweb.asm.Type


    Iterator<Map.Entry<String, Type>> i = fields.entrySet().iterator();
    while (i.hasNext()) {
      Map.Entry<String, Type> e = i.next();
      String fName = e.getKey();
      String fDesc = e.getValue().getDescriptor();
      Type fType = e.getValue();
      String mName;
      String mDesc;

      // generate field
      cv.visitField(ACC_PRIVATE, fName, fDesc, null, null).visitEnd();

      // generate getter
      mName = "get" + up(fName);
      mDesc = "()" + fDesc;
      mv = cv.visitMethod(ACC_PUBLIC, mName, mDesc, null, null);
      if (mv != null) {
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name, fName, fDesc);
        mv.visitInsn(fType.getOpcode(IRETURN));
        mv.visitMaxs(fType.getSize(), 1);
        mv.visitEnd();
      }

      // generate setter
      mName = "set" + up(fName);
      mDesc = "(" + fDesc + ")V";
      mv = cv.visitMethod(ACC_PUBLIC, mName, mDesc, null, null);
      if (mv != null) {
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(fType.getOpcode(ILOAD), 1);
        mv.visitFieldInsn(PUTFIELD, name, fName, fDesc);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1 + fType.getSize(), 1 + fType.getSize());
        mv.visitEnd();
      }
    }

    cv.visitEnd();
View Full Code Here


            validateArgs(runtime, targetClassName, superClass);

            Map methods = new HashMap();
            collectMethods(superClass, interfaces, methods, names);

            Type selfType = Type.getType("L"
                    + toInternalClassName(targetClassName) + ";");
            proxyClass = generate(loader, targetClassName, superClass,
                    interfaces, methods, selfType);

            proxies.put(key, proxyClass);
View Full Code Here

    private static void generateProxyMethods(Class superClass, Map methods,
            Type selfType, ClassVisitor cw, GeneratorAdapter clazzInit) {
        Iterator it = methods.values().iterator();
        while (it.hasNext()) {
            MethodData md = (MethodData) it.next();
            Type superClassType = Type.getType(superClass);
            generateProxyMethod(selfType, superClassType, cw, clazzInit, md);
        }
    }
View Full Code Here

        ga.visitTryCatchBlock(before, after, rethrow, "java/lang/Error");
        ga.visitTryCatchBlock(before, after, rethrow,
                "java/lang/RuntimeException");

        Type thr = Type.getType(Throwable.class);
        Label handler = ga.mark();
        Type udt = Type.getType(UndeclaredThrowableException.class);
        int loc = ga.newLocal(thr);
        ga.storeLocal(loc, thr);
        ga.newInstance(udt);
        ga.dup();
        ga.loadLocal(loc, thr);
View Full Code Here

            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, _internalClassName, _subjectAnalysisDataContainer._syntheticProxyFieldName, "Lcom/mobixess/jodb/core/query/NQueryDataObjectProxy;");
            //mv.visitFieldInsn(GETFIELD, "com/mobixess/jodb/tests/transformations/TestTrans", "_dataObjectProxy", "Lcom/mobixess/jodb/core/query/NQueryDataObjectProxy;");
            mv.visitLdcInsn(referringFieldId);
            //mv.visitIntInsn(BIPUSH, 10);
            Type type = Type.getType(typeClass);
            String getMethodSuffix = typeClass.getName();
            int lastDotIndx = getMethodSuffix.lastIndexOf('.');
            if(lastDotIndx>=0){
                getMethodSuffix = getMethodSuffix.substring(lastDotIndx+1);
            }
            mv.visitMethodInsn(INVOKEVIRTUAL, "com/mobixess/jodb/core/query/NQueryDataObjectProxy", "getValue_"+getMethodSuffix, "(I)"+type.getDescriptor());
            //mv.visitMethodInsn(INVOKEVIRTUAL, "com/mobixess/jodb/core/query/NQueryDataObjectProxy", "getIntValue", "(I)I");
            mv.visitFieldInsn(PUTFIELD, _internalClassName, fieldName, type.getDescriptor());
            //mv.visitFieldInsn(PUTFIELD, "com/mobixess/jodb/tests/transformations/TestTrans", "_localVar", "I");
            mv.visitLabel(l1);
        }
View Full Code Here

        }
       
        private void writeReturn(MethodVisitor mv, Field field){
            Label l4 = new Label();
            mv.visitLabel(l4);
            Type declaringClassType = Type.getType(field.getDeclaringClass());
            Class fieldTypeClass = field.getType();
           
            int returnOpcode = -1;
            if(!fieldTypeClass.isPrimitive()){
                returnOpcode = Opcodes.ARETURN;
            }else{
                try {
                    PRIMITIVES_ENUMERATION primitives_enumeration = PrimitiveJavaTypesUtil.getEnumeratedType(fieldTypeClass.getName());
                    switch (primitives_enumeration) {
                        case _long:
                            returnOpcode = Opcodes.LRETURN;
                            break;
                        case _double:
                            returnOpcode = Opcodes.DRETURN;
                            break;
                        case _float:
                            returnOpcode = Opcodes.FRETURN;
                            break;
                        default:
                            returnOpcode = Opcodes.IRETURN;
                            break;
                    }
                } catch (JodbIOException e) {
                    //should never happen
                    e.printStackTrace();
                }
            }
            Type type = Type.getType(field.getType());
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, declaringClassType.getInternalName(), field.getName(), type.getDescriptor());
            mv.visitInsn(returnOpcode);
            mv.visitEnd();
            Label l3 = new Label();
            mv.visitLabel(l3);
            //mv.visitLocalVariable("this", "Lcom/mobixess/jodb/tests/transformations/TestTrans;", null, l0, l3, 0);
View Full Code Here

        private void addVarAccessDelegators() throws ClassNotFoundException{
            Iterator<String> keys = _subjectAnalysisDataContainer._directFieldsAccess.keySet().iterator();
            ClassDescriptor subjectClassDescriptor = _subjectAnalysisDataContainer._predicateSubjectClassDescriptor;
            while (keys.hasNext()) {
                String nextVar = keys.next();
                Type owner = _subjectAnalysisDataContainer._directFieldsAccess.get(nextVar);
                ClassDescriptor ownerClassDescriptor = _subjectAnalysisDataContainer._session.getDescriptorForClass(owner.getClassName());
                if(!owner.getInternalName().equals(_internalClassName)){
                    continue;
                }
                String methodNameBase = "_synthAcc$$$"+nextVar;
                String methodName = methodNameBase;
                int counter = 0;
                while(subjectClassDescriptor.getMethodForName(methodName)!=null){
                    methodName = methodNameBase+counter;
                    counter++;
                }
               
                Field field = ownerClassDescriptor.getFieldForName(nextVar);
                Type returnType = Type.getType(field.getType());
                org.objectweb.asm.commons.Method method = new org.objectweb.asm.commons.Method(methodName,returnType,new Type[0]);
                MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, method.getDescriptor(), null, null);
                int fieldId = ownerClassDescriptor.getFieldIDForName(nextVar);
                writeVarInitCondition(mv, fieldId, nextVar, field.getType());
                writeReturn(mv, field);
View Full Code Here

                    case Opcodes.GETFIELD:
                        stackItem = _stack.get(_stack.size()-1);
                        if (_localPredicateSubjectVariables
                                .get(stackItem._localVarId))
                        {
                            Type type = Type.getObjectType(owner);
                            ClassDescriptor ownerDescriptor;
                            try {
                                ownerDescriptor = _predicateAnalysisDataContainer._session.getDescriptorForClass(type.getClassName());
                            } catch (ClassNotFoundException e) {
                                throw new RuntimeException(e);
                            }
                            Type ownerType = Type.getType(ownerDescriptor.getType());
                            Field field = ownerDescriptor.getFieldForName(name);
                            if(field==null){
                                _notEligible = true;
                                break;
                            }
                            Class fieldType = field.getType();
                            if(fieldType.isPrimitive() || fieldType == String.class){
                                _predicateAnalysisDataContainer._directFieldsAccess.put(name,ownerType);
                                int typeIndex = _predicateAnalysisDataContainer._predicateSubjectClassDescriptor.getHierarchyTypeIndex(ownerType.getClassName());
                                _predicateAnalysisDataContainer._lowestClassInHieratchyToModify = Math.min(typeIndex, _predicateAnalysisDataContainer._lowestClassInHieratchyToModify);
                            }else{
                                _notEligible = true;
                            }
                        }
View Full Code Here

                    } else {
                        //_predicateAnalysisDataContainer._fieldByMethodAccessMap.put(name, _methodDecriptor);
                        String methodId = composeReferringMethodId(_methodName, _methodDecriptor);
                        Integer accessField = _predicateAnalysisDataContainer._referringMethods.get(methodId);
                        if(accessField == null){
                            Type type = Type.getObjectType(owner);
                            ClassDescriptor ownerDescriptor;
                            try {
                                ownerDescriptor = _predicateAnalysisDataContainer._session.getDescriptorForClass(type.getClassName());
                            } catch (ClassNotFoundException e) {
                                throw new RuntimeException(e);
                            }
                            int id = ownerDescriptor.getFieldIDForName(name);
//                            Class realOwner = ownerDescriptor.getTopmostFieldOwner(name);
View Full Code Here

                    addLocal(owner);
                }
            }
            Type[] types = Type.getArgumentTypes(descriptor);
            for (int i = 0; i < types.length; ++i) {
                Type type = types[i];
                switch (type.getSort()) {
                    case Type.BOOLEAN:
                    case Type.CHAR:
                    case Type.BYTE:
                    case Type.SHORT:
                    case Type.INT:
View Full Code Here

TOP

Related Classes of org.objectweb.asm.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.