contrib/jwrapper examples: update java_api to benefit from polymorphism
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 1 Aug 2015 13:26:36 +0000 (09:26 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 5 Aug 2015 01:41:51 +0000 (21:41 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/examples/java_api/Makefile
contrib/jwrapper/examples/java_api/api_user.nit
contrib/jwrapper/examples/java_api/api_user.sav

index a98f013..3acbfc9 100644 (file)
@@ -16,16 +16,19 @@ check: api_user
        ./api_user > api_user.res
        diff api_user.sav api_user.res
 
-check-more-java:
+full_java_api.nit:
        mkdir -p tmp
-       ../../bin/jwrapper -vv -u comment -o java_api.nit $(RT_JAR) \
+       ../../bin/jwrapper -vv -u comment -o full_java_api.nit $(RT_JAR) \
                -r "^(java|org)" -i ../../../../lib/java/collections.nit
        echo "+ Disabled functions: `grep '#\s*fun' $@ | wc -l` / `grep '^\s*fun' $@ | wc -l`"
 
+       # Force compilation of the Java code
+       echo 'fun foo in "Java" `{  `}; foo' >> full_java_api.nit
+
        # This may take a while...
-       time -f "%E k:%S u:%U" ../../../../bin/nitc -v api_user.nit --no-cc
+       time -f "%E k:%S u:%U" ../../../../bin/nitc -v full_java_api.nit --no-cc
 
-       # Don't compile the C only the Java
-       make -C nit_compile Nit_rt.class
+       # Don't compile the C, only the Java
+       make -C nit_compile Nit_full_java_api.class
 
 .PHONY: api_user java_api.nit
index b0f5a0c..a06bf95 100644 (file)
@@ -18,17 +18,22 @@ import java_api
 var str = java_lang_integer_to_string_int(5678)
 
 # Do some Java side printing
-var stdout = java_lang_system_out
-stdout.println_int 1234
-stdout.println_String str
+java_lang_system_out.println_int 1234
+java_lang_system_out.println_String str
 
 # Test a generic list
 var list = new Java_util_ArrayList
 
-print list.is_empty
-assert list.is_empty
+print "List is empty? {list.is_empty}"
+print "List size {list.size}"
 
-print list.size
-assert list.size == 0
+list.add str
+print "List is empty? {list.is_empty}"
+print "List size {list.size}"
+
+var str_back = list.get(0)
+java_lang_system_out.println_String str_back.to_string
 
 list.clear
+print "List is empty? {list.is_empty}"
+print "List size {list.size}"
index 86d17d1..fc0b3bd 100644 (file)
@@ -1,4 +1,9 @@
 1234
 5678
-true
-0
+List is empty? true
+List size 0
+List is empty? false
+List size 1
+5678
+List is empty? true
+List size 0