generate_aidl_mappings.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "generate_aidl_mappings.h"
  17. #include "type_java.h"
  18. #include <sstream>
  19. namespace android {
  20. namespace aidl {
  21. namespace mappings {
  22. std::string dump_location(const AidlNode& method) {
  23. return method.PrintLocation();
  24. }
  25. SignatureMap generate_mappings(const AidlDefinedType* defined_type) {
  26. const AidlInterface* interface = defined_type->AsInterface();
  27. SignatureMap mappings;
  28. if (interface == nullptr) {
  29. return mappings;
  30. }
  31. for (const auto& method : interface->GetMethods()) {
  32. if (method->IsUserDefined()) {
  33. std::stringstream signature;
  34. signature << interface->GetCanonicalName() << "|";
  35. signature << method->GetName() << "|";
  36. for (const auto& arg : method->GetArguments()) {
  37. signature << arg->GetType().ToString() << ",";
  38. }
  39. signature << "|";
  40. signature << method->GetType().GetLanguageType<java::Type>()->JavaType();
  41. mappings[signature.str()] = dump_location(*method);
  42. }
  43. }
  44. return mappings;
  45. }
  46. } // namespace mappings
  47. } // namespace aidl
  48. } // namespace android