Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.Type


                    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
                    TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
                    if (!typeFrame.isValid()) {
                        continue;
                    }
                    Type instanceType = typeFrame.getInstance(handle.getInstruction(), cpg);
                    if (instanceType instanceof TopType) {
                        if (DEBUG) {
                            System.out.println("Freaky: typeFrame is " + typeFrame);
                        }
                        continue;
View Full Code Here


      JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
      Field[] fields = jc.getFields();
      Field f = null;
      for (int i=0; i<fields.length; i++){
        if (fields[i].getName().equals(field_name)){
          Type f_type = Type.getType(fields[i].getSignature());
          Type o_type = o.getType(cpg);
          /* TODO: Check if assignment compatibility is sufficient.
           * What does Sun do?
           */
          if (f_type.equals(o_type)){
            f = fields[i];
            break;
          }
        }
      }
      if (f == null){
        JavaClass[] superclasses = jc.getSuperClasses();
        outer:
        for (int j=0; j<superclasses.length; j++){
          fields = superclasses[j].getFields();
          for (int i=0; i<fields.length; i++){
            if (fields[i].getName().equals(field_name)){
              Type f_type = Type.getType(fields[i].getSignature());
              Type o_type = o.getType(cpg);
              if (f_type.equals(o_type)){
                f = fields[i];
                if ((f.getAccessFlags() & (Constants.ACC_PUBLIC | Constants.ACC_PROTECTED)) == 0) {
                                    f = null;
                                }
                break outer;
              }
            }
          }
        }
        if (f == null) {
                    constraintViolated(o, "Referenced field '"+field_name+"' does not exist in class '"+jc.getClassName()+"'.");
                }
      }
      else{
        /* TODO: Check if assignment compatibility is sufficient.
           What does Sun do? */
        Type f_type = Type.getType(f.getSignature());
        Type o_type = o.getType(cpg);
               
        // Argh. Sun's implementation allows us to have multiple fields of
        // the same name but with a different signature.
        //if (! f_type.equals(o_type)){
        //  constraintViolated(o, "Referenced field '"+field_name+"' has type '"+f_type+"' instead of '"+o_type+"' as expected.");
View Full Code Here

        }
      }
   
      // The LoadClassType is the method-declaring class, so we have to check the other types.
     
      Type t = o.getReturnType(cpg);
      if (t instanceof ArrayType){
        t = ((ArrayType) t).getBasicType();
      }
      if (t instanceof ObjectType){
        Verifier v = VerifierFactory.getVerifier(((ObjectType) t).getClassName());
View Full Code Here

      if ((c instanceof ConstantClass)){
        constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
      }
      else{
        ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant( ((ConstantClass) c).getNameIndex() ));
        Type t = Type.getType("L"+cutf8.getBytes()+";");
        if (t instanceof ArrayType){
          constraintViolated(o, "NEW must not be used to create an array.");
        }
      }
     
View Full Code Here

      }
      int dimensions2create = o.getDimensions();
      if (dimensions2create < 1){
        constraintViolated(o, "Number of dimensions to create must be greater than zero.");
      }
      Type t = o.getType(cpg);
      if (t instanceof ArrayType){
        int dimensions = ((ArrayType) t).getDimensions();
        if (dimensions < dimensions2create){
          constraintViolated(o, "Not allowed to create array with more dimensions ('+dimensions2create+') than the one referenced by the CONSTANT_Class '"+t+"'.");
        }
View Full Code Here

      indexValid(o, o.getIndex());
      Constant c = cpg.getConstant(o.getIndex());
      if ((c instanceof ConstantClass)){
        constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
      }
      Type t = o.getType(cpg);
      if (t instanceof ArrayType){
        int dimensions = ((ArrayType) t).getDimensions();
        if (dimensions >= 255){
          constraintViolated(o, "Not allowed to create an array with more than 255 dimensions.");
        }
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(), FLAG_FOR_METHOD) + ", "
                + printType(result_type) + ", " + printArgumentTypes(arg_types) + ", "
View Full Code Here

        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(Locale.ENGLISH);
        } 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()) + ", " + at.getDimensions()
                    + ")";
View Full Code Here

    }


    public void visitLocalVariableInstruction( LocalVariableInstruction i ) {
        short opcode = i.getOpcode();
        Type type = i.getType(_cp);
        if (opcode == Constants.IINC) {
            _out.println("il.append(new IINC(" + i.getIndex() + ", " + ((IINC) i).getIncrement()
                    + "));");
        } else {
            String kind = (opcode < Constants.ISTORE) ? "Load" : "Store";
View Full Code Here

    }


    public void visitArrayInstruction( ArrayInstruction i ) {
        short opcode = i.getOpcode();
        Type type = i.getType(_cp);
        String kind = (opcode < Constants.IASTORE) ? "Load" : "Store";
        _out.println("il.append(_factory.createArray" + kind + "(" + BCELifier.printType(type)
                + "));");
    }
View Full Code Here

TOP

Related Classes of org.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.