LCOV - code coverage report
Current view: top level - native/vm/gnuclasspath - java_lang_reflect_VMConstructor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 48 75.0 %
Date: 2015-06-10 18:10:59 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /* src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp
       2             : 
       3             :    Copyright (C) 1996-2013
       4             :    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
       5             : 
       6             :    This file is part of CACAO.
       7             : 
       8             :    This program is free software; you can redistribute it and/or
       9             :    modify it under the terms of the GNU General Public License as
      10             :    published by the Free Software Foundation; either version 2, or (at
      11             :    your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful, but
      14             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :    General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program; if not, write to the Free Software
      20             :    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
      21             :    02110-1301, USA.
      22             : 
      23             : */
      24             : 
      25             : 
      26             : #include "config.h"
      27             : 
      28             : #include <assert.h>
      29             : #include <stdlib.h>
      30             : 
      31             : #include "native/jni.hpp"
      32             : #include "native/llni.hpp"
      33             : #include "native/native.hpp"
      34             : 
      35             : #if defined(ENABLE_JNI_HEADERS)
      36             : # include "native/vm/include/java_lang_reflect_VMConstructor.h"
      37             : #endif
      38             : 
      39             : #include "native/vm/reflection.hpp"
      40             : 
      41             : #include "vm/javaobjects.hpp"
      42             : #include "vm/string.hpp"
      43             : #include "vm/utf8.hpp"
      44             : #include "vm/vm.hpp"
      45             : 
      46             : 
      47             : // Native functions are exported as C functions.
      48             : extern "C" {
      49             : 
      50             : /*
      51             :  * Class:     java/lang/reflect/VMConstructor
      52             :  * Method:    getModifiersInternal
      53             :  * Signature: ()I
      54             :  */
      55         320 : JNIEXPORT jint JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, jobject _this)
      56             : {
      57         320 :         java_lang_reflect_VMConstructor rvmc(_this);
      58         320 :         methodinfo* m = rvmc.get_method();
      59         320 :         return m->flags;
      60             : }
      61             : 
      62             : 
      63             : /*
      64             :  * Class:     java/lang/reflect/VMConstructor
      65             :  * Method:    getParameterTypes
      66             :  * Signature: ()[Ljava/lang/Class;
      67             :  */
      68         468 : JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, jobject _this)
      69             : {
      70         468 :         java_lang_reflect_VMConstructor rvmc(_this);
      71         468 :         methodinfo* m = rvmc.get_method();
      72             : 
      73         468 :         java_handle_objectarray_t* hoa = method_get_parametertypearray(m);
      74             : 
      75         468 :         return (jobjectArray) hoa;
      76             : }
      77             : 
      78             : 
      79             : /*
      80             :  * Class:     java/lang/reflect/VMConstructor
      81             :  * Method:    getExceptionTypes
      82             :  * Signature: ()[Ljava/lang/Class;
      83             :  */
      84           0 : JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, jobject _this)
      85             : {
      86           0 :         java_lang_reflect_VMConstructor rvmc(_this);
      87           0 :         methodinfo* m = rvmc.get_method();
      88             : 
      89           0 :         java_handle_objectarray_t* hoa = method_get_exceptionarray(m);
      90             : 
      91           0 :         return (jobjectArray) hoa;
      92             : }
      93             : 
      94             : 
      95             : /*
      96             :  * Class:     java/lang/reflect/VMConstructor
      97             :  * Method:    construct
      98             :  * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
      99             :  */
     100         468 : JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, jobject _this, jobjectArray args)
     101             : {
     102         468 :         java_lang_reflect_VMConstructor jlrvmc(_this);
     103         468 :         java_lang_reflect_Constructor jlrc(jlrvmc.get_cons());
     104             : 
     105         468 :         java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args);
     106             : 
     107         468 :         return (jobject) o;
     108             : }
     109             : 
     110             : 
     111             : /*
     112             :  * Class:     java/lang/reflect/VMConstructor
     113             :  * Method:    getSignature
     114             :  * Signature: ()Ljava/lang/String;
     115             :  */
     116           0 : JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, jobject _this)
     117             : {
     118           0 :         java_lang_reflect_VMConstructor rvmc(_this);
     119           0 :         methodinfo* m = rvmc.get_method();
     120             :         java_handle_t *o;
     121             : 
     122           0 :         if (m->signature == NULL)
     123           0 :                 return NULL;
     124             : 
     125           0 :         o = JavaString::from_utf8(m->signature);
     126             : 
     127             :         /* In error case o is NULL. */
     128             : 
     129           0 :         return (jstring) o;
     130             : }
     131             : 
     132             : 
     133             : #if defined(ENABLE_ANNOTATIONS)
     134             : /*
     135             :  * Class:     java/lang/reflect/VMConstructor
     136             :  * Method:    declaredAnnotations
     137             :  * Signature: ()Ljava/util/Map;
     138             :  *
     139             :  * Parses the annotations (if they aren't parsed yet) and stores them into
     140             :  * the declaredAnnotations map and return this map.
     141             :  */
     142           6 : JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, jobject _this)
     143             : {
     144           6 :         java_lang_reflect_VMConstructor rvmc(_this);
     145             : 
     146           6 :         java_handle_t* declaredAnnotations = rvmc.get_declaredAnnotations();
     147             : 
     148             :         /* are the annotations parsed yet? */
     149           6 :         if (declaredAnnotations == NULL) {
     150           2 :                 java_handle_bytearray_t* annotations    = rvmc.get_annotations();
     151           2 :                 classinfo*               declaringClass = rvmc.get_clazz();
     152           2 :                 classinfo*               referer        = rvmc.get_Class();
     153             : 
     154           2 :                 declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer);
     155             : 
     156           2 :                 rvmc.set_declaredAnnotations(declaredAnnotations);
     157             :         }
     158             : 
     159           6 :         return (jobject) declaredAnnotations;
     160             : }
     161             : 
     162             : 
     163             : /*
     164             :  * Class:     java/lang/reflect/VMConstructor
     165             :  * Method:    getParameterAnnotations
     166             :  * Signature: ()[[Ljava/lang/annotation/Annotation;
     167             :  *
     168             :  * Parses the parameter annotations and returns them in an 2 dimensional array.
     169             :  */
     170           2 : JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, jobject _this)
     171             : {
     172           2 :         java_lang_reflect_VMConstructor rvmc(_this);
     173             : 
     174           2 :         java_handle_bytearray_t* parameterAnnotations = rvmc.get_parameterAnnotations();
     175           2 :         methodinfo* m = rvmc.get_method();
     176           2 :         classinfo* referer = rvmc.get_Class();
     177             : 
     178           2 :         java_handle_objectarray_t* oa = Reflection::get_parameterannotations(parameterAnnotations, m, referer);
     179             : 
     180           2 :         return (jobjectArray) oa;
     181             : }
     182             : #endif
     183             : 
     184             : } // extern "C"
     185             : 
     186             : 
     187             : /* native methods implemented by this file ************************************/
     188             : 
     189             : static JNINativeMethod methods[] = {
     190             :         { (char*) "getModifiersInternal",    (char*) "()I",                                     (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal    },
     191             :         { (char*) "getParameterTypes",       (char*) "()[Ljava/lang/Class;",                    (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes       },
     192             :         { (char*) "getExceptionTypes",       (char*) "()[Ljava/lang/Class;",                    (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes       },
     193             :         { (char*) "construct",               (char*) "([Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_construct               },
     194             :         { (char*) "getSignature",            (char*) "()Ljava/lang/String;",                    (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getSignature            },
     195             : #if defined(ENABLE_ANNOTATIONS)
     196             :         { (char*) "declaredAnnotations",     (char*) "()Ljava/util/Map;",                       (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations     },
     197             :         { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;",   (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations },
     198             : #endif
     199             : };
     200             : 
     201             : 
     202             : /* _Jv_java_lang_reflect_VMConstructor_init ************************************
     203             : 
     204             :    Register native functions.
     205             : 
     206             : *******************************************************************************/
     207             : 
     208         163 : void _Jv_java_lang_reflect_VMConstructor_init(void)
     209             : {
     210         163 :         Utf8String u = Utf8String::from_utf8("java/lang/reflect/VMConstructor");
     211             : 
     212         163 :         NativeMethods& nm = VM::get_current()->get_nativemethods();
     213         163 :         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
     214         163 : }
     215             : 
     216             : 
     217             : /*
     218             :  * These are local overrides for various environment variables in Emacs.
     219             :  * Please do not remove this and leave it at the end of the file, where
     220             :  * Emacs will automagically detect them.
     221             :  * ---------------------------------------------------------------------
     222             :  * Local variables:
     223             :  * mode: c++
     224             :  * indent-tabs-mode: t
     225             :  * c-basic-offset: 4
     226             :  * tab-width: 4
     227             :  * End:
     228             :  */

Generated by: LCOV version 1.11