2006-07-15 Andrew John Hughes <gnu_andrew@member.fsf.org>
[official-gcc.git] / libjava / java / lang / reflect / natConstructor.cc
blobd04031f8d4b27ef1218ff0f88f94d7884e03408a
1 // natConstructor.cc - Native code for Constructor class.
3 /* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #include <config.h>
13 #include <gcj/cni.h>
14 #include <jvm.h>
15 #include <java-stack.h>
17 #include <java/lang/ArrayIndexOutOfBoundsException.h>
18 #include <java/lang/IllegalAccessException.h>
19 #include <java/lang/reflect/Constructor.h>
20 #include <java/lang/reflect/Method.h>
21 #include <java/lang/reflect/InvocationTargetException.h>
22 #include <java/lang/reflect/Modifier.h>
23 #include <java/lang/InstantiationException.h>
24 #include <gcj/method.h>
26 typedef JArray< ::java::lang::annotation::Annotation * > * anno_a_t;
27 typedef JArray< JArray< ::java::lang::annotation::Annotation * > *> * anno_aa_t;
29 jint
30 java::lang::reflect::Constructor::getModifiersInternal ()
32 return _Jv_FromReflectedConstructor (this)->accflags;
35 jstring
36 java::lang::reflect::Constructor::getSignature()
38 return declaringClass->getReflectionSignature (this);
41 anno_a_t
42 java::lang::reflect::Constructor::getDeclaredAnnotationsInternal()
44 anno_a_t result;
45 return (anno_a_t) declaringClass->getDeclaredAnnotations(this, false);
48 anno_aa_t
49 java::lang::reflect::Constructor::getParameterAnnotationsInternal()
51 anno_aa_t result;
52 return (anno_aa_t) declaringClass->getDeclaredAnnotations(this, true);
55 void
56 java::lang::reflect::Constructor::getType ()
58 _Jv_GetTypesFromSignature (_Jv_FromReflectedConstructor (this),
59 declaringClass,
60 &parameter_types,
61 NULL);
63 // FIXME: for now we have no way to get exception information.
64 exception_types =
65 (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$, NULL);
68 jobject
69 java::lang::reflect::Constructor::newInstance (jobjectArray args)
71 using namespace java::lang::reflect;
73 if (parameter_types == NULL)
74 getType ();
76 jmethodID meth = _Jv_FromReflectedConstructor (this);
78 // Check accessibility, if required.
79 if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
81 Class *caller = _Jv_StackTrace::GetCallingClass (&Constructor::class$);
82 if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
83 throw new IllegalAccessException;
86 if (Modifier::isAbstract (declaringClass->getModifiers()))
87 throw new InstantiationException;
89 _Jv_InitClass (declaringClass);
91 // In the constructor case the return type is the type of the
92 // constructor.
93 return _Jv_CallAnyMethodA (NULL, declaringClass, meth, true,
94 parameter_types, args);