natConstructor.cc 2.58 KB
Newer Older
Tom Tromey committed
1 2
// natConstructor.cc - Native code for Constructor class.

3
/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006  Free Software Foundation
Tom Tromey committed
4 5 6 7 8 9 10 11 12 13 14

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

#include <config.h>

#include <gcj/cni.h>
#include <jvm.h>
15
#include <java-stack.h>
Tom Tromey committed
16

Tom Tromey committed
17 18
#include <java/lang/ArrayIndexOutOfBoundsException.h>
#include <java/lang/IllegalAccessException.h>
Tom Tromey committed
19 20 21 22 23 24 25
#include <java/lang/reflect/Constructor.h>
#include <java/lang/reflect/Method.h>
#include <java/lang/reflect/InvocationTargetException.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/InstantiationException.h>
#include <gcj/method.h>

26 27 28
typedef JArray< ::java::lang::annotation::Annotation * > * anno_a_t;
typedef JArray< JArray< ::java::lang::annotation::Annotation * > *> * anno_aa_t;

Tom Tromey committed
29
jint
30
java::lang::reflect::Constructor::getModifiersInternal ()
Tom Tromey committed
31
{
32
  return _Jv_FromReflectedConstructor (this)->accflags;
Tom Tromey committed
33 34
}

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
jstring
java::lang::reflect::Constructor::getSignature()
{
  return declaringClass->getReflectionSignature (this);
}

anno_a_t
java::lang::reflect::Constructor::getDeclaredAnnotationsInternal()
{
  return (anno_a_t) declaringClass->getDeclaredAnnotations(this, false);
}

anno_aa_t
java::lang::reflect::Constructor::getParameterAnnotationsInternal()
{
  return (anno_aa_t) declaringClass->getDeclaredAnnotations(this, true);
}

Tom Tromey committed
53 54 55 56 57 58 59
void
java::lang::reflect::Constructor::getType ()
{
  _Jv_GetTypesFromSignature (_Jv_FromReflectedConstructor (this),
			     declaringClass,
			     &parameter_types,
			     NULL);
60 61 62 63

  // FIXME: for now we have no way to get exception information.
  exception_types = 
    (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$, NULL);
Tom Tromey committed
64 65 66 67 68
}

jobject
java::lang::reflect::Constructor::newInstance (jobjectArray args)
{
69 70
  using namespace java::lang::reflect;

Tom Tromey committed
71 72 73
  if (parameter_types == NULL)
    getType ();

74 75 76 77
  jmethodID meth = _Jv_FromReflectedConstructor (this);

  // Check accessibility, if required.
  if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
Tom Tromey committed
78
    {
79
      Class *caller = _Jv_StackTrace::GetCallingClass (&Constructor::class$);
80 81 82
      if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
	throw new IllegalAccessException;
    }
Tom Tromey committed
83

Tom Tromey committed
84
  if (Modifier::isAbstract (declaringClass->getModifiers()))
85
    throw new InstantiationException;
Tom Tromey committed
86

87 88
  _Jv_InitClass (declaringClass);

Tom Tromey committed
89 90
  // In the constructor case the return type is the type of the
  // constructor.
91 92
  return _Jv_CallAnyMethodA (NULL, declaringClass, meth, true,
			     parameter_types, args);
Tom Tromey committed
93
}