Skip to content
Snippets Groups Projects
Commit 236cf3e6 authored by Tomas Stupka's avatar Tomas Stupka
Browse files

[GR-3140] Support for rJava-style interoperability in FastR.

parents c5233106 826c40a7
No related branches found
No related tags found
No related merge requests found
# Generated by roxygen2: do not edit by hand
export(.jaddClassPath)
export(.jarray)
export(.jbyte)
export(.jcall)
......@@ -12,5 +13,7 @@ export(.jinit)
export(.jlong)
export(.jnew)
export(.jnull)
export(.jpackage)
export(.jshort)
export(.jsimplify)
export(J)
......@@ -24,6 +24,7 @@
simplify = FALSE, use.true.class = FALSE)
{
if(is.character(obj)) {
obj <- gsub("/", ".", as.character(obj))
co <- .fastr.java.class(obj)
r <- co[method](...)
} else {
......@@ -91,6 +92,18 @@
invisible(x)
}
#' @export
J <- function (class, method, ...)
{
class <- gsub("/", ".", as.character(class))
javaClass <- .fastr.java.class(class)
if (nargs() == 1L && missing(method)) {
javaClass
} else {
.jcall(javaClass, ,method, ...)
}
}
#
# noop stubs
#
......@@ -117,3 +130,31 @@
{
# do nothing
}
#' @export
.jpackage <- function (name, jars='*', morePaths='', nativeLibrary=FALSE, lib.loc=NULL)
{
javalibs <- system.file("java", package = name, lib.loc = lib.loc)
if(javalibs == "") {
javalibs = paste0("library/", name, "/java")
}
cat(paste0("********************************************************\n",
"*** WARNING!!!\n",
"*** .jpackage is not yet implemented.\n",
"*** Please ensure that all java libraries from:\n",
"*** ", javalibs, "\n",
"*** are on FastR classpath\n",
"********************************************************\n"))
}
#' @export
.jaddClassPath <- function (path)
{
cat(paste0("********************************************************\n",
"*** WARNING!!!\n",
"*** .jaddClasPath is not yet implemented.\n",
"*** Please ensure that \n",
"*** ", path, "\n",
"*** is on FastR classpath\n",
"********************************************************\n"))
}
\ No newline at end of file
# prerequisites:
# - 'testthat' package has to be installed: install.packages("testthat")
# - FastR`s rJava package has to be installed: bin/r CMD INSTALL com.oracle.truffle.r.pkgs/rjava
# - mxbuild/dists/fastr-unit-tests.jar has to be on FastR classpath
library(testthat)
library(rJava)
testName <- "test J function"
test_that(testName, {
cat(paste0(testName, "\n"))
tc <- J("com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass")
expect_equal(2147483647L, tc$fieldStaticInteger)
tc <- J("com/oracle/truffle/r/test/library/fastr/TestJavaInterop$TestClass")
expect_equal(2147483647L, tc$fieldStaticInteger)
expect_equal(2147483647L, J("com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass", "methodStaticInteger"))
expect_equal(2147483647L, J("com/oracle/truffle/r/test/library/fastr/TestJavaInterop$TestClass", "methodStaticInteger"))
})
......@@ -445,24 +445,24 @@ public class TestJavaInterop extends TestBase {
public static class TestClass {
public static boolean fieldStaticBoolean;
public static byte fieldStaticByte;
public static char fieldStaticChar;
public static short fieldStaticShort;
public static int fieldStaticInteger;
public static long fieldStaticLong;
public static double fieldStaticDouble;
public static float fieldStaticFloat;
public static Boolean fieldStaticBooleanObject;
public static Byte fieldStaticByteObject;
public static Character fieldStaticCharObject;
public static Short fieldStaticShortObject;
public static Integer fieldStaticIntegerObject;
public static Long fieldStaticLongObject;
public static Double fieldStaticDoubleObject;
public static Float fieldStaticFloatObject;
public static String fieldStaticStringObject;
public static boolean fieldStaticBoolean = true;
public static byte fieldStaticByte = Byte.MAX_VALUE;
public static char fieldStaticChar = 'a';
public static short fieldStaticShort = Short.MAX_VALUE;
public static int fieldStaticInteger = Integer.MAX_VALUE;
public static long fieldStaticLong = Long.MAX_VALUE;
public static double fieldStaticDouble = Double.MAX_VALUE;
public static float fieldStaticFloat = Float.MAX_VALUE;
public static Boolean fieldStaticBooleanObject = fieldStaticBoolean;
public static Byte fieldStaticByteObject = fieldStaticByte;
public static Character fieldStaticCharObject = fieldStaticChar;
public static Short fieldStaticShortObject = fieldStaticShort;
public static Integer fieldStaticIntegerObject = fieldStaticInteger;
public static Long fieldStaticLongObject = fieldStaticLong;
public static Double fieldStaticDoubleObject = fieldStaticDouble;
public static Float fieldStaticFloatObject = fieldStaticFloat;
public static String fieldStaticStringObject = "a string";
public boolean fieldBoolean;
public byte fieldByte;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment