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 16:55:39 UTC
svn commit: r470867 - in /hivemind/branches/branch-2-0-annot:
annotations/src/java/org/apache/hivemind/annotations/internal/
annotations/src/test/org/apache/hivemind/annotations/
framework/src/java/org/apache/hivemind/ framework/src/java/org/apache/hiv...
Author: ahuegen
Date: Fri Nov 3 07:55:39 2006
New Revision: 470867
URL: http://svn.apache.org/viewvc?view=rev&rev=470867
Log:
Introduced generic position attribute in Location instead of line and column
Added:
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
hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/Location.java
hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/LocationImpl.java
hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestLocation.java
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=470867&r1=470866&r2=470867
==============================================================================
--- 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 07:55:39 2006
@@ -61,7 +61,7 @@
public void processModule(Class moduleClass)
{
ModuleDefinition module = new ModuleDefinition(determineModuleId(moduleClass),
- createLocation(moduleClass), _classResolver, moduleClass.getPackage().getName());
+ createModuleLocation(moduleClass), _classResolver, moduleClass.getPackage().getName());
// processServices(moduleClass);
@@ -135,9 +135,11 @@
{
_log.debug("Method " + method.getName() + "classified as service point.");
}
+
+ Location location = new MethodLocation(module.getLocation().getResource(), method.getName());
- ServicePointDefinition spd = new ServicePointDefinition(module, service.id(), module
- .getLocation(), Visibility.PUBLIC, method.getReturnType().getName());
+ ServicePointDefinition spd = new ServicePointDefinition(module, service.id(), location,
+ Visibility.PUBLIC, method.getReturnType().getName());
module.addServicePoint(spd);
ImplementationConstructor constructor = new FactoryMethodImplementationConstructor(module
@@ -157,8 +159,10 @@
_log.debug("Method " + method.getName() + "classified as configuration point.");
}
- ConfigurationConstructor constructor = new FactoryMethodConfigurationConstructor(module
- .getLocation(), method, instanceProvider);
+ Location location = new MethodLocation(module.getLocation().getResource(), method.getName());
+
+ ConfigurationConstructor constructor = new FactoryMethodConfigurationConstructor(location
+ , method, instanceProvider);
ConfigurationPointDefinition cpd = new ConfigurationPointDefinition(module, configuration.id(), module
.getLocation(), Visibility.PUBLIC, constructor, method.getReturnType().getName(), Occurances.UNBOUNDED);
@@ -174,8 +178,10 @@
_log.debug("Method " + method.getName() + "classified as contribution.");
}
- ContributionConstructor constructor = new TemplateMethodContributionConstructor(module
- .getLocation(), method, instanceProvider);
+ Location location = new MethodLocation(module.getLocation().getResource(), method.getName());
+
+ ContributionConstructor constructor = new TemplateMethodContributionConstructor(
+ location, method, instanceProvider);
ContributionDefinition cd = new ContributionDefinition(module, module
.getLocation(), constructor);
@@ -192,13 +198,13 @@
* @param moduleClass
* @return the location
*/
- protected Location createLocation(Class moduleClass)
+ protected Location createModuleLocation(Class moduleClass)
{
String path = "/" + moduleClass.getName().replace('.', '/');
Resource r = new ClasspathResource(_classResolver, path);
- return new LocationImpl(r, 1);
+ return new LocationImpl(r);
}
/**
Added: 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/MethodLocation.java?view=auto&rev=470867
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/MethodLocation.java (added)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/MethodLocation.java Fri Nov 3 07:55:39 2006
@@ -0,0 +1,87 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.hivemind.annotations.internal;
+
+import org.apache.hivemind.Location;
+import org.apache.hivemind.Resource;
+
+/**
+ * Implementation of the {@link org.apache.hivemind.Location} interface.
+ * Uses a method name in a class as position.
+ *
+ * @author Howard Lewis Ship
+ */
+public final class MethodLocation implements Location
+{
+ private Resource _resource;
+ private String _methodName;
+
+ public MethodLocation(Resource resource, String methodName)
+ {
+ _resource = resource;
+ _methodName = methodName;
+ }
+
+ public Resource getResource()
+ {
+ return _resource;
+ }
+
+ private Object getMethodName()
+ {
+ return _methodName;
+ }
+
+ public int hashCode()
+ {
+ return ((237 + _resource.hashCode()) + _methodName.hashCode());
+ }
+
+ public boolean equals(Object other)
+ {
+ if (!(other instanceof MethodLocation))
+ return false;
+
+ MethodLocation l = (MethodLocation) other;
+
+ if (_methodName.equals(l.getMethodName()))
+ return false;
+
+ return _resource.equals(l.getResource());
+ }
+
+ /**
+ * Returns the position in format "method x"
+ *
+ * @see org.apache.hivemind.Location#getPosition()
+ */
+ public String getPosition()
+ {
+ return "method " + _methodName;
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer(_resource.toString());
+ String position = getPosition();
+ if (position.length() > 0) {
+ buffer.append(", ");
+ buffer.append(position);
+ }
+
+ return buffer.toString();
+ }
+
+ }
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=470867&r1=470866&r2=470867
==============================================================================
--- 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 07:55:39 2006
@@ -2,6 +2,7 @@
import org.apache.hivemind.Registry;
import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.definition.ServicePointDefinition;
public class TestAnnotatedModuleReader extends AnnotationTestCase
{
@@ -12,6 +13,13 @@
service.run();
}
+ public void testLocation()
+ {
+ RegistryDefinition registry = constructRegistryDefinition((new Class[] {SimpleAnnotatedModule.class}));
+ ServicePointDefinition service = registry.getServicePoint("org.apache.hivemind.annotations.SimpleAnnotatedModule.Test");
+ System.out.println(service.getLocation());
+ }
+
public void testModuleId()
{
RegistryDefinition registry = constructRegistryDefinition((new Class[] {ModuleWithExplicitId.class}));
Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/Location.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/Location.java?view=diff&rev=470867&r1=470866&r2=470867
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/Location.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/Location.java Fri Nov 3 07:55:39 2006
@@ -30,14 +30,9 @@
public Resource getResource();
/**
- * The line within the resource containing the location,
- * or -1 if the line number is not known.
- *
+ * A position inside the resource. The format of the position
+ * is implementation specific.
*/
- public int getLineNumber();
+ public String getPosition();
- /**
- * The column number, or -1 if not known.
- */
- public int getColumnNumber();
}
Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/LocationImpl.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/LocationImpl.java?view=diff&rev=470867&r1=470866&r2=470867
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/LocationImpl.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/LocationImpl.java Fri Nov 3 07:55:39 2006
@@ -19,6 +19,7 @@
/**
* Implementation of the {@link org.apache.hivemind.Location} interface.
+ * Uses a line and column based position.
*
* @author Howard Lewis Ship
*/
@@ -70,10 +71,10 @@
public boolean equals(Object other)
{
- if (!(other instanceof Location))
+ if (!(other instanceof LocationImpl))
return false;
- Location l = (Location) other;
+ LocationImpl l = (LocationImpl) other;
if (_lineNumber != l.getLineNumber())
return false;
@@ -83,26 +84,42 @@
return _resource.equals(l.getResource());
}
-
- public String toString()
+
+ /**
+ * Returns the position in format "line x, column y"
+ *
+ * @see org.apache.hivemind.Location#getPosition()
+ */
+ public String getPosition()
{
- if (_lineNumber <= 0 && _columnNumber <= 0)
- return _resource.toString();
-
- StringBuffer buffer = new StringBuffer(_resource.toString());
-
+ String result = "";
+
if (_lineNumber > 0)
{
- buffer.append(", line ");
- buffer.append(_lineNumber);
+ result += "line " + _lineNumber;
}
if (_columnNumber > 0)
{
- buffer.append(", column ");
- buffer.append(_columnNumber);
+ if (result.length() > 0) {
+ result += ", ";
+ }
+ result += "column " + _columnNumber;
+ }
+
+ 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();
}
-}
+
+ }
Modified: hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestLocation.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestLocation.java?view=diff&rev=470867&r1=470866&r2=470867
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestLocation.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestLocation.java Fri Nov 3 07:55:39 2006
@@ -35,7 +35,7 @@
public void testNoNumbers()
{
- Location l = new LocationImpl(_location);
+ LocationImpl l = new LocationImpl(_location);
assertSame(_location, l.getResource());
assertTrue(l.getLineNumber() <= 0);
@@ -51,7 +51,7 @@
public void testWithLine()
{
- Location l = new LocationImpl(_location, 22);
+ LocationImpl l = new LocationImpl(_location, 22);
assertEquals(22, l.getLineNumber());
assertEquals("classpath:/META-INF/foo.bar, line 22", l.toString());
@@ -59,7 +59,7 @@
public void testWithNumbers()
{
- Location l = new LocationImpl(_location, 100, 15);
+ LocationImpl l = new LocationImpl(_location, 100, 15);
assertEquals(100, l.getLineNumber());
assertEquals(15, l.getColumnNumber());