polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject zest-java git commit: ZEST-193: support for Java 8 interface static methods
Date Sun, 20 Nov 2016 15:04:34 GMT
Repository: zest-java
Updated Branches:
  refs/heads/develop 9d3f380d7 -> 64d6d81ce


ZEST-193: support for Java 8 interface static methods

Basically, do not fail when resolving the usage graph on a composite
with interface static methods.


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/64d6d81c
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/64d6d81c
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/64d6d81c

Branch: refs/heads/develop
Commit: 64d6d81ce945434d908e1614ce05bc2c935e089f
Parents: 9d3f380
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sun Nov 20 16:04:00 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sun Nov 20 16:04:00 2016 +0100

----------------------------------------------------------------------
 .../zest/runtime/composite/MixinsModel.java     |  7 ++-
 .../composite/InterfaceStaticMethodsTest.java   | 60 ++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/64d6d81c/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
index 48fd39c..a34fecc 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
@@ -21,6 +21,7 @@
 package org.apache.zest.runtime.composite;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -236,7 +237,11 @@ public class MixinsModel
             {
                 for( Method method : thisMixinType.getMethods() )
                 {
-                    usedMixinClasses.add( methodImplementation.get( method ) );
+                    if( !Modifier.isStatic( method.getModifiers() ) )
+                    {
+                        MixinModel used = methodImplementation.get( method );
+                        usedMixinClasses.add( used );
+                    }
                 }
             }
             return usedMixinClasses;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/64d6d81c/core/runtime/src/test/java/org/apache/zest/runtime/composite/InterfaceStaticMethodsTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/composite/InterfaceStaticMethodsTest.java
b/core/runtime/src/test/java/org/apache/zest/runtime/composite/InterfaceStaticMethodsTest.java
new file mode 100644
index 0000000..12afc55
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/zest/runtime/composite/InterfaceStaticMethodsTest.java
@@ -0,0 +1,60 @@
+package org.apache.zest.runtime.composite;
+
+import org.apache.zest.api.common.UseDefaults;
+import org.apache.zest.api.property.Property;
+import org.apache.zest.bootstrap.AssemblyException;
+import org.apache.zest.bootstrap.ModuleAssembly;
+import org.apache.zest.test.AbstractZestTest;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Assert that interface static methods are ignored when assembling composites.
+ */
+public class InterfaceStaticMethodsTest extends AbstractZestTest
+{
+    public interface StaticMethods
+    {
+        @UseDefaults( "foo" )
+        Property<String> foo();
+
+        static String bar()
+        {
+            return "bar";
+        }
+    }
+
+    public interface OverrideStaticMethods extends StaticMethods
+    {
+        static String bar()
+        {
+            return "bar overridden";
+        }
+    }
+
+    @Override
+    public void assemble( final ModuleAssembly module ) throws AssemblyException
+    {
+        module.transients( StaticMethods.class, OverrideStaticMethods.class );
+    }
+
+    @Test
+    public void staticMethods() throws NoSuchMethodException
+    {
+        StaticMethods staticMethods = transientBuilderFactory.newTransient( StaticMethods.class
);
+
+        assertThat( staticMethods.foo().get(), equalTo( "foo" ) );
+        assertThat( StaticMethods.bar(), equalTo( "bar" ) );
+    }
+
+    @Test
+    public void overrideStaticMethods()
+    {
+        OverrideStaticMethods staticMethods = transientBuilderFactory.newTransient( OverrideStaticMethods.class
);
+
+        assertThat( staticMethods.foo().get(), equalTo( "foo" ) );
+        assertThat( OverrideStaticMethods.bar(), equalTo( "bar overridden" ) );
+    }
+}


Mime
View raw message