tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r293093 - in /jakarta/tapestry/trunk: ./ framework/src/java/org/apache/tapestry/enhance/ framework/src/test/org/apache/tapestry/enhance/
Date Sun, 02 Oct 2005 11:52:00 GMT
Author: hlship
Date: Sun Oct  2 04:51:52 2005
New Revision: 293093

URL: http://svn.apache.org/viewcvs?rev=293093&view=rev
Log:
TAPESTRY-344: Unimplemented abstract method check broken

Added:
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractBase.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnable.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnableSubclass.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Complete.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java
      - copied, changed from r292042, jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/TestEnhancedClassValidator.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Incomplete.java
Removed:
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/TestEnhancedClassValidator.java
Modified:
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhancedClassValidatorImpl.java
    jakarta/tapestry/trunk/status.xml

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
(original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
Sun Oct  2 04:51:52 2005
@@ -33,11 +33,20 @@
 {
     private final static MessageFormatter _formatter = new MessageFormatter(EnhanceMessages.class);
 
-    static String noImplForAbstractMethod(Method method, Class declareClass, String className,
+    static String noImplForAbstractMethod(Method method, Class declareClass, Class baseClass,
             Class enhancedClass)
     {
         return _formatter.format("no-impl-for-abstract-method", new Object[]
-        { method, declareClass.getName(), className, enhancedClass.getName() });
+        { method, declareClass.getName(), baseClass.getName(), enhancedClass.getName() });
+    }
+
+    static String unimplementedInterfaceMethod(Method method, Class baseClass, Class enhancedClass)
+    {
+        return _formatter.format(
+                "unimplemented-interface-method",
+                method,
+                baseClass.getName(),
+                enhancedClass.getName());
     }
 
     static String unabelToIntrospectClass(Class targetClass, Throwable cause)

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
(original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
Sun Oct  2 04:51:52 2005
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 no-impl-for-abstract-method=Method ''{0}'' (declared in class {1}) has no implementation
in class {2} (or enhanced subclass {3}).
+unimplemented-interface-method=Method ''{0}'' has no implementation in class {1} (or enhanced
subclass {2}).
 property-type-mismatch=Unable to enhance class {0} because it contains property {1} of type
{2}, not the expected type {3}.
 unable-to-introspect-class=Unable to introspect properties of class {0}: {1}
 error-adding-property=Error adding property {0} to class {1}: {2}

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhancedClassValidatorImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhancedClassValidatorImpl.java?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhancedClassValidatorImpl.java
(original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhancedClassValidatorImpl.java
Sun Oct  2 04:51:52 2005
@@ -16,10 +16,14 @@
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.hivemind.ErrorLog;
+import org.apache.hivemind.Location;
 import org.apache.hivemind.service.MethodSignature;
 import org.apache.tapestry.spec.IComponentSpecification;
 
@@ -37,6 +41,8 @@
     public void validate(Class baseClass, Class enhancedClass, IComponentSpecification specification)
     {
         Set implementedMethods = new HashSet();
+        List interfaceQueue = new ArrayList();
+        Location location = specification.getLocation();
 
         Class current = enhancedClass;
 
@@ -57,31 +63,62 @@
                     if (implementedMethods.contains(s))
                         continue;
 
-                    _errorLog.error(EnhanceMessages.noImplForAbstractMethod(m, current, baseClass
-                            .getName(), enhancedClass), specification.getLocation(), null);
+                    _errorLog.error(EnhanceMessages.noImplForAbstractMethod(
+                            m,
+                            current,
+                            baseClass,
+                            enhancedClass), location, null);
                 }
 
                 implementedMethods.add(s);
             }
 
-            // An earlier version of this code walked the interfaces directly,
-            // but it appears that implementing an interface actually
-            // puts abstract method declarations into the class
-            // (at least, in terms of what getDeclaredMethods() returns).
+            interfaceQueue.addAll(Arrays.asList(current.getInterfaces()));
 
-            // March up to the super class.
+            // Did an earlier JDK include methods from interfaces in
+            // getDeclaredMethods()? The old code here seemed to indicate
+            // that was the case, but it certainly is no longer, that's why
+            // we add all the interfaces to a queue to check after the rest.
 
             current = current.getSuperclass();
 
-            // Once advanced up to a concrete class, we trust that
-            // the compiler did its checking. Alternately, if
-            // we started on java.lang.Object for some reason, current
-            // will be null and we can stop.S
+            // We need to run straight to the top, to find all the implemented methods.
 
-            if (current == null || !Modifier.isAbstract(current.getModifiers()))
+            if (current == null)
                 break;
         }
 
+        while (!interfaceQueue.isEmpty())
+        {
+            Class thisInterface = (Class) interfaceQueue.remove(0);
+
+            checkAllInterfaceMethodsImplemented(
+                    thisInterface,
+                    baseClass,
+                    enhancedClass,
+                    implementedMethods,
+                    location);
+        }
+
+    }
+
+    private void checkAllInterfaceMethodsImplemented(Class interfaceClass, Class baseClass,
+            Class enhancedClass, Set implementedMethods, Location location)
+    {
+        // Get all methods defined by the interface, or its super-interfaces
+
+        Method[] methods = interfaceClass.getMethods();
+
+        for (int i = 0; i < methods.length; i++)
+        {
+            MethodSignature sig = new MethodSignature(methods[i]);
+
+            if (!implementedMethods.contains(sig))
+                _errorLog.error(EnhanceMessages.unimplementedInterfaceMethod(
+                        methods[i],
+                        baseClass,
+                        enhancedClass), location, null);
+        }
     }
 
     public void setErrorLog(ErrorLog errorLog)

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractBase.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractBase.java?rev=293093&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractBase.java
(added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractBase.java
Sun Oct  2 04:51:52 2005
@@ -0,0 +1,29 @@
+// Copyright 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.tapestry.enhance;
+
+/**
+ * Used by {@link org.apache.tapestry.enhance.EnhancedClassValidatorTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public abstract class AbstractBase
+{
+    public abstract void foo();
+}
\ No newline at end of file

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnable.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnable.java?rev=293093&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnable.java
(added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnable.java
Sun Oct  2 04:51:52 2005
@@ -0,0 +1,26 @@
+// Copyright 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.tapestry.enhance;
+
+/**
+ * Used by {@link org.apache.tapestry.enhance.EnhancedClassValidatorTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public abstract class AbstractRunnable implements Runnable
+{
+
+}

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnableSubclass.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnableSubclass.java?rev=293093&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnableSubclass.java
(added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/AbstractRunnableSubclass.java
Sun Oct  2 04:51:52 2005
@@ -0,0 +1,26 @@
+// Copyright 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.tapestry.enhance;
+
+/**
+ * Used by {@link org.apache.tapestry.enhance.EnhancedClassValidatorTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public abstract class AbstractRunnableSubclass extends AbstractRunnable
+{
+
+}

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Complete.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Complete.java?rev=293093&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Complete.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Complete.java Sun
Oct  2 04:51:52 2005
@@ -0,0 +1,32 @@
+// Copyright 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.tapestry.enhance;
+
+/**
+ * Used by {@link org.apache.tapestry.enhance.EnhancedClassValidatorTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public class Complete extends AbstractBase
+{
+    public void foo()
+    {
+        //
+    }
+}
\ No newline at end of file

Copied: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java
(from r292042, jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/TestEnhancedClassValidator.java)
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java?p2=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java&p1=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/TestEnhancedClassValidator.java&r1=292042&r2=293093&rev=293093&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/TestEnhancedClassValidator.java
(original)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java
Sun Oct  2 04:51:52 2005
@@ -15,10 +15,11 @@
 package org.apache.tapestry.enhance;
 
 import org.apache.hivemind.ErrorLog;
+import org.apache.hivemind.Locatable;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.spec.ComponentSpecification;
 import org.apache.tapestry.spec.IComponentSpecification;
-import org.easymock.MockControl;
 
 /**
  * Tests for {@link org.apache.tapestry.enhance.EnhancedClassValidatorImpl}.
@@ -26,29 +27,8 @@
  * @author Howard M. Lewis Ship
  * @since 4.0
  */
-public class TestEnhancedClassValidator extends HiveMindTestCase
+public class EnhancedClassValidatorTest extends HiveMindTestCase
 {
-    public static abstract class AbstractBase
-    {
-        public abstract void foo();
-    }
-
-    public static abstract class Incomplete extends AbstractBase
-    {
-        public void bar()
-        {
-            //
-        }
-    }
-
-    public static class Complete extends AbstractBase
-    {
-        public void foo()
-        {
-            //
-        }
-    }
-
     /**
      * Test for a class that fulfills its requirements (by implementing all inherited abstract
      * methods.
@@ -58,7 +38,7 @@
     {
         EnhancedClassValidator v = new EnhancedClassValidatorImpl();
 
-        v.validate(AbstractBase.class, Complete.class, null);
+        v.validate(AbstractBase.class, Complete.class, new ComponentSpecification());
     }
 
     /**
@@ -69,18 +49,18 @@
 
     public void testIncomplete()
     {
-        ErrorLog log = (ErrorLog) newMock(ErrorLog.class);
-        Location l = fabricateLocation(11);
+        ErrorLog log = newErrorLog();
+        Location l = newLocation();
 
-        MockControl specControl = newControl(IComponentSpecification.class);
-        IComponentSpecification spec = (IComponentSpecification) specControl.getMock();
+        IComponentSpecification spec = newSpec();
 
-        spec.getLocation();
-        specControl.setReturnValue(l);
+        trainGetLocation(spec, l);
 
         log
                 .error(
-                        "Method 'public abstract void org.apache.tapestry.enhance.TestEnhancedClassValidator$AbstractBase.foo()'
(declared in class org.apache.tapestry.enhance.TestEnhancedClassValidator$AbstractBase) has
no implementation in class org.apache.tapestry.enhance.TestEnhancedClassValidator$AbstractBase
(or enhanced subclass org.apache.tapestry.enhance.TestEnhancedClassValidator$Incomplete).",
+                        "Method 'public abstract void org.apache.tapestry.enhance.AbstractBase.foo()'
"
+                                + "(declared in class org.apache.tapestry.enhance.AbstractBase)
has no implementation in class "
+                                + "org.apache.tapestry.enhance.AbstractBase (or enhanced
subclass org.apache.tapestry.enhance.Incomplete).",
                         l,
                         null);
 
@@ -94,6 +74,49 @@
         verifyControls();
     }
 
+    public void testInheritsMissingMethod()
+    {
+        ErrorLog log = newErrorLog();
+        Location l = newLocation();
+
+        IComponentSpecification spec = newSpec();
+
+        trainGetLocation(spec, l);
+
+        log
+                .error(
+                        "Method 'public abstract void java.lang.Runnable.run()' "
+                                + "has no implementation in class org.apache.tapestry.enhance.AbstractRunnable
"
+                                + "(or enhanced subclass org.apache.tapestry.enhance.AbstractRunnableSubclass).",
+                        l,
+                        null);
+
+        replayControls();
+
+        EnhancedClassValidatorImpl v = new EnhancedClassValidatorImpl();
+        v.setErrorLog(log);
+
+        v.validate(AbstractRunnable.class, AbstractRunnableSubclass.class, spec);
+
+        verifyControls();
+    }
+
+    private void trainGetLocation(Locatable locatable, Location location)
+    {
+        locatable.getLocation();
+        setReturnValue(locatable, location);
+    }
+
+    private IComponentSpecification newSpec()
+    {
+        return (IComponentSpecification) newMock(IComponentSpecification.class);
+    }
+
+    private ErrorLog newErrorLog()
+    {
+        return (ErrorLog) newMock(ErrorLog.class);
+    }
+
     /**
      * Ensures that the code works when passed java.lang.Object (which has different inheritance
      * than other classes.
@@ -103,6 +126,6 @@
     {
         EnhancedClassValidator v = new EnhancedClassValidatorImpl();
 
-        v.validate(Object.class, Object.class, null);
+        v.validate(Object.class, Object.class, new ComponentSpecification());
     }
 }

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Incomplete.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Incomplete.java?rev=293093&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Incomplete.java
(added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/Incomplete.java
Sun Oct  2 04:51:52 2005
@@ -0,0 +1,32 @@
+// Copyright 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.tapestry.enhance;
+
+/**
+ * Used by {@link org.apache.tapestry.enhance.EnhancedClassValidatorTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public abstract class Incomplete extends AbstractBase
+{
+    public void bar()
+    {
+        //
+    }
+}
\ No newline at end of file

Modified: jakarta/tapestry/trunk/status.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Sun Oct  2 04:51:52 2005
@@ -51,7 +51,7 @@
   </todo>
   <changes>
     <release version="4.0-beta-10" date="unreleased">
-      
+      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-344">Unimplemented abstract
method check broken</action>      
     </release>
     <release version="4.0-beta-9" date="Oct 1 2005">
       <action type="fix" dev="DS" fixes-bug="TAPESTRY-663">Document Button component</action>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


Mime
View raw message