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" |
| 22 | #include "jni_internal.h" |
| 23 | #include "scoped_fast_native_object_access.h" |
| 24 | #include "utils.h" |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | static jobject Parameter_getAnnotationNative(JNIEnv* env, |
| 29 | jclass, |
| 30 | jobject javaMethod, |
| 31 | jint parameterIndex, |
| 32 | jclass annotationType) { |
| 33 | ScopedFastNativeObjectAccess soa(env); |
| 34 | if (UNLIKELY(javaMethod == nullptr)) { |
| 35 | ThrowNullPointerException("javaMethod == null"); |
| 36 | return nullptr; |
| 37 | } |
| 38 | |
| 39 | ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod); |
| 40 | if (method->IsProxyMethod()) { |
| 41 | return nullptr; |
| 42 | } |
| 43 | |
| 44 | uint32_t parameter_count = method->GetParameterTypeList()->Size(); |
| 45 | if (UNLIKELY(parameterIndex < 0 || static_cast<uint32_t>(parameterIndex) >= parameter_count)) { |
| 46 | ThrowIllegalArgumentException( |
| 47 | StringPrintf("Illegal parameterIndex %d for %s, parameter_count is %d", |
| 48 | parameterIndex, |
| 49 | PrettyMethod(method).c_str(), |
| 50 | parameter_count).c_str()); |
| 51 | return nullptr; |
| 52 | } |
| 53 | |
| 54 | StackHandleScope<1> hs(soa.Self()); |
| 55 | Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType))); |
| 56 | return soa.AddLocalReference<jobject>( |
| 57 | method->GetDexFile()->GetAnnotationForMethodParameter(method, parameterIndex, klass)); |
| 58 | } |
| 59 | |
| 60 | static JNINativeMethod gMethods[] = { |
| 61 | NATIVE_METHOD(Parameter, |
| 62 | getAnnotationNative, |
| 63 | "!(Ljava/lang/reflect/Executable;ILjava/lang/Class;)Ljava/lang/annotation/Annotation;"), |
| 64 | }; |
| 65 | |
| 66 | void register_java_lang_reflect_Parameter(JNIEnv* env) { |
| 67 | REGISTER_NATIVE_METHODS("java/lang/reflect/Parameter"); |
| 68 | } |
| 69 | |
| 70 | } // namespace art |