commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r790197 - in /commons/sandbox/runtime/trunk/src: main/native/include/acr_clazz.h main/native/shared/clazz.c main/native/test/testcase.c test/org/apache/commons/runtime/TestPrivate.java
Date Wed, 01 Jul 2009 14:48:15 GMT
Author: mturk
Date: Wed Jul  1 14:48:15 2009
New Revision: 790197

URL: http://svn.apache.org/viewvc?rev=790197&view=rev
Log:
Add Class getname API

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h?rev=790197&r1=790196&r2=790197&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h Wed Jul  1 14:48:15
2009
@@ -115,6 +115,14 @@
  */
 ACR_DECLARE(int) ACR_ClassGetFlags(JNIEnv *env, jobject obj);
 
+/**
+ * Get the Class name.
+ * @param env Current JNI environment.
+ * @param obj Class to use.
+ * @param simple If non-zero use getSimpleName instead getName
+ */
+ACR_DECLARE(char *) ACR_ClassGetName(JNIEnv *env, jobject obj, int simple);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=790197&r1=790196&r2=790197&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Wed Jul  1 14:48:15 2009
@@ -437,6 +437,24 @@
     return flags;
 }
 
+ACR_DECLARE(char *) ACR_ClassGetName(ACR_JNISTDARGS, int simple)
+{
+    char *name = NULL;
+    if (IS_JOBJECT_NULL(_E, _O))
+        return NULL;
+
+    if (_clazzn.i && J4MID(0000)) {
+        jstring sn;
+        if (simple)
+             sn = CALL_METHOD0(Object, 0001, _O);
+        else
+             sn = CALL_METHOD0(Object, 0000, _O);
+        if (sn)
+            name = ACR_GetJavaStringA(_E, sn, NULL);
+    }
+    return name;
+}
+
 #ifdef ACR_ENABLE_TEST
 /* Just for testing the cache table */
 int acr_clazz_cache_size()

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=790197&r1=790196&r2=790197&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Jul  1 14:48:15 2009
@@ -381,6 +381,18 @@
     return ACR_ClassGetFlags(_E, c);
 }
 
+ACR_JNI_EXPORT_DECLARE(jstring, TestPrivate, test036)(ACR_JNISTDARGS, jobject c)
+{
+    char *n;
+    jstring r = NULL;
+    n = ACR_ClassGetName(_E, c, 0);
+    if (n) {
+        r = ACR_NewJavaStringA(_E, n);
+        free(n);
+    }
+    return r;
+}
+
 ACR_JNI_EXPORT_DECLARE(jint, TestFile, ftest00)(ACR_JNISTDARGS, jint d)
 {
     return ldfile(_E);

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=790197&r1=790196&r2=790197&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Wed
Jul  1 14:48:15 2009
@@ -85,6 +85,7 @@
     private static native int      test033(int d);
     private static native int      test034(Descriptor p);
     private static native int      test035(Class c);
+    private static native String   test036(Class c);
 
 
     private static native String test100(String s);
@@ -272,6 +273,14 @@
         assertEquals("Flags", 4, i);
     }
 
+    public void testClassGetName()
+        throws Exception
+    {
+        String[] s = new String[2];
+        String   n = test036(s.getClass());
+        assertEquals("Name", s.getClass().getName(), n);
+    }
+
     public void testPointerCb()
         throws Throwable
     {



Mime
View raw message