Merge: Android annotations and longs
authorJean Privat <jean@pryen.org>
Wed, 30 Jul 2014 18:08:56 +0000 (14:08 -0400)
committerJean Privat <jean@pryen.org>
Wed, 30 Jul 2014 18:08:56 +0000 (14:08 -0400)
Fixes #621 and problems with annotations priority.

The new organization of mnit_simple, and its annotations, means that you can compile any of the test_*.nit and it will create a `.apk` with a distinct package. Thus they can be installed side by side, but they all have the same display name :(

Using Java `long` on Android works again, but they are not fully compatible with Nit's `Int`. Java's `long` are on 64 bits, and Nit's `Int` on 32 bit under ARM. There may be data loss.

Pull-Request: #629
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

examples/mnit_simple/src/complete_simple_android.nit
examples/mnit_simple/src/simple.nit
examples/mnit_simple/src/simple_android.nit
src/android_annotations.nit
src/common_ffi/java.nit
tests/sav/test_ffi_java_minimal.res
tests/test_ffi_java_minimal.nit

index 57eead6..9ee8b06 100644 (file)
@@ -1,8 +1,21 @@
-#FIXME: Improper way of resolving unjustified metadata conflict
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
+#
+# 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.
+
 module complete_simple_android is
-    app_name("test all")
        java_package("org.nitlanguage.test_all")
-       app_version(1, 0)
 end
 
 import test_bundle
index dd6f65d..6bfc9b1 100644 (file)
@@ -16,7 +16,7 @@
 
 # Very simple application
 module simple is
-       app_name("mnit Simple example")
+       app_name("mnit Simple example") # On Android, this name is hidden by the value in `res/values/strings.xml`
        app_version(0, 2, git_revision)
 end
 
index d92ecc6..833d832 100644 (file)
@@ -15,7 +15,6 @@
 # limitations under the License.
 
 module simple_android is
-       java_package("org.nitlanguage.simple")
        android_manifest("""<uses-permission android:name="android.permission.VIBRATE" />""")
 end
 
index cad98bd..7e9f43a 100644 (file)
@@ -133,21 +133,21 @@ redef class ModelBuilder
                        end
                end
 
-               var sources = new Array[MModule]
-               var annotations = null
+               var annotations = new HashSet[AAnnotation]
                for mmod in mmodule.in_importation.direct_greaters do
                        var res = priority_annotation_on_modules(name, mmod)
-                       if res != null then
-                               sources.add mmod
-                               annotations = res
-                       end
+                       if res != null then annotations.add res
                end
-               if sources.length > 1 then
+               if annotations.length > 1 then
+                       var locs = new Array[Location]
+                       for annot in annotations do locs.add(annot.location)
+
                        toolcontext.error(mmodule.location,
-                               "Priority conflict on annotation {name}, it has been defined in: {sources.join(", ")}")
+                               "Priority conflict on annotation {name}, it has been defined in: {locs.join(", ")}")
                        return null
-               end
-               return annotations
+               else if annotations.length == 1 then
+                       return annotations.first
+               else return null
        end
 end
 
index eefb5c6..a43cab6 100644 (file)
@@ -119,7 +119,11 @@ class JavaLanguage
                        end
                end
 
-               for p in signature.mparameters do params.add(p.name)
+               for p in signature.mparameters do
+                       var param_mtype = p.mtype
+                       param_mtype = param_mtype.resolve_for(mclass_type, mclass_type, mmodule, true)
+                       params.add(to_java_call_context.cast_to(param_mtype, p.name))
+               end
 
                var cname = "(*nit_ffi_jni_env)->CallStatic{jni_signature_alt}Method"
                var ccall
index 3705de2..3c80b7c 100644 (file)
@@ -21,6 +21,12 @@ class MyClass
        fun foo in "Java" `{
                System.out.println("Hello world");
        `}
+
+       fun bar(i: Int) in "Java" `{
+               System.out.println(i);
+       `}
 end
 
-(new MyClass).foo
+var a = new MyClass
+a.foo
+a.bar(777)