mdahm       2002/11/30 03:16:44

  Modified:    src/java/org/apache/bcel/generic MethodGen.java
  Log:
  Bug fixes
  
  Revision  Changes    Path
  1.6       +42 -25    jakarta-bcel/src/java/org/apache/bcel/generic/MethodGen.java
  
  Index: MethodGen.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/generic/MethodGen.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MethodGen.java    24 Apr 2002 08:11:30 -0000      1.5
  +++ MethodGen.java    30 Nov 2002 11:16:44 -0000      1.6
  @@ -122,37 +122,47 @@
       setInstructionList(il);
       setConstantPool(cp);
   
  -    if((access_flags & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0) {
  -      InstructionHandle start = il.getStart();
  -      InstructionHandle end   = il.getEnd();
  +    boolean abstract_ = isAbstract() || isNative();
  +    InstructionHandle start = null;
  +    InstructionHandle end   = null;
  +
  +    if(!abstract_) {
  +      start = il.getStart();
  +      end   = il.getEnd();
   
         /* Add local variables, namely the implicit `this' and the arguments
          */
  -      if(!isStatic() && (class_name != null)) // Instance method -> `this' is local 
var 0
  +      if(!isStatic() && (class_name != null)) { // Instance method -> `this' is 
local var 0
        addLocalVariable("this", new ObjectType(class_name), start, end);
  +      }
  +    }
   
  -      if(arg_types != null) {
  -     int size = arg_types.length;
  -     for(int i=0; i < size; i++) {
  -       if(Type.VOID == arg_types[i])
  -         throw new ClassGenException("'void' is an illegal argument type for a 
method");
  -}
  -     
  -     if(arg_names != null) { // Names for variables provided?
  -       if(size != arg_names.length)
  -         throw new ClassGenException("Mismatch in argument array lengths: " +
  -                                     size + " vs. " + arg_names.length);
  -     } else { // Give them dummy names
  -       arg_names = new String[size];
  -
  -       for(int i=0; i < size; i++)
  -         arg_names[i] = "arg" + i;
  +    if(arg_types != null) {
  +      int size = arg_types.length;
   
  -       setArgumentNames(arg_names);
  +      for(int i=0; i < size; i++) {
  +     if(Type.VOID == arg_types[i]) {
  +       throw new ClassGenException("'void' is an illegal argument type for a 
method");
        }
  -
  +      }
  +     
  +      if(arg_names != null) { // Names for variables provided?
  +     if(size != arg_names.length)
  +       throw new ClassGenException("Mismatch in argument array lengths: " +
  +                                   size + " vs. " + arg_names.length);
  +      } else { // Give them dummy names
  +     arg_names = new String[size];
  +     
        for(int i=0; i < size; i++)
  +       arg_names[i] = "arg" + i;
  +     
  +     setArgumentNames(arg_names);
  +      }
  +      
  +      if(!abstract_) {
  +     for(int i=0; i < size; i++) {
          addLocalVariable(arg_names[i], arg_types[i], start, end);
  +     }
         }
       }
     }
  @@ -217,22 +227,29 @@
   
          if(a instanceof LineNumberTable) {
            LineNumber[] ln = ((LineNumberTable)a).getLineNumberTable();
  +
            for(int k=0; k < ln.length; k++) {
              LineNumber l = ln[k];
              addLineNumber(il.findHandle(l.getStartPC()), l.getLineNumber());
            }
          } else if(a instanceof LocalVariableTable) {
            LocalVariable[] lv = ((LocalVariableTable)a).getLocalVariableTable();
  +
  +         removeLocalVariables();
  +
            for(int k=0; k < lv.length; k++) {
              LocalVariable     l     = lv[k];
              InstructionHandle start = il.findHandle(l.getStartPC());
              InstructionHandle end   = il.findHandle(l.getStartPC() + l.getLength());
   
              // Repair malformed handles
  -           if(start == null)
  +           if(null == start) {
                start = il.getStart();
  -           if(end == null)
  +           }
  +
  +           if(null == end) {
                end = il.getEnd();
  +           }
   
              addLocalVariable(l.getName(), Type.getType(l.getSignature()),
                               l.getIndex(), start, end);
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to