commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bali...@apache.org
Subject cvs commit: jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools Enhancer.java
Date Mon, 04 Mar 2002 22:51:16 GMT
baliuka     02/03/04 14:51:16

  Modified:    simplestore/src/java/org/apache/commons/simplestore/tools
                        Enhancer.java
  Log:
  bug fixes for Enhancer
  
  Revision  Changes    Path
  1.8       +34 -56    jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java
  
  Index: Enhancer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Enhancer.java	4 Mar 2002 22:11:40 -0000	1.7
  +++ Enhancer.java	4 Mar 2002 22:51:16 -0000	1.8
  @@ -63,7 +63,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: Enhancer.java,v 1.7 2002/03/04 22:11:40 baliuka Exp $
  + *@version    $Id: Enhancer.java,v 1.8 2002/03/04 22:51:16 baliuka Exp $
    */
   public class Enhancer implements org.apache.bcel.Constants{
       
  @@ -140,7 +140,6 @@
               result = (Class)m.invoke(loader,new Object[]{clazz.getClassName(),b,new Integer(0),new
Integer(b.length)});
               m.setAccessible(flag);
               
  -            
               for( java.util.Iterator i =  methods.keySet().iterator(); i.hasNext();  ){
                   String name = (String)i.next();
                   result.getField( name ).set(null,methods.get(name));
  @@ -150,14 +149,9 @@
           }
           return result.getConstructor(new Class[]{ MethodInterceptor.class} ).
           newInstance(new Object[]{ih});
  -        
  -        
  -        
       }
       
       
  -    
  -    
       private static void addConstructor(ClassGen  cg ){
           
           String parentClass = cg.getSuperclassName();
  @@ -172,7 +166,6 @@
           }, null, // arg names
           CONSTRUCTOR_NAME, cg.getClassName(), il, cp);
           
  -        
           il.append( new ALOAD(0));
           il.append( factory.createInvoke(parentClass,CONSTRUCTOR_NAME,Type.VOID ,new Type[]{},
INVOKESPECIAL ));
           il.append( new ALOAD(0));
  @@ -192,10 +185,17 @@
           
       }
       
  -    private static ClassGen getClassGen( String class_name, Class  parentClass){
  +    private static ClassGen getClassGen( String class_name, Class  parentClass,Class []
interfaces){
           
  -        return new ClassGen( class_name , parentClass.getName(),
  +        ClassGen gen = new ClassGen( class_name , parentClass.getName(),
           SOURCE_FILE, ACC_PUBLIC , null );
  +        if( interfaces != null ){
  +            for(int i = 0; i< interfaces.length; i++ ){
  +                gen.addInterface(interfaces[i].getName());
  +            }
  +        }
  +        
  +        return gen;
       }
       
       private static JavaClass enhance( Class parentClass,Class interfaces [],java.util.HashMap
methodTable )  {
  @@ -203,8 +203,8 @@
           String class_name = parentClass.getName() + ENHAVCED_CLASS_SUFIX;
           if(class_name.startsWith("java")){
               class_name =  ENHAVCED_CLASS_PREFIX + class_name;
  -        }  
  -        ClassGen  cg = getClassGen(class_name,parentClass);
  +        }
  +        ClassGen  cg = getClassGen(class_name,parentClass,interfaces);
           ConstantPoolGen cp = cg.getConstantPool(); // cg creates constant pool
           addHandlerField(cg);
           addConstructor(cg);
  @@ -213,7 +213,7 @@
           int invokeSuper  = addInvokeSupperRef(cp);
           java.util.Set methodSet = new java.util.HashSet();
           
  -        for(int j = 0; j <= (interfaces == null ? 0 : interfaces.length); j++   ) {
  +        for(int j = (interfaces == null ? 0 : interfaces.length); j == 0 ; j--  ) {
               java.lang.reflect.Method  methods[];
               if( j == 0 ){
                   methods = parentClass.getMethods();
  @@ -222,10 +222,10 @@
               }
               for( int i = 0 ; i < methods.length; i++ ){
                   int mod = methods[i].getModifiers();
  -                if( !java.lang.reflect.Modifier.isStatic(mod) && 
  -                    !java.lang.reflect.Modifier.isFinal(mod) &&
  -                   ( java.lang.reflect.Modifier.isPublic(mod)|| 
  -                     java.lang.reflect.Modifier.isProtected(mod)) ){
  +                if( !java.lang.reflect.Modifier.isStatic(mod) &&
  +                !java.lang.reflect.Modifier.isFinal(mod) &&
  +                ( java.lang.reflect.Modifier.isPublic(mod)||
  +                java.lang.reflect.Modifier.isProtected(mod)) ){
                       methodSet.add(methods[i]);
                       
                   }
  @@ -238,16 +238,13 @@
               cg.addMethod( generateMethod( method,fieldName,cg, before,after,invokeSuper
) );
               methodTable.put(fieldName,method);
           }
  -        
  -        
  -        
           JavaClass jcl = cg.getJavaClass();
           return  jcl;
  -        
       }
       
       
       private static void addMethodField(String fieldName, ClassGen cg ){
  +        
           ConstantPoolGen cp = cg.getConstantPool();
           FieldGen fg = new FieldGen( ACC_PUBLIC | ACC_STATIC  , METHOD_OBJECT , fieldName
, cp);
           cg.addField(fg.getField());
  @@ -255,6 +252,7 @@
       }
       
       private static int createArgArray(InstructionList    il, InstructionFactory factory,
ConstantPoolGen cp, Type[] args ){
  +        
           int argCount = args.length;
           if( argCount > 5 )
               il.append( new  BIPUSH((byte)argCount) );
  @@ -312,11 +310,7 @@
                       il.append( new INVOKESPECIAL(cp.addMethodref(Float.class.getName(),CONSTRUCTOR_NAME,
"(F)V")) );
                   }
                   
  -                
  -                
  -                
                   il.append( new AASTORE() );
  -                //  il.append( new DUP() );
                   
               }else{
                   il.append( new ALOAD( load++ ) );
  @@ -341,8 +335,8 @@
           il.append( new ASTORE( stack  ) );
           il.append( new ALOAD( stack  ) );
           if( returnType instanceof ObjectType ) {
  -             if(!returnType.equals(Type.OBJECT))
  -             il.append( new CHECKCAST( cp.addClass( (ObjectType)returnType ) ) );
  +            if(!returnType.equals(Type.OBJECT))
  +                il.append( new CHECKCAST( cp.addClass( (ObjectType)returnType ) ) );
               return il.append( new ARETURN() );
           }else if ( returnType instanceof BasicType  ){
               if ( returnType.equals( Type.BOOLEAN )  ){
  @@ -388,8 +382,6 @@
                   return il.append( new IRETURN());
               }
               
  -            
  -            
           }
           return null;
       }
  @@ -446,16 +438,9 @@
           }
           
           return null;
  -        
  -        
  -        
  -        
       }
  -    
  -    
       private static int loadArg(InstructionList il, Type t, int index,int pos ){
           
  -        
           if( t instanceof BasicType ){
               
               if( t.equals( Type.LONG )) {
  @@ -476,8 +461,6 @@
           }else{
               il.append(new ALOAD(pos));
               return ++pos;
  -            
  -            
           }
           
       }
  @@ -514,12 +497,12 @@
               
           }else return new ObjectType(cls.getName());
           throw new java.lang.InternalError(cls.getName());
  -        
       }
       
       
       private static MethodGen toMethodGen( java.lang.reflect.Method mtd,String className,
       InstructionList il ,ConstantPoolGen cp){
  +        
           Class args [] = mtd.getParameterTypes();
           Type arg_types [] =  new Type[ args.length ];
           for( int i = 0; i < arg_types.length; i++){
  @@ -528,9 +511,6 @@
           
           return new MethodGen(ACC_PUBLIC, toType( mtd.getReturnType() ) , arg_types ,
           null, mtd.getName(), className ,  il, cp);
  -        
  -        
  -        
       }
       
       private static  Method  generateMethod( java.lang.reflect.Method method,
  @@ -561,7 +541,7 @@
           int loaded = createArgArray(il,factory,cp,mg.getArgumentTypes());
           int argArray = loaded;
           int resutFromBefore = ++loaded ;
  -         
  +        
           il.append( new ASTORE(argArray) );
           if(!abstractM){// invoke before
               il.append( new ALOAD(0) );
  @@ -571,10 +551,10 @@
               il.append( new ALOAD( argArray  ) );
               il.append( new INVOKEINTERFACE(before,4) );
               il.append( new ASTORE( resutFromBefore ) );
  -         
  +            
           }else {
  -          il.append( new ACONST_NULL() );
  -          il.append( new ASTORE( resutFromBefore ) );
  +            il.append( new ACONST_NULL() );
  +            il.append( new ASTORE( resutFromBefore ) );
           }
           //locals
           il.append( new ACONST_NULL() );
  @@ -615,15 +595,15 @@
               if( wrapper != null ){
                   il.append( initWrapper(mg.getReturnType(),cp) );
               }
  -           if( returnsValue ){ 
  -             ehEnd = il.append( new ASTORE(resultFromSuper) );
  -           }
  +            if( returnsValue ){
  +                ehEnd = il.append( new ASTORE(resultFromSuper) );
  +            }
               gotoHandled = new GOTO(null);
  -           if(!returnsValue ){ 
  -             ehEnd = il.append( gotoHandled );
  -           }else{
  -             il.append( gotoHandled );  
  -           }
  +            if(!returnsValue ){
  +                ehEnd = il.append( gotoHandled );
  +            }else{
  +                il.append( gotoHandled );
  +            }
               ehHandled =  il.append( new ASTORE(error ) );
           }
           
  @@ -644,7 +624,6 @@
           il.append( new ALOAD(error) );
           il.append( new INVOKEINTERFACE(after,8) );
           
  -        
           InstructionHandle exitMethod =  generateReturnValue(il,factory,cp,mg.getReturnType(),++loaded);
           
           if( !abstractM ){
  @@ -662,7 +641,6 @@
           
           return result;
       }
  -    
       
       static class MethodWrapper{
           java.lang.reflect.Method method;
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message