You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by ah...@apache.org on 2006/11/03 22:05:48 UTC

svn commit: r470993 - in /hivemind/branches/branch-2-0-annot/annotations/src: java/org/apache/hivemind/annotations/internal/ test/org/apache/hivemind/annotations/

Author: ahuegen
Date: Fri Nov  3 13:05:47 2006
New Revision: 470993

URL: http://svn.apache.org/viewvc?view=rev&rev=470993
Log:
Improved location of annotated modules and their methods

Added:
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleLocation.java
      - copied, changed from r470974, hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/MethodLocation.java
Removed:
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/MethodLocation.java
Modified:
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
    hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java

Copied: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleLocation.java (from r470974, hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/MethodLocation.java)
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleLocation.java?view=diff&rev=470993&p1=hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/MethodLocation.java&r1=470974&p2=hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleLocation.java&r2=470993
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/MethodLocation.java (original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleLocation.java Fri Nov  3 13:05:47 2006
@@ -14,6 +14,8 @@
 
 package org.apache.hivemind.annotations.internal;
 
+import java.lang.reflect.Method;
+
 import org.apache.hivemind.Location;
 import org.apache.hivemind.Resource;
 
@@ -21,17 +23,24 @@
  * Implementation of the {@link org.apache.hivemind.Location} interface.
  * Uses a method name in a class as position.
  *
- * @author Howard Lewis Ship
+ * @author Achim Huegen
  */
-public final class MethodLocation implements Location
+public final class AnnotatedModuleLocation implements Location
 {
     private Resource _resource;
-    private String _methodName;
+    private Class _moduleClass;
+    private Method _method;
 
-    public MethodLocation(Resource resource, String methodName)
+    public AnnotatedModuleLocation(Resource resource, Class moduleClass, Method method)
     {
         _resource = resource;
-        _methodName = methodName;
+        _moduleClass = moduleClass;
+        _method = method;
+    }
+    
+    public AnnotatedModuleLocation(Resource resource, Class moduleClass)
+    {
+        this(resource, moduleClass, null);
     }
 
     public Resource getResource()
@@ -39,49 +48,55 @@
         return _resource;
     }
     
-    private Object getMethodName()
+    public Method getMethod()
     {
-        return _methodName;
+        return _method;
+    }
+
+    public Class getModuleClass()
+    {
+        return _moduleClass;
     }
 
     public int hashCode()
     {
-        return ((237 + _resource.hashCode()) + _methodName.hashCode());
+        return ((237 + _resource.hashCode()) + 13 * _moduleClass.hashCode()) 
+            + (_method != null ? _method.hashCode() : 0);
     }
 
     public boolean equals(Object other)
     {
-        if (!(other instanceof MethodLocation))
+        if (!(other instanceof AnnotatedModuleLocation))
             return false;
 
-        MethodLocation l = (MethodLocation) other;
+        AnnotatedModuleLocation l = (AnnotatedModuleLocation) other;
 
-        if (_methodName.equals(l.getMethodName()))
+        if (_moduleClass.equals(l.getModuleClass()))
+            return false;
+        
+        if (_method.equals(l.getMethod()))
             return false;
 
         return _resource.equals(l.getResource());
     }
 
     /**
-     * Returns the position in format "method x"
+     * Returns the position in format "class x, method y"
      * 
      * @see org.apache.hivemind.Location#getPosition()
      */
     public String getPosition()
     {
-        return "method " + _methodName;
+        String result = "Class " + _moduleClass.getName();
+        if (_method != null) {
+            result += ", method " + _method.getName();
+        }
+        return result;
     }
     
     public String toString()
     {
-        StringBuffer buffer = new StringBuffer(_resource.toString());
-        String position = getPosition();
-        if (position.length() > 0) {
-            buffer.append(", "); 
-            buffer.append(position); 
-        }
-
-        return buffer.toString();
+        return getPosition();
     }
 
  }

Modified: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java?view=diff&rev=470993&r1=470992&r2=470993
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java (original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java Fri Nov  3 13:05:47 2006
@@ -24,7 +24,6 @@
 import org.apache.hivemind.definition.construction.ConfigurationConstructor;
 import org.apache.hivemind.definition.construction.ContributionConstructor;
 import org.apache.hivemind.definition.construction.ImplementationConstructor;
-import org.apache.hivemind.impl.LocationImpl;
 import org.apache.hivemind.util.ClasspathResource;
 import org.apache.hivemind.util.IdUtils;
 
@@ -136,7 +135,8 @@
             _log.debug("Method " + method.getName() + "classified as service point.");
         }
         
-        Location location = new MethodLocation(module.getLocation().getResource(), method.getName());
+        Location location = new AnnotatedModuleLocation(module.getLocation().getResource(), 
+                method.getDeclaringClass(), method);
 
         ServicePointDefinition spd = new ServicePointDefinition(module, service.id(), location, 
                 Visibility.PUBLIC, method.getReturnType().getName());
@@ -159,7 +159,8 @@
             _log.debug("Method " + method.getName() + "classified as configuration point.");
         }
         
-        Location location = new MethodLocation(module.getLocation().getResource(), method.getName());
+        Location location = new AnnotatedModuleLocation(module.getLocation().getResource(), 
+                method.getDeclaringClass(), method);
         
         ConfigurationConstructor constructor = new FactoryMethodConfigurationConstructor(location
                 , method, instanceProvider);
@@ -170,7 +171,6 @@
 
     }
 
-
     private void processAnnotatedContributionMethod(Method method, Contribution contribution, ModuleDefinition module, ModuleInstanceProvider instanceProvider)
     {
         if (_log.isDebugEnabled())
@@ -178,7 +178,8 @@
             _log.debug("Method " + method.getName() + "classified as contribution.");
         }
         
-        Location location = new MethodLocation(module.getLocation().getResource(), method.getName());
+        Location location = new AnnotatedModuleLocation(module.getLocation().getResource(), 
+                method.getDeclaringClass(), method);
         
         ContributionConstructor constructor = new TemplateMethodContributionConstructor(
                 location, method, instanceProvider);
@@ -193,10 +194,7 @@
     }
     
     /**
-     * Creates a location pointing at the module class. The location contains a fixed line number 1.
-     * 
-     * @param moduleClass
-     * @return the location
+     * Creates a location pointing at the module class. 
      */
     protected Location createModuleLocation(Class moduleClass)
     {
@@ -204,7 +202,7 @@
 
         Resource r = new ClasspathResource(_classResolver, path);
 
-        return new LocationImpl(r);
+        return new AnnotatedModuleLocation(r, moduleClass);
     }
 
     /**

Modified: hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java?view=diff&rev=470993&r1=470992&r2=470993
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java (original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java Fri Nov  3 13:05:47 2006
@@ -1,6 +1,7 @@
 package org.apache.hivemind.annotations;
 
 import org.apache.hivemind.Registry;
+import org.apache.hivemind.definition.ModuleDefinition;
 import org.apache.hivemind.definition.RegistryDefinition;
 import org.apache.hivemind.definition.ServicePointDefinition;
 
@@ -13,11 +14,16 @@
         service.run();
     }
 
+    /**
+     * Tests the string representation of the location of a module and an extension point
+     */
     public void testLocation()
     {
         RegistryDefinition registry = constructRegistryDefinition((new Class[] {SimpleAnnotatedModule.class}));
+        ModuleDefinition module = registry.getModule("org.apache.hivemind.annotations.SimpleAnnotatedModule");
+        assertEquals("Class org.apache.hivemind.annotations.SimpleAnnotatedModule", module.getLocation().toString());
         ServicePointDefinition service = registry.getServicePoint("org.apache.hivemind.annotations.SimpleAnnotatedModule.Test");
-        System.out.println(service.getLocation());
+        assertEquals("Class org.apache.hivemind.annotations.SimpleAnnotatedModule, method getRunnable", service.getLocation().toString());
     }
     
     public void testModuleId()