You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/09/04 19:26:13 UTC

svn commit: r1520078 - in /felix/trunk/ipojo: manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java runtime/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java

Author: clement
Date: Wed Sep  4 17:26:12 2013
New Revision: 1520078

URL: http://svn.apache.org/r1520078
Log:
FELIX-4215 Extend manipulation metadata with argument names

Extract argument's name from the byte code (local variables) and extends the MethodMetadata to handle them.

Modified:
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java?rev=1520078&r1=1520077&r2=1520078&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java Wed Sep  4 17:26:12 2013
@@ -19,12 +19,8 @@
 
 package org.apache.felix.ipojo.manipulation;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+
 import org.apache.felix.ipojo.manipulation.ClassChecker.AnnotationDescriptor;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
@@ -85,6 +81,12 @@ public class MethodDescriptor {
     private final boolean m_isStatic;
 
     /**
+     * The local variables by index.
+     * This map is used to detect the argument names.
+     */
+    private LinkedHashMap<Integer, LocalVariableNode> m_locals = new LinkedHashMap<Integer, LocalVariableNode>();
+
+    /**
      * Constructor.
      * @param name : name of the method.
      * @param desc : descriptor of the method.
@@ -164,13 +166,23 @@ public class MethodDescriptor {
 
         // Add arguments
         if (m_arguments.length > 0) {
-            StringBuffer args = new StringBuffer("{");
+            StringBuilder args = new StringBuilder("{");
+            StringBuilder names = new StringBuilder("{");
             args.append(m_arguments[0]);
+            if (m_locals.containsKey(1)) {
+                names.append(m_locals.get(1).name); // index +1 as the 0 is this
+            }
             for (int i = 1; i < m_arguments.length; i++) {
-                args.append("," + m_arguments[i]);
+                args.append(",").append(m_arguments[i]);
+                if (m_locals.containsKey(i +1)) {
+                    names.append(",").append(m_locals.get(i +1).name);
+                }
             }
             args.append("}");
+            names.append("}");
+
             method.addAttribute(new Attribute("arguments", args.toString()));
+            method.addAttribute(new Attribute("names", names.toString()));
         }
 
         return method;
@@ -221,6 +233,7 @@ public class MethodDescriptor {
     }
 
     public void addLocalVariable(String name, String desc, String signature, int index) {
+        m_locals.put(index, new LocalVariableNode(name, desc, signature, null, null, index));
         if (index >= m_argsVarLength) {
             // keep only argument-related local variables definitions (others relate to code which isn't in this method) 
             return;

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java?rev=1520078&r1=1520077&r2=1520078&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java Wed Sep  4 17:26:12 2013
@@ -20,6 +20,8 @@ package org.apache.felix.ipojo.parser;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 import org.apache.felix.ipojo.InstanceManager;
 import org.apache.felix.ipojo.metadata.Element;
@@ -47,20 +49,27 @@ public class MethodMetadata {
      */
     public static final String CONSTRUCTOR_PREFIX = "$init";
 
+
     /**
      * The name of the method.
      */
-    private String m_name;
+    private final String m_name;
 
     /**
      * The argument type array.
      */
-    private String[] m_arguments = new String[0];
+    private final String[] m_arguments;
 
     /**
      * The returned type.
      */
-    private String m_return = "void";
+    private final String m_return;
+
+    /**
+     * The argument names if there were contained in the manifest.
+     * @since 1.10.2
+     */
+    private final String[] m_names;
 
     /**
      * Creates a Method Metadata.
@@ -69,12 +78,23 @@ public class MethodMetadata {
     MethodMetadata(Element metadata) {
         m_name = metadata.getAttribute("name");
         String arg = metadata.getAttribute("arguments");
+        String names = metadata.getAttribute("names");
         String result = metadata.getAttribute("return");
         if (arg != null) {
             m_arguments = ParseUtils.parseArrays(arg);
+        } else {
+            m_arguments = new String[0];
         }
+        if (names != null) {
+            m_names = ParseUtils.parseArrays(names);
+        } else {
+            m_names = new String[0];
+        }
+
         if (result != null) {
             m_return = result;
+        } else {
+            m_return = "void";
         }
     }
 
@@ -86,6 +106,24 @@ public class MethodMetadata {
         return m_arguments;
     }
 
+    public String[] getMethodArgumentNames() {
+        return m_names;
+    }
+
+    /**
+     * Gets the method arguments.
+     * The keys are the argument names, while the values are the argument type.
+     * @return the map of argument
+     * @since 1.10.2
+     */
+    public Map<String, String> getArguments() {
+        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
+        for (int i = 0; i < m_names.length; i++) {
+            map.put(m_names[i], m_arguments[i]);
+        }
+        return map;
+    }
+
     public String getMethodReturn() {
         return m_return;
     }