Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantPool


                    boolean implicitNullCheckForEquals = false;
                    if (directTypeQualifierAnnotation == null && method.getName().equals("equals")
                            && method.getSignature().equals("(Ljava/lang/Object;)Z") && !method.isStatic()) {
                        implicitNullCheckForEquals = true;
                        Code code = method.getCode();
                        ConstantPool cp = jclass.getConstantPool();
                        byte codeBytes[] = code.getCode();
                        for (CodeException e : code.getExceptionTable()) {
                            ConstantClass cl = (ConstantClass) cp.getConstant(e.getCatchType());
                            int endPC = e.getEndPC();
                            int startPC = e.getStartPC();
                            int handlerPC = e.getHandlerPC();
                            if (startPC == 0 && endPC + 1 == handlerPC && handlerPC == codeBytes.length - 3
                                    && (codeBytes[handlerPC + 1] & 0xff) == Constants.ICONST_0
View Full Code Here


   * and add them to the dependents list if they are not in allClasses
   */
  void addDependents( JavaClass clazz ) throws IOException {
    String name = clazz.getClassName().replace('.', '/');
    allClasses.put( name , clazz );
    ConstantPool pool = clazz.getConstantPool();
    for( int i = 1 ; i < pool.getLength() ; i++){
      Constant cons =  pool.getConstant(i);
      //System.out.println("("+i+") " + cons );
      if( cons!=null && cons.getTag() == Constants.CONSTANT_Class ){
  int idx = ((ConstantClass)pool.getConstant(i)).getNameIndex();
  String clas = ((ConstantUtf8)pool.getConstant(idx)).getBytes();
  addClassString(clas,name);
      }
    }
  }
View Full Code Here

        boolean caught = true;

        Set<Location> dereferenceSites
        = entryFact.getDerefLocationSet(paramVN);
        if (dereferenceSites != null && !dereferenceSites.isEmpty()) {
            ConstantPool cp = classContext.getJavaClass().getConstantPool();

            for(Location loc : dereferenceSites) {
                if (!FindNullDeref.catchesNull(cp, method.getCode(), loc)) {
                    caught = false;
                }
View Full Code Here

  public static void main(String[] argv) {
    try {
      for(int i=0; i < argv.length; i++) {
  if(argv[i].endsWith(".class")) {
          JavaClass       java_class = new ClassParser(argv[i]).parse();
    ConstantPool    constants  = java_class.getConstantPool();
          String          file_name  = argv[i].substring(0, argv[i].length() - 6) +
      "_hello.class";
    cp = new ConstantPoolGen(constants);

    helloifyClassName(java_class);
View Full Code Here

        int[] interfaces = getInterfaces();
        Field[] fields = getFields();
        Method[] methods = getMethods();
        Attribute[] attributes = getAttributes();
        // Must be last since the above calls may still add something to it
        ConstantPool _cp = this.cp.getFinalConstantPool();
        return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor,
                access_flags, _cp, interfaces, fields, methods, attributes);
    }
View Full Code Here

                addUsedClasses(usingClass, decodeSignature(method.getReturnType().getSignature()));
            }
        }

        private void analyzeConstantPool(String usingClass, JavaClass javaClass) {
            final ConstantPool constantPool = javaClass.getConstantPool();
            for (Constant constant : constantPool.getConstantPool()) {
                if (constant instanceof ConstantClass) {
                    String signature = ((ConstantClass) constant).getBytes(constantPool);
                    if (signature != null) {
                        if (signature.startsWith("[")) {
                            signature = decodeTypeName(signature);
View Full Code Here

  }

  /** @return type related with this instruction.
   */
  public Type getType(ConstantPoolGen cpg) {
    ConstantPool cp   = cpg.getConstantPool();
    String       name = cp.getConstantString(index, org.apache.bcel.Constants.CONSTANT_Class);

    if(!name.startsWith("["))
      name = "L" + name + ";";

    return Type.getType(name);
View Full Code Here

      // we determine the dependencies by looking at class references
      // from in the constant pool, method args (and return type), and
      // class fields

      // first look at the constant pool
      ConstantPool oConstantPool = _oJavaClass.getConstantPool();
      for ( int i = 0; i < oConstantPool.getLength(); i++ )
      {
         Constant oConstant = oConstantPool.getConstant( i );

         if ( oConstant instanceof ConstantClass )
         {
            ConstantUtf8 oConstantUtf8
               =  ( ConstantUtf8 )
                     oConstantPool
                        .getConstant( ( ( ConstantClass ) oConstant ).getNameIndex() );

            String sReferencedClassname = oConstantUtf8.getBytes().replace( '/', '.' );

            // only consider the class if it is not an array, since classloaders do not
View Full Code Here

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return rval;
        }

        ConstantPool constantPool = lookupClass.getConstantPool();

        int length = constantPool.getLength();
        for (int i = 0; i < length; i++) {
            Constant constant = constantPool.getConstant(i);
            if (constant instanceof ConstantClass) {
                ConstantClass cc = (ConstantClass) constant;
                ConstantUtf8 constant2 = (ConstantUtf8) constantPool.getConstant(cc.getNameIndex());

                // In case a subclass fails, skip, but print warning.
                try {
                    String toLoad = constant2.getBytes().replace('/', '.');
                    if (toLoad.contains("[")) continue;
View Full Code Here

            className = javaClass.getClassName();
           
            if(!d.needEvalCurrentClass(className))
                return;
   
            ConstantPool pool = javaClass.getConstantPool();
            processConstantPool(pool);
            VisitorImpl visitor = new VisitorImpl(pool, this, d, task.getLocation());
            DescendingVisitor desc = new DescendingVisitor(javaClass, visitor);
            desc.visit();
        } catch(BuildException e) {
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.ConstantPool

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.