blob: 6060b8a2f619a8906fe7c1fcab645bbc1ab38937 [file] [log] [blame]
Neil Fuller60458a02016-09-01 15:32:44 +01001/*
2 * Copyright (C) 2016 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 "java_lang_reflect_Parameter.h"
18
19#include "art_method-inl.h"
20#include "common_throws.h"
21#include "dex_file-inl.h"
David Sehr9323e6e2016-09-13 08:58:35 -070022#include "dex_file_annotations.h"
Neil Fuller60458a02016-09-01 15:32:44 +010023#include "jni_internal.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070024#include "scoped_fast_native_object_access-inl.h"
Neil Fuller60458a02016-09-01 15:32:44 +010025#include "utils.h"
26
27namespace art {
28
29static jobject Parameter_getAnnotationNative(JNIEnv* env,
30 jclass,
31 jobject javaMethod,
32 jint parameterIndex,
33 jclass annotationType) {
34 ScopedFastNativeObjectAccess soa(env);
35 if (UNLIKELY(javaMethod == nullptr)) {
36 ThrowNullPointerException("javaMethod == null");
37 return nullptr;
38 }
39
40 ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod);
41 if (method->IsProxyMethod()) {
42 return nullptr;
43 }
44
45 uint32_t parameter_count = method->GetParameterTypeList()->Size();
46 if (UNLIKELY(parameterIndex < 0 || static_cast<uint32_t>(parameterIndex) >= parameter_count)) {
47 ThrowIllegalArgumentException(
48 StringPrintf("Illegal parameterIndex %d for %s, parameter_count is %d",
49 parameterIndex,
50 PrettyMethod(method).c_str(),
51 parameter_count).c_str());
52 return nullptr;
53 }
54
55 StackHandleScope<1> hs(soa.Self());
Mathieu Chartier0795f232016-09-27 18:43:30 -070056 Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class>(annotationType)));
Neil Fuller60458a02016-09-01 15:32:44 +010057 return soa.AddLocalReference<jobject>(
David Sehr9323e6e2016-09-13 08:58:35 -070058 annotations::GetAnnotationForMethodParameter(method, parameterIndex, klass));
Neil Fuller60458a02016-09-01 15:32:44 +010059}
60
61static JNINativeMethod gMethods[] = {
62 NATIVE_METHOD(Parameter,
63 getAnnotationNative,
64 "!(Ljava/lang/reflect/Executable;ILjava/lang/Class;)Ljava/lang/annotation/Annotation;"),
65};
66
67void register_java_lang_reflect_Parameter(JNIEnv* env) {
68 REGISTER_NATIVE_METHODS("java/lang/reflect/Parameter");
69}
70
71} // namespace art