Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.Type


  private void createBridgeMethodForITDF(BcelClassWeaver weaver, LazyClassGen gen, ResolvedMember itdfieldSetter, ResolvedMember bridgingSetter) {
    InstructionFactory fact;
    LazyMethodGen bridgeMethod = makeMethodGen(gen,bridgingSetter)
    Type[] paramTypes = BcelWorld.makeBcelTypes(bridgingSetter.getParameterTypes());
      Type[] bridgingToParms = BcelWorld.makeBcelTypes(itdfieldSetter.getParameterTypes());
      Type returnType   = BcelWorld.makeBcelType(bridgingSetter.getReturnType());
      InstructionList body = bridgeMethod.getBody();
      fact = gen.getFactory();
      int pos = 0;

      if (!bridgingSetter.isStatic()) {
      body.append(InstructionFactory.createThis());
      pos++;
      }
      for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      if (!bridgingSetter.getParameterTypes()[i].getErasureSignature().equals(itdfieldSetter.getParameterTypes()[i].getErasureSignature()) ) {
        // une cast est required
        System.err.println("Putting in cast from "+paramType+" to "+bridgingToParms[i]);
        body.append(fact.createCast(paramType,bridgingToParms[i]));
      }
      pos+=paramType.getSize();
      }
    
      body.append(Utility.createInvoke(fact, weaver.getWorld(), itdfieldSetter));
      body.append(InstructionFactory.createReturn(returnType));
      gen.addMethodGen(bridgeMethod);
View Full Code Here


        whatToBridgeToMethodGen.getName(),
        whatToBridgeToMethodGen.getSignature());
    }
    LazyMethodGen bridgeMethod = makeBridgeMethod(clazz,theBridgeMethod); // The bridge method in this type will have the same signature as the one in the supertype
    bridgeMethod.setAccessFlags(bridgeMethod.getAccessFlags() | 0x00000040 /*BRIDGE    = 0x00000040*/ );
    Type returnType   = BcelWorld.makeBcelType(theBridgeMethod.getReturnType());
    Type[] paramTypes = BcelWorld.makeBcelTypes(theBridgeMethod.getParameterTypes());
    Type[] newParamTypes=whatToBridgeToMethodGen.getArgumentTypes();
    body = bridgeMethod.getBody();
    fact = clazz.getFactory();

    if (!whatToBridgeToMethodGen.isStatic()) {
       body.append(InstructionFactory.createThis());
       pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      if (!newParamTypes[i].equals(paramTypes[i])) {
        if (debug) System.err.println("Cast "+newParamTypes[i]+" from "+paramTypes[i]);
        body.append(fact.createCast(paramTypes[i],newParamTypes[i]));
      }
      pos+=paramType.getSize();
    }

    body.append(Utility.createInvoke(fact, world,whatToBridgeTo));
    body.append(InstructionFactory.createReturn(returnType));
    clazz.addMethodGen(bridgeMethod);
View Full Code Here

      frameEnv.put(donorFramePos, targetSlot);
      donorFramePos += 1;
    }
    Type[] argTypes = donor.getArgumentTypes();
    for (int i = 0, len = argTypes.length; i < len; i++) {
      Type argType = argTypes[i];
      int argSlot = recipient.allocateLocal(argType);
      ret.insert(InstructionFactory.createStore(argType, argSlot));
      frameEnv.put(donorFramePos, argSlot);
      donorFramePos += argType.getSize();
    }
    return ret;
  }
View Full Code Here

      }

      String sig  = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
           
      try{
        Type   t  = Type.getReturnType(sig);
        if ( name.equals(CONSTRUCTOR_NAME) && (t != Type.VOID) ){
          throw new ClassConstraintException("Instance initialization method must have VOID return type.");
        }
      }
      catch (ClassFormatError cfe){
View Full Code Here

      }

      String sig  = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
           
      try{
        Type   t  = Type.getReturnType(sig);
        if ( name.equals(STATIC_INITIALIZER_NAME) && (t != Type.VOID) ){
          addMessage("Class or interface initialization method '"+STATIC_INITIALIZER_NAME+"' usually has VOID return type instead of '"+t+"'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition.");
        }
      }
      catch (ClassFormatError cfe){
View Full Code Here

        locals[i] = ((UninitializedObjectType) locals[i]).getInitialized();
      }
    }
    if ((locals[i] instanceof ReferenceType) && (lv.locals[i] instanceof ReferenceType)){
      if (! locals[i].equals(lv.locals[i])){ // needed in case of two UninitializedObjectType instances
        Type sup = ((ReferenceType) locals[i]).getFirstCommonSuperclass((ReferenceType) (lv.locals[i]));

        if (sup != null){
          locals[i] = sup;
        }
        else{
View Full Code Here

  }

  public void visitMethod(Method method) {
    MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp);

    Type   result_type = mg.getReturnType();
    Type[] arg_types   = mg.getArgumentTypes();

    _out.println("    InstructionList il = new InstructionList();");
    _out.println("    MethodGen method = new MethodGen(" +
     printFlags(method.getAccessFlags()) +
View Full Code Here

  static String printType(Type type) {
    return printType(type.getSignature());
  }

  static String printType(String signature) {
    Type type = Type.getType(signature);
    byte t    = type.getType();

    if(t <= Constants.T_VOID) {
      return "Type." + Constants.TYPE_NAMES[t].toUpperCase();
    } else if(type.toString().equals("java.lang.String")) {
      return "Type.STRING";
    } 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()) +
View Full Code Here

      // A descriptor is often named signature in BCEL
      checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);

      String sig  = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Method's signature(=descriptor)

      Type t;
      Type[] ts; // needed below the try block.
      try{
        t  = Type.getReturnType(sig);
        ts = Type.getArgumentTypes(sig);
      }
      catch (ClassFormatError cfe){
        // Well, BCEL sometimes is a little harsh describing exceptional situations.
        throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by Method '"+tostring(obj)+"'.");
      }

      // Check if referenced objects exist.
      Type act = t;
      if (act instanceof ArrayType) act = ((ArrayType) act).getBasicType();
      if (act instanceof ObjectType){
        Verifier v = VerifierFactory.getVerifier( ((ObjectType) act).getClassName() );
        VerificationResult vr = v.doPass1();
        if (vr != VerificationResult.VR_OK) {
View Full Code Here

      Object pred = carrier.predecessor();
      if (pred instanceof Field){ //ConstantValue attributes are quite senseless if the predecessor is not a field.
        Field f = (Field) pred;
        // Field constraints have been checked before -- so we are safe using their type information.
        Type field_type = Type.getType(((ConstantUtf8) (cp.getConstant(f.getSignatureIndex()))).getBytes());

        int index = obj.getConstantValueIndex();
        if ((index < 0) || (index >= cplen)){
          throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(obj)+"'.");
        }
        Constant c = cp.getConstant(index);

        if (CONST_Long.isInstance(c) && field_type.equals(Type.LONG)){
          return;
        }
        if (CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT)){
          return;
        }
        if (CONST_Double.isInstance(c) && field_type.equals(Type.DOUBLE)){
          return;
        }
        if (CONST_Integer.isInstance(c) && (field_type.equals(Type.INT) || field_type.equals(Type.SHORT) || field_type.equals(Type.CHAR) || field_type.equals(Type.BYTE) || field_type.equals(Type.BOOLEAN))){
          return;
        }
        if (CONST_String.isInstance(c) && field_type.equals(Type.STRING)){
          return;
        }

        throw new ClassConstraintException("Illegal type of ConstantValue '"+obj+"' embedding Constant '"+c+"'. It is referenced by field '"+tostring(f)+"' expecting a different type: '"+field_type+"'.");
      }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.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.