Return-Path: Delivered-To: apmail-hivemind-commits-archive@www.apache.org Received: (qmail 53649 invoked from network); 3 Nov 2006 15:56:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Nov 2006 15:56:05 -0000 Received: (qmail 89345 invoked by uid 500); 3 Nov 2006 15:56:17 -0000 Delivered-To: apmail-hivemind-commits-archive@hivemind.apache.org Received: (qmail 89335 invoked by uid 500); 3 Nov 2006 15:56:16 -0000 Mailing-List: contact commits-help@hivemind.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hivemind.apache.org Delivered-To: mailing list commits@hivemind.apache.org Received: (qmail 89326 invoked by uid 99); 3 Nov 2006 15:56:16 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Nov 2006 07:56:16 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Nov 2006 07:56:04 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 0F5B01A9846; Fri, 3 Nov 2006 07:55:40 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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... Date: Fri, 03 Nov 2006 15:55:39 -0000 To: commits@hivemind.apache.org From: ahuegen@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061103155540.0F5B01A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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());