Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.JavaClass


     */
    private void defineFields(ClassFile cf, ContainerElementBase contain)
        throws JiBXException {
       
        // process all non-final/non-static/non-transient fields of class
        JavaClass clas = cf.getRawClass();
        Field[] fields = clas.getFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            if (!field.isFinal() && !field.isStatic() && !field.isTransient()) {
               
                // find type of handling needed for field type
View Full Code Here


     * @param fname name of field supplying reference
     * @throws JiBXException on error in binding generation
     */
    private StructureElement createStructure(ClassFile cf, String fname)
        throws JiBXException {
        JavaClass clas = cf.getRawClass();
        if (m_verbose) {
            nestingIndent(System.out);
            System.out.println("creating nested structure definition for " +
                clas.getClassName());
        }
        String cname = clas.getClassName();
        for (int i = 0; i < m_structureStack.size(); i++) {
            if (cname.equals(m_structureStack.peek(i))) {
                StringBuffer buff =
                    new StringBuffer("Error: recursive use of ");
                buff.append(cname);
                buff.append(" requires <mapping>:\n ");
                while (i >= 0) {
                    buff.append(m_structureStack.peek(i--));
                    buff.append(" -> ");
                }
                buff.append(cname);
                throw new JiBXException(buff.toString());
            }
        }
        if (cname.startsWith("java.")) {
            nestingIndent(System.err);
            System.err.println("Warning: trying to create structure for " +
                cname);
        } else if (m_structureNames.contains(cname)) {
            nestingIndent(System.err);
            System.err.println("Warning: repeated usage of class " +
                cname + "; consider adding to mapping list");
        } else {
            m_structureNames.add(cname);
        }
        m_structureStack.push(cname);
        StructureElement element = new StructureElement();
        element.setFieldName(fname);
        element.setName(valueName(fname));
        defineStructure(cf, element);
        if (element.children().isEmpty()) {
            throw new JiBXException("No content found for class " + cname);
        }
        m_structureStack.pop();
        if (m_verbose) {
            nestingIndent(System.out);
            System.out.println("completed nested structure definition for " +
                clas.getClassName());
        }
        return element;
    }
View Full Code Here

     * @param abstr force abstract mapping flag
     * @throws JiBXException on error in binding generation
     */
    private MappingElementBase createMapping(ClassFile cf, boolean abstr)
        throws JiBXException {
        JavaClass clas = cf.getRawClass();
        if (m_verbose) {
            System.out.println("\nBuilding mapping definition for " +
                clas.getClassName());
        }
        MappingElementBase element = new MappingElement();
        element.setAbstract(abstr || clas.isAbstract() || clas.isInterface());
        String name = clas.getClassName();
        element.setClassName(name);
        if (abstr) {
            element.setAbstract(true);
        } else {
            element.setName((String)m_mappedNames.get(name));
View Full Code Here

            if (!org.jibx.runtime.Utility.isEqual(getPackage(),
                comp.getPackage()) || getSuperFile() != comp.getSuperFile() ||
                !Arrays.equals(getInterfaces(), comp.getInterfaces())) {
                return false;
            }
            JavaClass tjc = m_curClass;
            JavaClass cjc = comp.m_curClass;
            if (tjc.getAccessFlags() != cjc.getAccessFlags()) {
                return false;
            }
           
            // compare the defined fields
            Field[] tfields = tjc.getFields();
            Field[] cfields = cjc.getFields();
            if (tfields.length != cfields.length) {
                return false;
            }
            for (int i = 0; i < tfields.length; i++) {
                if (!equalFieldOrMethods(tfields[i], cfields[i])) {
                    return false;
                }
            }
           
            // compare the defined methods
            Method[] tmethods = tjc.getMethods();
            Method[] cmethods = cjc.getMethods();
            if (tmethods.length != cmethods.length) {
                return false;
            }
            for (int i = 0; i < tmethods.length; i++) {
                Method tmethod = tmethods[i];
                Method cmethod = cmethods[i];
                if (!equalFieldOrMethods(tmethod, cmethod) ||
                    !equalMethods(tmethod, cmethod)) {
                    return false;
                }
            }
       
            // finish with constant table values (correcting name and signature)
            Constant[] tcnsts = tjc.getConstantPool().getConstantPool();
            Constant[] ccnsts = cjc.getConstantPool().getConstantPool();
            if (tcnsts.length != ccnsts.length) {
                return false;
            }
            for (int i = tjc.getClassNameIndex()+1; i < tcnsts.length; i++) {
                Constant tcnst = tcnsts[i];
View Full Code Here

  /*
   * Test for JavaClass speedup(JavaClass)
   */
  public void testSpeedupJavaClass() throws IOException {
    //System.out.println(before);
    JavaClass beforeClass = getJavaClassForSource(getFilename(), getBefore());
    new Class2HTML(beforeClass, tempdir.getPath()+File.separator+"before"+File.separator);
    JavaClass afterClass = getJavaClassForSource(getFilename(), getAfter());
    new Class2HTML(afterClass, tempdir.getPath()+File.separator+"after"+File.separator);
    JavaClass justLogClass = Transform.speedup(beforeClass);
    new Class2HTML(justLogClass, tempdir.getPath()+File.separator+"modified"+File.separator);
    //assertNotSame(beforeClass.getBytes(),justLog.getBytes());
   
    //justLog.dump(new File(tempdir, "justlog.class"));
   
View Full Code Here

    InputStream in,
    String filename,
    OutputStream out)
    throws ClassFormatException, IOException {
    input.setInput(in);
    JavaClass source = (new ClassParser(input, filename)).parse();
    logger.info("Source size:" + source.getBytes().length);
    JavaClass target = Transform.speedup(source);
    logger.info("after optimization: " + target.getBytes().length);
    byte[] tmp = target.getBytes();
    out.write(tmp);
  }
View Full Code Here

  public static void doOnClassUnload( Class cls ) {
    if( null == classRepository )
      return;

    // Remove from class file repository.
    JavaClass bcelClass = classRepository.findClass( cls.getName() );
    if( null != bcelClass )
      classRepository.removeClass( bcelClass );
    // Notify HotSwapClassRegister
    //HotSwapClassRegister.getInstance().classUnloaded( cls ); 
  }
View Full Code Here

    if(scannedClasses.containsKey(cls))
      return;

    String className = cls.getName();
    // 0. Get the BCEL constant pool object
    JavaClass bcelClass = HotSwapAspectInterfaceImpl.getBCELClassDefinition( cls );
    ConstantPool constantPool = bcelClass.getConstantPool();
    Constant[] constants = constantPool.getConstantPool();

    // Remember the class, so it doesn't get scanned again.
    scannedConstantPools.put( cls, dummyValue );
View Full Code Here

    weave = false;

    String className = cls.getName();

    // 1. Get the BCEL JavaClass object for cls
    JavaClass bcelClass;
    bcelClass = HotSwapAspectInterfaceImpl.getBCELClassDefinition( cls );
    // The constant pool is common for all methods belonging to a class, so we store it
    // here to make it accessible to all RegisterMethodVisitors
    cpGen = new ConstantPoolGen( bcelClass.getConstantPool() );

    // 2. Scan each method defined in the class file
    org.apache.bcel.classfile.Method[] methods = bcelClass.getMethods();

    for( int j = 0; j < methods.length; j++ ) {
      org.apache.bcel.classfile.Method method = methods[j];
      if( (! method.isAbstract()) && (! method.isNative()) ) {
        MethodGen methodGen = new MethodGen( methods[j], className, cpGen );
View Full Code Here

    //System.out.println( "Verifying " + bcelClass.getClassName() );

    // Get classes 
    ClassParser cp = new ClassParser( new ByteArrayInputStream(originalCode), targetClass.getName().replace( '.', '/') );
    JavaClass originalClass;
    try {
      originalClass = cp.parse();
    }
    catch (java.io.IOException e) {
      throw new RuntimeException( e.getMessage() );
    }
    JavaClass newClass = clGen.getJavaClass();

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

    // Methods
    org.apache.bcel.classfile.Method oldMethods[] = originalClass.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[] = originalClass.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

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.