blob: b91410dd0c8fc9b8ee15c46788a2854109354809 [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);
Elliott Hughesd369bb72011-09-12 14:41:14 -070046}
47
48jobjectArray Class_getDeclaredClasses(JNIEnv* env, jclass java_lang_Class_class, jclass c, jboolean publicOnly) {
49 UNIMPLEMENTED(WARNING);
50 return env->NewObjectArray(0, java_lang_Class_class, NULL);
51}
52
53static JNINativeMethod gMethods[] = {
54 //NATIVE_METHOD(Class, classForName, "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"),
55 //NATIVE_METHOD(Class, desiredAssertionStatus, "()Z"),
56 //NATIVE_METHOD(Class, getClassLoader, "(Ljava/lang/Class;)Ljava/lang/ClassLoader;"),
57 NATIVE_METHOD(Class, getComponentType, "()Ljava/lang/Class;"),
58 //NATIVE_METHOD(Class, getDeclaredAnnotation, "(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;"),
59 //NATIVE_METHOD(Class, getDeclaredAnnotations, "()[Ljava/lang/annotation/Annotation;"),
60 NATIVE_METHOD(Class, getDeclaredClasses, "(Ljava/lang/Class;Z)[Ljava/lang/Class;"),
61 //NATIVE_METHOD(Class, getDeclaredConstructorOrMethod, "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Member;"),
62 //NATIVE_METHOD(Class, getDeclaredConstructors, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Constructor;"),
63 //NATIVE_METHOD(Class, getDeclaredField, "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Field;"),
64 //NATIVE_METHOD(Class, getDeclaredFields, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Field;"),
65 //NATIVE_METHOD(Class, getDeclaredMethods, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Method;"),
66 //NATIVE_METHOD(Class, getDeclaringClass, "()Ljava/lang/Class;"),
67 //NATIVE_METHOD(Class, getEnclosingClass, "()Ljava/lang/Class;"),
68 //NATIVE_METHOD(Class, getEnclosingConstructor, "()Ljava/lang/reflect/Constructor;"),
69 //NATIVE_METHOD(Class, getEnclosingMethod, "()Ljava/lang/reflect/Method;"),
70 //NATIVE_METHOD(Class, getInnerClassName, "()Ljava/lang/String;"),
71 //NATIVE_METHOD(Class, getInterfaces, "()[Ljava/lang/Class;"),
72 //NATIVE_METHOD(Class, getModifiers, "(Ljava/lang/Class;Z)I"),
73 //NATIVE_METHOD(Class, getNameNative, "()Ljava/lang/String;"),
74 //NATIVE_METHOD(Class, getSignatureAnnotation, "()[Ljava/lang/Object;"),
75 //NATIVE_METHOD(Class, getSuperclass, "()Ljava/lang/Class;"),
76 //NATIVE_METHOD(Class, isAnonymousClass, "()Z"),
77 //NATIVE_METHOD(Class, isAssignableFrom, "(Ljava/lang/Class;)Z"),
78 //NATIVE_METHOD(Class, isDeclaredAnnotationPresent, "(Ljava/lang/Class;)Z"),
79 //NATIVE_METHOD(Class, isInstance, "(Ljava/lang/Object;)Z"),
80 //NATIVE_METHOD(Class, isInterface, "()Z"),
81 //NATIVE_METHOD(Class, isPrimitive, "()Z"),
82 //NATIVE_METHOD(Class, newInstanceImpl, "()Ljava/lang/Object;"),
83};
84
85} // namespace
86
87void register_java_lang_Class(JNIEnv* env) {
88 jniRegisterNativeMethods(env, "java/lang/Class", gMethods, NELEM(gMethods));
89}
90
91} // namespace art