Re: [patch] FieldOrMethod.java, added two convenience methods

Neeme Praks <[email protected]>
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
Enver Haase wrote:

> >I added two convenience methods to FieldOrMethod class:
> >* Type getReturnType()
> >* Type[] getArgumentTypes()
>
> I don't like them.
>
> I can't see either argument types of a field,
> nor a return type. I'd say these convenience
> methods belong in the Method class; and the
> Field class should have a "Type getType()"
> method.

Ok, sorry for that, I managed to miss that for some reason.
So, following your proposal, the new methods would be:
Method.java:
* Type getReturnType()
* Type[] getArgumentTypes()
Field.java:
* Type getType()

(patches attached)

> Look at the "FieldOrMethod" in the "generic" package;
> there's all of the above, done in the way I'd suppose.

Well, I had a look there, but as far as I have understood, generic 
package purpose is for generating classes, not for inspecting them.
And, I didn't really find the thing you mention... there is:
FieldOrMethod.java
FieldInstruction.java
MethodGen.java
MethodObserver.java

All of those are geared towards generating classes, not for inspecting 
them, no?

> As for the dependency "Type" indroduces--- that's
> not really a problem, I believe.
> On the other hand, if you need elements of the "generic"
> package, why don't you simply convert a "classfile" Method or
> Field to its "generic" counterpart and use all of the
> already-implemented features instead of re-implementing
> them all in the "classfile" package?

What I need is an API that fulfils the same need as java reflection API 
but has the same types as BCEL uses. This would make it easier to 
inspect a class and then generate a new class based on the inspected 
class...

Rgds,
Neeme

--
To unsubscribe, e-mail:   <mailto:[email protected]>
For additional commands, e-mail: <mailto:[email protected]>
Field.java.diff.txt (text/plain, 686 B)
Index: Field.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/classfile/Field.java,v
retrieving revision 1.2
diff -u -r1.2 Field.java
--- Field.java	24 Apr 2002 11:01:30 -0000	1.2
+++ Field.java	3 Dec 2002 15:07:36 -0000
@@ -54,6 +54,8 @@
  * <http://www.apache.org/>.
  */
 import  org.apache.bcel.Constants;
+import org.apache.bcel.generic.Type;
+
 import java.io.*;
 
 /**
@@ -115,6 +117,13 @@
 	return (ConstantValue)attributes[i];
 
     return null;
+  }
+
+  /**
+   * @return return type of a method
+   */
+  public Type getType() {
+    return Type.getType(getSignature());
   }
 
   /**
Method.java.diff.txt (text/plain, 956 B)
Index: Method.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/classfile/Method.java,v
retrieving revision 1.4
diff -u -r1.4 Method.java
--- Method.java	3 Jun 2002 09:06:37 -0000	1.4
+++ Method.java	3 Dec 2002 15:08:48 -0000
@@ -54,6 +54,8 @@
  * <http://www.apache.org/>.
  */
 import org.apache.bcel.Constants;
+import org.apache.bcel.generic.Type;
+
 import java.io.*;
 
 /**
@@ -162,6 +164,20 @@
       return null;
   }
 
+  /**
+   * @return return type of a method
+   */
+  public Type getReturnType() {
+    return Type.getReturnType(getSignature());
+  }
+
+  /**
+   * @return array of method argument types
+   */
+  public Type[] getArgumentTypes() {
+    return Type.getArgumentTypes(getSignature());
+  }
+  
   /**
    * Return string representation close to declaration format,
    * `public static void main(String[] args) throws IOException', e.g.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.