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 17 #ifndef ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_ 18 #define ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_ 19 20 #include <string> 21 22 #include "dex/primitive.h" 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 // Used to convert user-specified ignored types ("java.lang.String[]", 36 // "byte[][]") to the form returned by art::mirror::Class->GetDescriptor() 37 // ("[Ljava/lang/String;", "[[B"). 38 std::string InversePrettyDescriptor(const std::string& pretty_descriptor); 39 40 // Performs JNI name mangling as described in section 11.3 "Linking Native Methods" 41 // of the JNI spec. 42 std::string MangleForJni(const std::string& s); 43 44 std::string GetJniShortName(const std::string& class_name, const std::string& method_name); 45 46 // Turn "java.lang.String" into "Ljava/lang/String;". 47 std::string DotToDescriptor(const char* class_name); 48 49 // Turn "Ljava/lang/String;" into "java.lang.String" using the conventions of 50 // java.lang.Class.getName(). 51 std::string DescriptorToDot(const char* descriptor); 52 53 // Turn "Ljava/lang/String;" into "java/lang/String" using the opposite conventions of 54 // java.lang.Class.getName(). 55 std::string DescriptorToName(const char* descriptor); 56 57 // Tests for whether 's' is a valid class name in the three common forms: 58 bool IsValidBinaryClassName(const char* s); // "java.lang.String" 59 bool IsValidJniClassName(const char* s); // "java/lang/String" 60 bool IsValidDescriptor(const char* s); // "Ljava/lang/String;" 61 62 // Returns whether the given string is a valid field or method name, 63 // additionally allowing names that begin with '<' and end with '>'. 64 bool IsValidMemberName(const char* s); 65 66 } // namespace art 67 68 #endif // ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_ 69