contrib/jwrapper examples: intro an example using the standard Java API
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 28 Jul 2015 21:51:24 +0000 (17:51 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 29 Jul 2015 19:08:58 +0000 (15:08 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/Makefile
contrib/jwrapper/examples/java_api/.gitignore [new file with mode: 0644]
contrib/jwrapper/examples/java_api/Makefile [new file with mode: 0644]
contrib/jwrapper/examples/java_api/api_user.nit [new file with mode: 0644]
contrib/jwrapper/examples/java_api/api_user.sav [new file with mode: 0644]

index ceb9722..3c96127 100644 (file)
@@ -62,3 +62,4 @@ check-libs: bin/jwrapper
        nitpick tests/sablecc.nit
 
        make -C examples/android_api/ check
+       make -C examples/java_api/ check
diff --git a/contrib/jwrapper/examples/java_api/.gitignore b/contrib/jwrapper/examples/java_api/.gitignore
new file mode 100644 (file)
index 0000000..f2f6834
--- /dev/null
@@ -0,0 +1,5 @@
+java_api.nit
+api_user
+api_user.res
+api_user.jar
+tmp/
diff --git a/contrib/jwrapper/examples/java_api/Makefile b/contrib/jwrapper/examples/java_api/Makefile
new file mode 100644 (file)
index 0000000..ee6846b
--- /dev/null
@@ -0,0 +1,26 @@
+RT_JAR ?= /usr/lib/jvm/default-java/jre/lib/rt.jar
+
+all: api_user
+
+java_api.nit:
+       mkdir -p tmp
+       ../../bin/jwrapper -vv -u comment -o 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`"
+
+api_user: java_api.nit
+       # Using --semi-global makes it much faster
+       time -f "%E k:%S u:%U" ../../../../bin/nitc -v api_user.nit --semi-global
+
+check: api_user
+       ./api_user > api_user.res
+       diff api_user.sav api_user.res
+
+check-generated-java: java_api.nit
+       # This may take a while...
+       time -f "%E k:%S u:%U" ../../../../bin/nitc -v api_user.nit --no-cc
+
+       # Don't compile the C only the Java
+       make -C nit_compile Nit_rt.class
+
+.PHONY: api_user java_api.nit
diff --git a/contrib/jwrapper/examples/java_api/api_user.nit b/contrib/jwrapper/examples/java_api/api_user.nit
new file mode 100644 (file)
index 0000000..b0f5a0c
--- /dev/null
@@ -0,0 +1,34 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# 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.
+
+import java_api
+
+# Get a Java string
+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
+
+# Test a generic list
+var list = new Java_util_ArrayList
+
+print list.is_empty
+assert list.is_empty
+
+print list.size
+assert list.size == 0
+
+list.clear
diff --git a/contrib/jwrapper/examples/java_api/api_user.sav b/contrib/jwrapper/examples/java_api/api_user.sav
new file mode 100644 (file)
index 0000000..86d17d1
--- /dev/null
@@ -0,0 +1,4 @@
+1234
+5678
+true
+0