You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2007/09/03 13:40:21 UTC

svn commit: r572286 - /felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java

Author: cziegeler
Date: Mon Sep  3 04:40:20 2007
New Revision: 572286

URL: http://svn.apache.org/viewvc?rev=572286&view=rev
Log:
Fix type class reference for generated methods. Only create bind/unbind if flag is set. Refactor to use only one creation method.

Modified:
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java?rev=572286&r1=572285&r2=572286&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java Mon Sep  3 04:40:20 2007
@@ -249,8 +249,12 @@
 
             final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
             cn.accept(writer);
-            this.createBind(writer, propertyName, className);
-            this.createUnbind(writer, propertyName, className);
+            if ( createBind ) {
+                this.createMethod(writer, propertyName, className, true);
+            }
+            if ( createUnbind ) {
+                this.createMethod(writer, propertyName, className, false);
+            }
 
             final FileOutputStream fos = new FileOutputStream(fileName);
             fos.write(writer.toByteArray());
@@ -260,31 +264,16 @@
         }
     }
 
-    protected void createBind(ClassWriter cw, String propertyName, String typeName) {
-        final org.objectweb.asm.Type type = org.objectweb.asm.Type.getType("L" + typeName + ";");
-        final String methodName = "bind" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
+    protected void createMethod(ClassWriter cw, String propertyName, String typeName, boolean bind) {
+        final org.objectweb.asm.Type type = org.objectweb.asm.Type.getType("L" + typeName.replace('.', '/') + ";");
+        final String methodName = (bind ? "" : "un") + "bind" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
         MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, methodName, "(" + type.toString() + ")V", null, null);
         mv.visitVarInsn(Opcodes.ALOAD, 0);
-        mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), 1);
-        mv.visitFieldInsn(Opcodes.PUTFIELD, this.getName(), propertyName, type.toString());
-        mv.visitInsn(Opcodes.RETURN);
-        mv.visitMaxs(0, 0);
-        // add to qdox
-        final JavaParameter param = new JavaParameter(new Type(typeName), "param");
-        final JavaParameter[] params = new JavaParameter[] {param};
-        final com.thoughtworks.qdox.model.JavaMethod meth = new com.thoughtworks.qdox.model.JavaMethod();
-        meth.setName(methodName);
-        meth.setParameters(params);
-        meth.setModifiers(new String[] {"protected"});
-        this.javaClass.addMethod(meth);
-      }
-
-    protected void createUnbind(ClassWriter cw, String propertyName, String typeName) {
-        final org.objectweb.asm.Type type = org.objectweb.asm.Type.getType("L" + typeName + ";");
-        final String methodName = "unbind" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
-        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, methodName, "(" + type.toString() + ")V", null, null);
-        mv.visitVarInsn(Opcodes.ALOAD, 0);
-        mv.visitInsn(Opcodes.ACONST_NULL);
+        if ( bind ) {
+            mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), 1);
+        } else {
+            mv.visitInsn(Opcodes.ACONST_NULL);
+        }
         mv.visitFieldInsn(Opcodes.PUTFIELD, this.getName(), propertyName, type.toString());
         mv.visitInsn(Opcodes.RETURN);
         mv.visitMaxs(0, 0);
@@ -296,6 +285,5 @@
         meth.setParameters(params);
         meth.setModifiers(new String[] {"protected"});
         this.javaClass.addMethod(meth);
-      }
-
+    }
 }