natConstructor.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // natConstructor.cc - Native code for Constructor class.
  2. /* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. #include <config.h>
  8. #include <gcj/cni.h>
  9. #include <jvm.h>
  10. #include <java-stack.h>
  11. #include <java/lang/ArrayIndexOutOfBoundsException.h>
  12. #include <java/lang/IllegalAccessException.h>
  13. #include <java/lang/reflect/Constructor.h>
  14. #include <java/lang/reflect/Method.h>
  15. #include <java/lang/reflect/InvocationTargetException.h>
  16. #include <java/lang/reflect/Modifier.h>
  17. #include <java/lang/InstantiationException.h>
  18. #include <gcj/method.h>
  19. typedef JArray< ::java::lang::annotation::Annotation * > * anno_a_t;
  20. typedef JArray< JArray< ::java::lang::annotation::Annotation * > *> * anno_aa_t;
  21. jint
  22. java::lang::reflect::Constructor::getModifiersInternal ()
  23. {
  24. return _Jv_FromReflectedConstructor (this)->accflags;
  25. }
  26. jstring
  27. java::lang::reflect::Constructor::getSignature()
  28. {
  29. return declaringClass->getReflectionSignature (this);
  30. }
  31. anno_a_t
  32. java::lang::reflect::Constructor::getDeclaredAnnotationsInternal()
  33. {
  34. return (anno_a_t) declaringClass->getDeclaredAnnotations(this, false);
  35. }
  36. anno_aa_t
  37. java::lang::reflect::Constructor::getParameterAnnotationsInternal()
  38. {
  39. return (anno_aa_t) declaringClass->getDeclaredAnnotations(this, true);
  40. }
  41. void
  42. java::lang::reflect::Constructor::getType ()
  43. {
  44. _Jv_GetTypesFromSignature (_Jv_FromReflectedConstructor (this),
  45. declaringClass,
  46. &parameter_types,
  47. NULL);
  48. // FIXME: for now we have no way to get exception information.
  49. exception_types =
  50. (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$, NULL);
  51. }
  52. jobject
  53. java::lang::reflect::Constructor::newInstance (jobjectArray args)
  54. {
  55. using namespace java::lang::reflect;
  56. if (parameter_types == NULL)
  57. getType ();
  58. jmethodID meth = _Jv_FromReflectedConstructor (this);
  59. // Check accessibility, if required.
  60. if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
  61. {
  62. Class *caller = _Jv_StackTrace::GetCallingClass (&Constructor::class$);
  63. if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
  64. throw new IllegalAccessException;
  65. }
  66. if (Modifier::isAbstract (declaringClass->getModifiers()))
  67. throw new InstantiationException;
  68. _Jv_InitClass (declaringClass);
  69. // In the constructor case the return type is the type of the
  70. // constructor.
  71. return _Jv_CallAnyMethodA (NULL, declaringClass, meth, true,
  72. parameter_types, args);
  73. }