David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
David Sehr | 334b9d7 | 2018-02-12 18:27:56 -0800 | [diff] [blame] | 17 | #ifndef ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_ |
| 18 | #define ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_ |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 22 | #include "dex/primitive.h" |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | // Used to implement PrettyClass, PrettyField, PrettyMethod, and PrettyTypeOf, |
| 27 | // one of which is probably more useful to you. |
| 28 | // Returns a human-readable equivalent of 'descriptor'. So "I" would be "int", |
| 29 | // "[[I" would be "int[][]", "[Ljava/lang/String;" would be |
| 30 | // "java.lang.String[]", and so forth. |
| 31 | void AppendPrettyDescriptor(const char* descriptor, std::string* result); |
| 32 | std::string PrettyDescriptor(const char* descriptor); |
| 33 | std::string PrettyDescriptor(Primitive::Type type); |
| 34 | |
| 35 | // Performs JNI name mangling as described in section 11.3 "Linking Native Methods" |
| 36 | // of the JNI spec. |
| 37 | std::string MangleForJni(const std::string& s); |
| 38 | |
| 39 | std::string GetJniShortName(const std::string& class_name, const std::string& method_name); |
| 40 | |
| 41 | // Turn "java.lang.String" into "Ljava/lang/String;". |
| 42 | std::string DotToDescriptor(const char* class_name); |
| 43 | |
| 44 | // Turn "Ljava/lang/String;" into "java.lang.String" using the conventions of |
| 45 | // java.lang.Class.getName(). |
| 46 | std::string DescriptorToDot(const char* descriptor); |
| 47 | |
| 48 | // Turn "Ljava/lang/String;" into "java/lang/String" using the opposite conventions of |
| 49 | // java.lang.Class.getName(). |
| 50 | std::string DescriptorToName(const char* descriptor); |
| 51 | |
| 52 | // Tests for whether 's' is a valid class name in the three common forms: |
| 53 | bool IsValidBinaryClassName(const char* s); // "java.lang.String" |
| 54 | bool IsValidJniClassName(const char* s); // "java/lang/String" |
| 55 | bool IsValidDescriptor(const char* s); // "Ljava/lang/String;" |
| 56 | |
| 57 | // Returns whether the given string is a valid field or method name, |
| 58 | // additionally allowing names that begin with '<' and end with '>'. |
| 59 | bool IsValidMemberName(const char* s); |
| 60 | |
| 61 | } // namespace art |
| 62 | |
David Sehr | 334b9d7 | 2018-02-12 18:27:56 -0800 | [diff] [blame] | 63 | #endif // ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_ |