Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 1 | /* |
| 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 Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 22 | #include "dex_file_annotations.h" |
Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 23 | #include "jni_internal.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 24 | #include "scoped_fast_native_object_access-inl.h" |
Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 25 | #include "utils.h" |
| 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | static 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, |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 50 | method->PrettyMethod().c_str(), |
Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 51 | parameter_count).c_str()); |
| 52 | return nullptr; |
| 53 | } |
| 54 | |
| 55 | StackHandleScope<1> hs(soa.Self()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 56 | Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class>(annotationType))); |
Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 57 | return soa.AddLocalReference<jobject>( |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 58 | annotations::GetAnnotationForMethodParameter(method, parameterIndex, klass)); |
Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static JNINativeMethod gMethods[] = { |
| 62 | NATIVE_METHOD(Parameter, |
| 63 | getAnnotationNative, |
| 64 | "!(Ljava/lang/reflect/Executable;ILjava/lang/Class;)Ljava/lang/annotation/Annotation;"), |
| 65 | }; |
| 66 | |
| 67 | void register_java_lang_reflect_Parameter(JNIEnv* env) { |
| 68 | REGISTER_NATIVE_METHODS("java/lang/reflect/Parameter"); |
| 69 | } |
| 70 | |
| 71 | } // namespace art |