blob: e068d2e428aa43ccf66e5a7a891e09ddf96d9a1d [file] [log] [blame]
Elliott Hughesd369bb72011-09-12 14:41:14 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "jni_internal.h"
18#include "class_linker.h"
19#include "object.h"
20
21#include "JniConstants.h" // Last to avoid problems with LOG redefinition.
22
23namespace art {
24
25namespace {
26
27jclass Class_getComponentType(JNIEnv* env, jobject javaThis) {
28 Class* c = Decode<Class*>(env, javaThis);
29 if (!c->IsArrayClass()) {
30 return NULL;
31 }
32
33 /*
34 * We can't just return c->GetComponentType(), because that gives
35 * us the base type (e.g. X[][][] returns X). If this is a multi-
36 * dimensional array, we have to do the lookup by name.
37 */
38 Class* result;
39 std::string descriptor(c->GetDescriptor()->ToModifiedUtf8());
40 if (descriptor[1] == '[') {
41 result = Runtime::Current()->GetClassLinker()->FindClass(descriptor.c_str() + 1, c->GetClassLoader());
42 } else {
43 result = c->GetComponentType();
44 }
45 return AddLocalReference<jclass>(env, result);
46
47}
48
49jobjectArray Class_getDeclaredClasses(JNIEnv* env, jclass java_lang_Class_class, jclass c, jboolean publicOnly) {
50 UNIMPLEMENTED(WARNING);
51 return env->NewObjectArray(0, java_lang_Class_class, NULL);
52}
53
54static JNINativeMethod gMethods[] = {
55 //NATIVE_METHOD(Class, classForName, "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"),
56 //NATIVE_METHOD(Class, desiredAssertionStatus, "()Z"),
57 //NATIVE_METHOD(Class, getClassLoader, "(Ljava/lang/Class;)Ljava/lang/ClassLoader;"),
58 NATIVE_METHOD(Class, getComponentType, "()Ljava/lang/Class;"),
59 //NATIVE_METHOD(Class, getDeclaredAnnotation, "(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;"),
60 //NATIVE_METHOD(Class, getDeclaredAnnotations, "()[Ljava/lang/annotation/Annotation;"),
61 NATIVE_METHOD(Class, getDeclaredClasses, "(Ljava/lang/Class;Z)[Ljava/lang/Class;"),
62 //NATIVE_METHOD(Class, getDeclaredConstructorOrMethod, "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Member;"),
63 //NATIVE_METHOD(Class, getDeclaredConstructors, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Constructor;"),
64 //NATIVE_METHOD(Class, getDeclaredField, "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Field;"),
65 //NATIVE_METHOD(Class, getDeclaredFields, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Field;"),
66 //NATIVE_METHOD(Class, getDeclaredMethods, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Method;"),
67 //NATIVE_METHOD(Class, getDeclaringClass, "()Ljava/lang/Class;"),
68 //NATIVE_METHOD(Class, getEnclosingClass, "()Ljava/lang/Class;"),
69 //NATIVE_METHOD(Class, getEnclosingConstructor, "()Ljava/lang/reflect/Constructor;"),
70 //NATIVE_METHOD(Class, getEnclosingMethod, "()Ljava/lang/reflect/Method;"),
71 //NATIVE_METHOD(Class, getInnerClassName, "()Ljava/lang/String;"),
72 //NATIVE_METHOD(Class, getInterfaces, "()[Ljava/lang/Class;"),
73 //NATIVE_METHOD(Class, getModifiers, "(Ljava/lang/Class;Z)I"),
74 //NATIVE_METHOD(Class, getNameNative, "()Ljava/lang/String;"),
75 //NATIVE_METHOD(Class, getSignatureAnnotation, "()[Ljava/lang/Object;"),
76 //NATIVE_METHOD(Class, getSuperclass, "()Ljava/lang/Class;"),
77 //NATIVE_METHOD(Class, isAnonymousClass, "()Z"),
78 //NATIVE_METHOD(Class, isAssignableFrom, "(Ljava/lang/Class;)Z"),
79 //NATIVE_METHOD(Class, isDeclaredAnnotationPresent, "(Ljava/lang/Class;)Z"),
80 //NATIVE_METHOD(Class, isInstance, "(Ljava/lang/Object;)Z"),
81 //NATIVE_METHOD(Class, isInterface, "()Z"),
82 //NATIVE_METHOD(Class, isPrimitive, "()Z"),
83 //NATIVE_METHOD(Class, newInstanceImpl, "()Ljava/lang/Object;"),
84};
85
86} // namespace
87
88void register_java_lang_Class(JNIEnv* env) {
89 jniRegisterNativeMethods(env, "java/lang/Class", gMethods, NELEM(gMethods));
90}
91
92} // namespace art