POLYGENE-120 : Rudimentary support for default interface methods.

Signed-off-by: niclas <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/7526b32f
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/7526b32f
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/7526b32f

Branch: refs/heads/develop
Commit: 7526b32f4988075a44c6438af63f7f59cfe14c0e
Parents: 4d81812
Author: niclas <[email protected]>
Authored: Sat May 13 10:03:01 2017 +0800
Committer: niclas <[email protected]>
Committed: Sun May 14 12:07:56 2017 +0800

----------------------------------------------------------------------
 .../bootstrap/CompositeAssemblyImpl.java        |  6 +-
 .../runtime/mixin/DefaultMethodsTest.java       | 64 ++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7526b32f/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java
----------------------------------------------------------------------
diff --git 
a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java
 
b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java
index 54c597b..4e173e4 100644
--- 
a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java
+++ 
b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java
@@ -326,8 +326,10 @@ public abstract class CompositeAssemblyImpl
         {
             return implementMethodWithClass( method, mixinClass );
         }
-
-        handleInvalidCompositeType( "No implementation found for method ", 
null, null, null, null, method, types );
+        if( !method.isDefault() )  // if it is NOT a default method in an 
interface, we don't have an implementation.
+        {
+            handleInvalidCompositeType( "No implementation found for method ", 
null, null, null, null, method, types );
+        }
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7526b32f/core/runtime/src/test/java/org/apache/polygene/runtime/mixin/DefaultMethodsTest.java
----------------------------------------------------------------------
diff --git 
a/core/runtime/src/test/java/org/apache/polygene/runtime/mixin/DefaultMethodsTest.java
 
b/core/runtime/src/test/java/org/apache/polygene/runtime/mixin/DefaultMethodsTest.java
new file mode 100644
index 0000000..5beb98f
--- /dev/null
+++ 
b/core/runtime/src/test/java/org/apache/polygene/runtime/mixin/DefaultMethodsTest.java
@@ -0,0 +1,64 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.polygene.runtime.mixin;
+
+import org.apache.polygene.api.property.Property;
+import org.apache.polygene.api.value.ValueBuilder;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.test.AbstractPolygeneTest;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Initial tests for interface default methods support.
+ */
+public class DefaultMethodsTest extends AbstractPolygeneTest
+{
+
+    @Override
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        module.values( Hello.class );
+    }
+
+    @Test
+    public void givenInterfaceWithDefaultMethodWhenCallingExpectSuccess()
+    {
+        ValueBuilder<Hello> builder = valueBuilderFactory.newValueBuilder( 
Hello.class );
+        Hello prototype = builder.prototype();
+        Property<String> phrase = prototype.phrase();
+        phrase.set( "Hello!" );
+        Hello hello = builder.newInstance();
+        assertThat( hello.phrase().get(), equalTo( "Hello!" ) );
+    }
+
+    //    @Mixins( { PropertyMixin.class, NoopMixin.class } )
+    interface Hello
+    {
+        Property<String> phrase();
+
+        default String speak()
+        {
+            return phrase().get();
+        }
+    }
+}

Reply via email to