Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.ArrayType


            return IncompatibleTypes.SEEMS_OK;
        }

        // -~- Array Types: compare dimensions, then base type
        if (expectedCat == TypeCategory.ARRAY_TYPE && argCat == TypeCategory.ARRAY_TYPE) {
            ArrayType parmArray = (ArrayType) expectedType;
            ArrayType argArray = (ArrayType) actualType;

            if (parmArray.getDimensions() != argArray.getDimensions()) {
                return IncompatibleTypes.ARRAY_AND_NON_ARRAY;
            }

            return compareTypes(parmArray.getBasicType(), argArray.getBasicType(), ignoreBaseType);
        }
        // If one is an Array Type and the other is not, then they
        // are incompatible. (We already know neither is java.lang.Object)
        if (expectedCat == TypeCategory.ARRAY_TYPE ^ argCat == TypeCategory.ARRAY_TYPE) {
            return IncompatibleTypes.ARRAY_AND_NON_ARRAY;
View Full Code Here


        } else if (type.toString().equals("java.lang.Object")) {
            return "Type.OBJECT";
        } else if (type.toString().equals("java.lang.StringBuffer")) {
            return "Type.STRINGBUFFER";
        } else if (type instanceof ArrayType) {
            ArrayType at = (ArrayType) type;
            return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions()
                    + ")";
        } else {
            return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")";
        }
    }
View Full Code Here

        typeComparable = ObjectTypeFactory.getInstance("java.lang.Comparable");

        typeList = ObjectTypeFactory.getInstance("java.util.List");
        typeCollection = ObjectTypeFactory.getInstance("java.util.Collection");
        typeHashSet = ObjectTypeFactory.getInstance("java.util.HashSet");
        typeArrayClonable = new ArrayType(typeClonable, 1);
        typeArrayComparable = new ArrayType(typeComparable, 1);
        typeArrayObject = new ArrayType(typeObject, 1);
        typeArrayInteger = new ArrayType(typeInteger, 1);
        typeArrayString = new ArrayType(typeString, 1);
        typeArrayArrayObject = new ArrayType(typeObject, 2);
        typeArrayArraySerializable = new ArrayType(typeSerializable, 2);
        typeArrayArrayString = new ArrayType(typeString, 2);
        typeArrayInt = new ArrayType(Type.INT, 1);
        typeArrayArrayInt = new ArrayType(Type.INT, 2);
        typeArrayArrayArrayInt = new ArrayType(Type.INT, 3);
        typeArrayChar = new ArrayType(Type.CHAR, 1);
        typeArrayArrayChar = new ArrayType(Type.CHAR, 2);
        typeArrayArrayArrayChar = new ArrayType(Type.CHAR, 3);
        typeDynamicString = new FindRefComparison.DynamicStringType();
        typeStaticString = new FindRefComparison.StaticStringType();
        typeParameterString = new FindRefComparison.ParameterStringType();
    }
View Full Code Here

    InstructionList il = new InstructionList();
    MethodGen       mg = new MethodGen(Constants.ACC_STATIC |
               Constants.ACC_PUBLIC,// access flags
               Type.VOID,              // return type
               new Type[] {            // argument types
           new ArrayType(Type.STRING, 1)
               },
               new String[] { "argv" }, // arg names
               "main", "HelloWorld",    // method, class
               il, cp);
    InstructionFactory factory = new InstructionFactory(cg);
View Full Code Here

    boolean main=false, ignore=false;
    String class_name = class_gen.getClassName();
    String fname      = name.getName();
    InstructionList il = new InstructionList();

    Type[] args = { new ArrayType(Type.STRING, 1) }; // default for `main'
    String[] arg_names = { "$argv" };

    if(fname.equals("main")) {
      method = new MethodGen(ACC_STATIC | ACC_PUBLIC,
           Type.VOID, args, arg_names,
View Full Code Here

   private static org.apache.bcel.classfile.Method createInvokeImpl(MBeanMetaData metadata, ClassGen classGen, String clsName)
   {
      InstructionList implementation = new InstructionList();

      ObjectType metadataType = new ObjectType(MBeanMetaData.class.getName());
      Type[] signature = new Type[]{metadataType, Type.STRING, new ArrayType(Type.STRING, 1), new ArrayType(Type.OBJECT, 1)};

      // Method definition
      MethodGen mthd = new MethodGen(Constants.ACC_PROTECTED, // Modifiers
                                     Type.OBJECT, // Return type
                                     signature, // Signature
                                     new String[]{"metadata", "method", "params", "args"}, // Parameter names
                                     "invokeImpl", // Method name
                                     clsName, // Class name
                                     implementation, // Implementation
                                     classGen.getConstantPool()); // Pool
      mthd.addException("java.lang.Throwable");

      // Now I should create the implementation
      InstructionFactory factory = new InstructionFactory(classGen);

      Method[] methods = metadata.getMBeanInterface().getMethods();
      List tests = new ArrayList();
      List catches = new ArrayList();
      for (int i = 0; i < methods.length; ++i)
      {
         Method method = methods[i];
         catches.addAll(generateDirectInvokeBranch(classGen, mthd, implementation, factory, metadata.getMBeanInterface().getName(), method, tests));
      }

      // To close the last branch, I must jump to super.invokeImpl(), so I need its first instruction here
      InstructionHandle invokeSuper = implementation.append(factory.createThis());
      for (int i = 0; i < tests.size(); ++i)
      {
         BranchInstruction branch = (BranchInstruction)tests.get(i);
         branch.setTarget(invokeSuper);
      }
      tests.clear();
      for (int i = 0; i < catches.size(); ++i)
      {
         BranchInstruction branch = (BranchInstruction)catches.get(i);
         branch.setTarget(invokeSuper);
      }
      catches.clear();

      //
      // return super.invokeImpl(metadata, method, params, args);
      //
      // Again, it's invokeImpl(super, args) instead of super.invokeImpl(args)
      // Use 'this' as first argument, and invokespecial instead of invokevirtual to call super
      // 'this' is created above, to close the last branch
      implementation.append(factory.createLoad(metadataType, 1));
      implementation.append(factory.createLoad(Type.STRING, 2));
      implementation.append(factory.createLoad(new ArrayType(Type.STRING, 1), 3));
      implementation.append(factory.createLoad(new ArrayType(Type.OBJECT, 1), 4));
      implementation.append(factory.createInvoke(BCELMBeanInvoker.class.getName(), "invokeImpl", Type.OBJECT, signature, Constants.INVOKESPECIAL));
      implementation.append(factory.createReturn(Type.OBJECT));

      mthd.setMaxStack();
View Full Code Here

      // IFEQ compares the stack with 0, which means "if the previous comparison is false, ..."
      BranchInstruction test1 = factory.createBranchInstruction(Constants.IFEQ, null);
      tests.add(test1);
      implementation.append(test1);

      implementation.append(factory.createLoad(new ArrayType(Type.OBJECT, 1), 4));
      implementation.append(new ARRAYLENGTH());
      implementation.append(new PUSH(classGen.getConstantPool(), method.getParameterTypes().length));
      // Here I should test if args.length == <num>, if not equal then go to the next branch
      // Create branch instructions with no offset, since it cannot be handled now, see above
      BranchInstruction test2 = factory.createBranchInstruction(Constants.IF_ICMPNE, null);
      tests.add(test2);
      implementation.append(test2);

      // Here I am on the right method, unless someone created 2 methods with same names and same number of
      // parameters but of different type. In this last case if we're lucky it's the right method and we go
      // via direct call, otherwise we will have a class cast exception and go via reflection

      // Cast and invoke
      // Put the metadata on the stack, to access its 'mbean' field, that will be put on the stack
      // It's also the start of the try block
      InstructionHandle tryStart = implementation.append(factory.createLoad(new ObjectType(MBeanMetaData.class.getName()), 1));
      implementation.append(factory.createInvoke(MBeanMetaData.class.getName(), "getMBean", Type.OBJECT, new Type[0], Constants.INVOKEVIRTUAL));
      // Cast the 'mbean' field to the proper type, the stack will contain the casted mbean
      implementation.append(factory.createCheckCast(new ObjectType(management)));

      // Now add all the arguments to the stack
      Class[] signature = method.getParameterTypes();
      Type[] invokeSignature = new Type[signature.length];
      for (int i = 0; i < signature.length; ++i)
      {
         Class param = signature[i];

         // Load all args on the stack
         implementation.append(factory.createLoad(new ArrayType(Type.OBJECT, 1), 4));
         // I want index 'i'
         implementation.append(new PUSH(classGen.getConstantPool(), i));
         // Now on the stack there is args[i]
         implementation.append(factory.createArrayLoad(Type.OBJECT));
View Full Code Here

         {
            ++dimensions;
            cls = c;
         }
         Type t = convertClassToType(cls);
         return new ArrayType(t, dimensions);
      }
      return new ObjectType(cls.getName());
   }
View Full Code Here

            // Detachable fields
            fieldsToAdd.add(new ClassField(this, FN_JdoDetachedState, Constants.ACC_PROTECTED, OT_ObjectArray));
        }

        fieldsToAdd.add(new ClassField(this, FN_FieldFlags, Constants.ACC_PRIVATE | Constants.ACC_STATIC | Constants.ACC_FINAL,
                new ArrayType(Type.BYTE, 1)));
        fieldsToAdd.add(new ClassField(this, FN_PersistenceCapableSuperclass,
                Constants.ACC_PRIVATE | Constants.ACC_STATIC | Constants.ACC_FINAL, OT_CLASS));
        fieldsToAdd.add(new ClassField(this, FN_FieldTypes, Constants.ACC_PRIVATE | Constants.ACC_STATIC | Constants.ACC_FINAL,
                new ArrayType(Class.class.getName(), 1)));
        fieldsToAdd.add(new ClassField(this, FN_FieldNames, Constants.ACC_PRIVATE | Constants.ACC_STATIC | Constants.ACC_FINAL,
                new ArrayType(Type.STRING, 1)));
        fieldsToAdd.add(new ClassField(this, FN_JdoInheritedFieldCount, Constants.ACC_PRIVATE | Constants.ACC_STATIC | Constants.ACC_FINAL,
                Type.INT));

        try
        {
View Full Code Here

            int svUidIndex = constantPoolGen.addLong(addSerialVersionUID);
            il.append(new LDC2_W(svUidIndex));
            il.append(factory.createPutStatic(className, FN_serialVersionUID, Type.LONG));
        }
        // field init MN_jdoFieldNamesInit
        il.append(factory.createInvoke(className, MN_FieldNamesInitMethod, new ArrayType(Type.STRING, 1), Type.NO_ARGS,
            Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_FieldNames, new ArrayType(Type.STRING, 1)));

        // field init MN_jdoFieldTypesInit
        il.append(factory.createInvoke(className, MN_FieldTypesInitMethod, new ArrayType(OT_CLASS, 1), Type.NO_ARGS, Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_FieldTypes, new ArrayType(OT_CLASS, 1)));

        // field init MN_FieldFlagsInitMethod
        il.append(factory.createInvoke(className, MN_FieldFlagsInitMethod, new ArrayType(Type.BYTE, 1), Type.NO_ARGS,
            Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_FieldFlags, new ArrayType(Type.BYTE, 1)));

        // field init MN_JdoFieldCounInitMethod
        il.append(factory.createInvoke(className, MN_JdoGetInheritedFieldCount, Type.INT, Type.NO_ARGS, Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_JdoInheritedFieldCount, Type.INT));

        // ___jdo$PersistenceCapableSuperclass =
        // ___jdo$PersistenceCapableSuperclassInit();
        il.append(factory.createInvoke(className, MN_JdoPersistenceCapableSuperclassInit, OT_CLASS, Type.NO_ARGS, Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_PersistenceCapableSuperclass, OT_CLASS));

        // class init
        /*
         * JDOImplHelper.registerClass( ___jdo$loadClass("fullclassname"),
         * ___jdo$fieldNames, ___jdo$fieldTypes, ___jdo$FieldFlags,
         * ___jdo$PersistenceCapableSuperclass, new ClassConstrutor());
         */
        il.append(new LDC(constantPoolGen.addString(className)));
        il.append(factory.createInvoke(className, MN_jdoLoadClass, OT_CLASS, new Type[]{Type.STRING}, Constants.INVOKESTATIC));
        il.append(factory.createGetStatic(className, FN_FieldNames, new ArrayType(Type.STRING, 1)));
        il.append(factory.createGetStatic(className, FN_FieldTypes, new ArrayType(OT_CLASS, 1)));
        il.append(factory.createGetStatic(className, FN_FieldFlags, new ArrayType(Type.BYTE, 1)));
        il.append(factory.createGetStatic(className, FN_PersistenceCapableSuperclass, OT_CLASS));

        if (((BCELClassMetaData) cmd).getClassGen().isAbstract())
        {
            // null
            il.append(InstructionConstants.ACONST_NULL);
        }
        else
        {
            // new ClassConstrutor()
            il.append(factory.createNew(new ObjectType(className)));
            il.append(InstructionConstants.DUP);
            il.append(factory.createInvoke(className, Constants.CONSTRUCTOR_NAME, Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
        }
        il.append(factory.createInvoke(CN_JDOImplHelper, "registerClass", Type.VOID, new Type[]{OT_CLASS, new ArrayType(Type.STRING, 1),
                new ArrayType(OT_CLASS, 1), new ArrayType(Type.BYTE, 1), OT_CLASS, OT_PersistenceCapable}, Constants.INVOKESTATIC));

        staticInitializerAppend(factory, il);
        il.append(InstructionConstants.RETURN);

        // newClass.addMethod(method);
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.ArrayType

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.