From 1991707066f15145c445d58873df1b159f765854 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Tue, 28 Jul 2015 17:51:24 -0400 Subject: [PATCH] contrib/jwrapper examples: intro an example using the standard Java API MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/jwrapper/Makefile | 1 + contrib/jwrapper/examples/java_api/.gitignore | 5 ++++ contrib/jwrapper/examples/java_api/Makefile | 26 +++++++++++++++++ contrib/jwrapper/examples/java_api/api_user.nit | 34 +++++++++++++++++++++++ contrib/jwrapper/examples/java_api/api_user.sav | 4 +++ 5 files changed, 70 insertions(+) create mode 100644 contrib/jwrapper/examples/java_api/.gitignore create mode 100644 contrib/jwrapper/examples/java_api/Makefile create mode 100644 contrib/jwrapper/examples/java_api/api_user.nit create mode 100644 contrib/jwrapper/examples/java_api/api_user.sav diff --git a/contrib/jwrapper/Makefile b/contrib/jwrapper/Makefile index ceb9722..3c96127 100644 --- a/contrib/jwrapper/Makefile +++ b/contrib/jwrapper/Makefile @@ -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 index 0000000..f2f6834 --- /dev/null +++ b/contrib/jwrapper/examples/java_api/.gitignore @@ -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 index 0000000..ee6846b --- /dev/null +++ b/contrib/jwrapper/examples/java_api/Makefile @@ -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 index 0000000..b0f5a0c --- /dev/null +++ b/contrib/jwrapper/examples/java_api/api_user.nit @@ -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 index 0000000..86d17d1 --- /dev/null +++ b/contrib/jwrapper/examples/java_api/api_user.sav @@ -0,0 +1,4 @@ +1234 +5678 +true +0 -- 1.7.9.5