Author: ravn
Date: Sun Oct 26 14:33:48 2008
New Revision: 1217

Modified:
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/agent/AgentPremain.java
   
slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java

Log:
added javadoc

Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/agent/AgentPremain.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/agent/AgentPremain.java       
(original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/agent/AgentPremain.java       
Sun Oct 26 14:33:48 2008
@@ -29,14 +29,11 @@
   public static void premain(String agentArgument,
       Instrumentation instrumentation) {
 
-    System.err.println("THIS JAVAAGENT IS NOT RELEASED YET.  "
-        + "DO NOT USE IN PRODUCTION ENVIRONMENTS.");
-
     LogTransformer.Builder builder = new LogTransformer.Builder();
     builder = builder.addEntryExit(true);
 
     if (agentArgument != null) {
-      Properties args = parseArguments(agentArgument);
+      Properties args = parseArguments(agentArgument, ";");
 
       if (args.containsKey("verbose")) {
         builder = builder.verbose(true);
@@ -60,11 +57,24 @@
     instrumentation.addTransformer(builder.build());
   }
 
-  private static Properties parseArguments(String agentArgument) {
+  /**
+   * Consider the argument string to be a property file (by converting the
+   * splitter character to line feeds), and then reading it like any other
+   * property file.
+   * 
+   * 
+   * @param agentArgument
+   *          string given by instrumentation framework
+   * @param separator
+   *          String to convert to line feeds
+   * @return argument converted to properties
+   */
+  private static Properties parseArguments(String agentArgument,
+      String separator) {
     Properties p = new Properties();
     try {
-      byte[] bytes = agentArgument.replaceAll(";", "\n").getBytes();
-      p.load(new ByteArrayInputStream(bytes));
+      String argumentAsLines = agentArgument.replaceAll(separator, "\n");
+      p.load(new ByteArrayInputStream(argumentAsLines.getBytes()));
     } catch (IOException e) {
       String s = "Could not load arguments as properties";
       throw new RuntimeException(s, e);
@@ -73,9 +83,9 @@
   }
 
   /**
-   * Print the start message with the time NOW, and register a shutdown hook
-   * which will print the stop message with the time then and the number of
-   * milliseconds passed since.
+   * Print the start message to System.err with the time NOW, and register a
+   * shutdown hook which will print the stop message to System.err with the 
time
+   * then and the number of milliseconds passed since.
    * 
    */
   private static void printStartStopTimes() {

Modified: 
slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java
==============================================================================
--- 
slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java
  (original)
+++ 
slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java
  Sun Oct 26 14:33:48 2008
@@ -10,7 +10,7 @@
 
 /**
  * Helper methods for Javassist functionality.
- *
+ * 
  */
 public class JavassistHelper {
 
@@ -84,15 +84,16 @@
     StringBuffer sb = new StringBuffer(methodName + "(\" ");
     for (int i = 0; i < parameterTypes.length; i++) {
       if (i > 0) {
+        // add a comma and a space between printed values
         sb.append(" + \", \" ");
       }
 
       CtClass parameterType = parameterTypes[i];
       boolean isArray = parameterType.isArray();
-      CtClass arrayOf = parameterType.getComponentType();
+      CtClass arrayType = parameterType.getComponentType();
       if (isArray) {
-        while (arrayOf.isArray()) {
-          arrayOf = arrayOf.getComponentType();
+        while (arrayType.isArray()) {
+          arrayType = arrayType.getComponentType();
         }
       }
 
@@ -101,7 +102,7 @@
       sb.append("\" + \"=");
 
       // use Arrays.asList() to render array of objects.
-      if (isArray && !arrayOf.isPrimitive()) {
+      if (isArray && !arrayType.isPrimitive()) {
         sb.append("\"+ java.util.Arrays.asList($" + (i + 1) + ")");
       } else {
         sb.append("\"+ $" + (i + 1));
@@ -115,15 +116,17 @@
 
   /**
    * Determine the name of parameter with index i in the given method. Use the
-   * locals attributes about local variables from the classfile.
+   * locals attributes about local variables from the classfile. Note: This is
+   * still work in progress.
    * 
    * @param method
    * @param locals
    * @param i
-   * @return
+   * @return the name of the parameter if available or a number if not.
    */
   static String parameterNameFor(CtBehavior method,
       LocalVariableAttribute locals, int i) {
+
     if (locals == null) {
       return Integer.toString(i + 1);
     }
@@ -144,7 +147,7 @@
     }
     String variableName = locals.variableName(j);
     if (variableName.equals("this")) {
-      System.err.println("this returned as a parameter name for "
+      System.err.println("'this' returned as a parameter name for "
           + method.getName() + " index " + j + ", names are probably 
shifted.");
     }
     return variableName;
_______________________________________________
dev mailing list
dev@slf4j.org
http://www.slf4j.org/mailman/listinfo/dev

Reply via email to