Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.JavaClass


   */
  private void verify() {
    if( null == clGen )
      throw new RuntimeException( "nothing to verify" );

    JavaClass jc = clGen.getJavaClass();
    Repository.addClass( jc );

    Verifier v = VerifierFactory.getVerifier( jc.getClassName() );
    checkVerificationResult(v.doPass1(), "1");
    checkVerificationResult(v.doPass2(), "2");
    MethodWeaver methodWeavers[] = new MethodWeaver[methods.size()];
    methods.values().toArray( methodWeavers );
    for( int i = 0; i < methods.size(); i++ ) {
View Full Code Here


  }

  public void test_020_RedefineClasses() {
    Class cl1=null, cl2=null;
    //   InputStream is1=null, is2=null;//, is3=null, is4=null;
    JavaClass jc1 = null, jc2 = null;

    // get classes
    try {
      cl1 = Class.forName( this.getClass().getName() + "$TestRedefineClasses1" );
      cl2 = Class.forName( this.getClass().getName() + "$TestRedefineClasses2" );
View Full Code Here

        // with the debugging implementation of prose).
      } catch(Exception e) { fail("wrong exception type"); }
      assertEquals( "exception test", 1, exceptionCount );

      Class thisClass = this.getClass();
      JavaClass jc = null;
      try{ jc = getBCELClassDefinition( this.getClass() ); }
      catch(ClassNotFoundException e) { fail("class not found"); }

      // class name
      assertEquals("different class name", thisClass.getName(), jc.getClassName() );

      // access flags. Note: the ACC_SUPER flag (0x020 or 32) may be set in class files
      // but newer VMs ignores it and wont return it, when quering the flags with the
      // reflection API.
      int accessMask = 0x0611// no ACC_SUPER flag, which is ignored by newer JVMs
      int jvmAccessFlags = thisClass.getModifiers();
      int bcelAccessFlags = jc.getModifiers();
      assertEquals("different modifier (access flags)", jvmAccessFlags & accessMask, bcelAccessFlags & accessMask );

      // methods
      java.lang.reflect.Method[] methods = thisClass.getDeclaredMethods();
      for( int i = 0; i < methods.length; i++ ) {
        java.lang.reflect.Method method = methods[i];
        assertNotNull("class file has no definition for " + method.getName(), jc.getMethod( method ) );
      }
    }
View Full Code Here

    String fileName = m.getDeclaringClass().getName().replace('.','/') + ".class";
    URL resource = cl.getResource(fileName);
    InputStream classStream = cl.getResourceAsStream(fileName);
    try  {
      ClassParser cparser=new ClassParser(classStream,fileName);
      JavaClass   parsedClass = cparser.parse();
      org.apache.bcel.classfile.Method[] methods = parsedClass.getMethods();
      org.apache.bcel.classfile.Method   javaMethod = null;
      for (int i = 0; i < methods.length && javaMethod == null; i++) {
        if (methods[i].getName().equals(m.getName()) &&
            JNIUtil.jniSignature(m).equals(methods[i].getSignature())) {
          javaMethod=methods[i];
View Full Code Here

      bcelClass = cp.parse();
    }
    catch (java.io.IOException e) {
      throw new RuntimeException( e.getMessage() );
    }
    JavaClass newClass = clGen.getJavaClass();

    // Check class name
    if( ! bcelClass.getClassName().equals( newClass.getClassName() ) ) {
      System.out.println( "Class name changed ( old: " + bcelClass.getClassName() + ", new: " + newClass.getClassName() + ")" );
      retval = false;
    }
    // Check class modifiers (access flags)
    if( bcelClass.getAccessFlags() != newClass.getAccessFlags() ) {
      System.out.println( "Class modifiers changed (old: " + bcelClass.getAccessFlags() + ", new: " + newClass.getAccessFlags() + ")" );
      retval = false;
    }

    // Methods
    org.apache.bcel.classfile.Method oldMethods[] = bcelClass.getMethods();
    org.apache.bcel.classfile.Method newMethods[] = newClass.getMethods();
    int oldMethodsLength = oldMethods.length;
    // number of methods
    if( oldMethodsLength != newMethods.length ) {
      System.out.println( "Number of methods changed (old: " + oldMethodsLength + ", new: " + newMethods.length + ")" );
      retval = false;
    }
    else {
      for( int i = 0; i < oldMethodsLength; i++ ) {
        org.apache.bcel.classfile.Method oldMeth = oldMethods[i];
        org.apache.bcel.classfile.Method newMeth = newMethods[i];

        // method name
        String oldMName = oldMeth.getName();
        if( ! oldMName.equals( newMeth.getName() ) ) {
          System.out.println( "Method name changed (old: " + oldMName + ", new: " + newMeth.getName() + ")" );
          retval = false;
        }
        // method modifiers
        if( oldMeth.getAccessFlags() != newMeth.getAccessFlags() ) {
          System.out.println( "Method modifiers changed for" + oldMName );
          retval = false;
        }
        // signature
        if( ! oldMeth.getSignature().equals( newMeth.getSignature() ) ) {
          System.out.println( "Method signature changed for " + oldMName );
          retval = false;
        }
      }
    }

    // Check for JVMDI_ERROR_SCHEMA_CHANGE... (Fields)
    org.apache.bcel.classfile.Field newFields[] = newClass.getFields();
    org.apache.bcel.classfile.Field oldFields[] = bcelClass.getFields();
    int newFieldsLength = newFields.length;
    if( newFieldsLength != oldFields.length ) {
      System.out.println( "Number of fields changed (old " + oldFields.length + ", new " + newFieldsLength + ")" );
      retval = false;
View Full Code Here

   */
  private void verify() {
    if( null == clGen )
      throw new RuntimeException( "nothing to verify" );

    JavaClass jc = clGen.getJavaClass();
    Repository.addClass( jc );

    Verifier v = VerifierFactory.getVerifier( jc.getClassName() );
    checkVerificationResult(v.doPass1(), "1");
    checkVerificationResult(v.doPass2(), "2");
    MethodWeaver methodWeavers[] = new MethodWeaver[methods.size()];
    methods.values().toArray( methodWeavers );
    for( int i = 0; i < methods.size(); i++ ) {
View Full Code Here

                    if (stripped != null)
                        cg.replaceMethod(methods[i], stripped);
                }
            }
            trans.done();
            JavaClass target = cg.getJavaClass();
            target.setFileName(source.getFileName());
            return target;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return source;
View Full Code Here

        }
        return ret;
    }

    static void nullBCELAdapt(final byte[] b) throws IOException {
        JavaClass jc = new ClassParser(new ByteArrayInputStream(b),
                "class-name").parse();
        ClassGen cg = new ClassGen(jc);
        ConstantPoolGen cp = cg.getConstantPool();
        Method[] ms = cg.getMethods();
        for (int k = 0; k < ms.length; ++k) {
View Full Code Here

  Enumeration classes = _bcelClasses.elements();
  final String now = (new Date()).toString();
  final java.util.jar.Attributes.Name dateAttr =
      new java.util.jar.Attributes.Name("Date");
  while (classes.hasMoreElements()) {
      final JavaClass clazz = (JavaClass)classes.nextElement();
      final String className = clazz.getClassName().replace('.','/');
      final java.util.jar.Attributes attr = new java.util.jar.Attributes();
      attr.put(dateAttr, now);
      map.put(className+".class", attr);
  }

  final File jarFile = new File(_destDir, _jarFileName);
  final JarOutputStream jos =
      new JarOutputStream(new FileOutputStream(jarFile), manifest);
  classes = _bcelClasses.elements();
  while (classes.hasMoreElements()) {
      final JavaClass clazz = (JavaClass)classes.nextElement();
      final String className = clazz.getClassName().replace('.','/');
      jos.putNextEntry(new JarEntry(className+".class"));
      final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
      clazz.dump(out); // dump() closes it's output stream
      out.writeTo(jos);
  }
  jos.close();
    }
View Full Code Here

        //
        for (int i = 0; i < superMethodRefs.length; i++) {
            generateSuperMethod(newStubClass, superMethodRefs[i]);
        }

        JavaClass javaClass = newStubClass.getJavaClass();
        byte[] classData = javaClass.getBytes();

        try {
            if (Boolean.getBoolean("org.apache.yoko.rmi.util.stub.debug")) {
                java.io.File out = new java.io.File(className + ".class");
                // System.out.println ("dumping to file "+out);
                javaClass.dump(out);
            }
        } catch (java.io.IOException ex) {
            logger.log(Level.WARNING, "", ex);
        }
View Full Code Here

TOP

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

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.