Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019, 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 "generate_aidl_mappings.h" |
Jeongik Cha | 2c5e762 | 2019-07-23 14:15:48 +0900 | [diff] [blame] | 18 | #include "aidl_to_java.h" |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 19 | |
| 20 | #include <sstream> |
| 21 | |
| 22 | namespace android { |
| 23 | namespace aidl { |
| 24 | namespace mappings { |
| 25 | |
| 26 | std::string dump_location(const AidlNode& method) { |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 27 | return method.PrintLine(); |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 30 | SignatureMap generate_mappings(const AidlDefinedType* defined_type, |
| 31 | const AidlTypenames& typenames) { |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 32 | const AidlInterface* interface = defined_type->AsInterface(); |
| 33 | SignatureMap mappings; |
| 34 | if (interface == nullptr) { |
| 35 | return mappings; |
| 36 | } |
| 37 | for (const auto& method : interface->GetMethods()) { |
| 38 | if (method->IsUserDefined()) { |
| 39 | std::stringstream signature; |
| 40 | signature << interface->GetCanonicalName() << "|"; |
| 41 | signature << method->GetName() << "|"; |
| 42 | for (const auto& arg : method->GetArguments()) { |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 43 | signature << java::JavaSignatureOf(arg->GetType(), typenames) << ","; |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 44 | } |
| 45 | signature << "|"; |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 46 | signature << java::JavaSignatureOf(method->GetType(), typenames); |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 47 | mappings[signature.str()] = dump_location(*method); |
| 48 | } |
| 49 | } |
| 50 | return mappings; |
| 51 | } |
| 52 | |
| 53 | } // namespace mappings |
| 54 | } // namespace aidl |
| 55 | } // namespace android |