[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bcel-dev
Subject:    Re: AW: Re: Lookup BCEL Method for a particular  java.lang.reflect.Method / Create JavaClass from ja
From:       Davanum Srinivas <dims () yahoo ! com>
Date:       2002-06-12 16:23:37
[Download RAW message or body]

Markus,

- I had downloaded bcel-5.0rc1 which did not have the SyntheticRepository.
- The enclosed patch 
  - Adds a getMethod in JavaClass...
  - Adds an entry in the manifest to make my Ant happy.
- When is RC2? 

Thanks,
dims

--- markus.dahm@berlin.de wrote:
> 
> > Wish #2: Wish i could create a JavaClass from java.lang.Class as shown below.
> > Class clazz = Class.forName("XXXX");
> > ClassParser parser = new ClassParser(clazz);
> > JavaClass jclazz = parser.parse();
> 
> You can already do this: 
> SyntheticRepository.getInstance().loadClass(clazz);
> 
> using the repository is the preferred way anyway.
> 
> > I can send in patches for both if anyone is interested.
> 
> Yes.
> 
> Cheers
>  Markus
> --
> berlin.de - meine stadt im netz. Jetzt eigene eMail-adresse @berlin.de sichern!
> http://webmail.berlin.de
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:bcel-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:bcel-dev-help@jakarta.apache.org>
> 


=====
Davanum Srinivas - http://xml.apache.org/~dims/

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
["bcel.txt" (text/plain)]

cvs server: Diffing .
Index: manifest.txt
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/manifest.txt,v
retrieving revision 1.1
diff -u -r1.1 manifest.txt
--- manifest.txt	18 Apr 2002 07:52:13 -0000	1.1
+++ manifest.txt	12 Jun 2002 16:21:13 -0000
@@ -1,2 +1,4 @@
-Manifest-Version: 1.0

-Main-Class: listclass

+Name: BCEL
+Manifest-Version: 1.0
+Main-Class: listclass
+
cvs server: Diffing docs
cvs server: Diffing docs/eps
cvs server: Diffing docs/verifier
cvs server: Diffing examples
cvs server: Diffing examples/Mini
cvs server: Diffing lib
cvs server: Diffing src
cvs server: Diffing src/java
cvs server: Diffing src/java/org
cvs server: Diffing src/java/org/apache
cvs server: Diffing src/java/org/apache/bcel
cvs server: Diffing src/java/org/apache/bcel/classfile
Index: src/java/org/apache/bcel/classfile/JavaClass.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/classfile/JavaClass.java,v
retrieving revision 1.9
diff -u -r1.9 JavaClass.java
--- src/java/org/apache/bcel/classfile/JavaClass.java	6 Jun 2002 11:35:43 -0000	1.9
+++ src/java/org/apache/bcel/classfile/JavaClass.java	12 Jun 2002 16:21:13 -0000
@@ -403,7 +403,20 @@
   /**
    * @return Methods of the class.
    */
-  public Method[] getMethods()       { return methods; }    
+  public Method[] getMethods()       { return methods; }
+
+  /**
+   * @return A org.apache.bcel.classfile.Method corresponding to java.lang.reflect.Method
+   */
+  public org.apache.bcel.classfile.Method getMethod(java.lang.reflect.Method m) {
+      for (int i = 0; i < methods.length; i++) {
+          if (m.getName().equals(methods[i].getName()) &&
+                  getSignature(m).equals(methods[i].getSignature())) {
+              return methods[i];
+          }
+      }
+      return null;
+  }
 
   /**
    * @return Minor number of compiler version.
@@ -794,4 +807,63 @@
 	    
     return vec.toArray();
   }
+
+    /**
+     * Compute the JVM signature for the class.
+     */
+    private String getSignature(Class clazz) {
+        String type = null;
+        if (clazz.isArray()) {
+            Class cl = clazz;
+            int dimensions = 0;
+            while (cl.isArray()) {
+                dimensions++;
+                cl = cl.getComponentType();
+            }
+            StringBuffer sb = new StringBuffer();
+            for (int i = 0; i < dimensions; i++) {
+                sb.append("[");
+            }
+            sb.append(getSignature(cl));
+            type = sb.toString();
+        } else if (clazz.isPrimitive()) {
+            if (clazz == Integer.TYPE) {
+                type = "I";
+            } else if (clazz == Byte.TYPE) {
+                type = "B";
+            } else if (clazz == Long.TYPE) {
+                type = "J";
+            } else if (clazz == Float.TYPE) {
+                type = "F";
+            } else if (clazz == Double.TYPE) {
+                type = "D";
+            } else if (clazz == Short.TYPE) {
+                type = "S";
+            } else if (clazz == Character.TYPE) {
+                type = "C";
+            } else if (clazz == Boolean.TYPE) {
+                type = "Z";
+            } else if (clazz == Void.TYPE) {
+                type = "V";
+            }
+        } else {
+            type = "L" + clazz.getName().replace('.', '/') + ";";
+        }
+        return type;
+    }
+
+    /*
+     * Compute the JVM method descriptor for the method.
+     */
+    private String getSignature(java.lang.reflect.Method meth) {
+        StringBuffer sb = new StringBuffer();
+        sb.append("(");
+        Class[] params = meth.getParameterTypes(); // avoid clone
+        for (int j = 0; j < params.length; j++) {
+            sb.append(getSignature(params[j]));
+        }
+        sb.append(")");
+        sb.append(getSignature(meth.getReturnType()));
+        return sb.toString();
+    }
 }
cvs server: Diffing src/java/org/apache/bcel/generic
cvs server: Diffing src/java/org/apache/bcel/util
cvs server: Diffing src/java/org/apache/bcel/verifier
cvs server: Diffing src/java/org/apache/bcel/verifier/exc
cvs server: Diffing src/java/org/apache/bcel/verifier/statics
cvs server: Diffing src/java/org/apache/bcel/verifier/structurals
cvs server: Diffing xdocs
cvs server: Diffing xdocs/images
cvs server: Diffing xdocs/stylesheets



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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic