blob: 62b0118ad4645479d451f119d60540ede4bb3928 [file] [log] [blame]
David Sehr0225f8e2018-01-31 08:52:24 +00001/*
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 Sehr334b9d72018-02-12 18:27:56 -080017#ifndef ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_
18#define ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_
David Sehr0225f8e2018-01-31 08:52:24 +000019
20#include <string>
21
David Sehr67bf42e2018-02-26 16:43:04 -080022#include "dex/primitive.h"
David Sehr0225f8e2018-01-31 08:52:24 +000023
24namespace 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.
31void AppendPrettyDescriptor(const char* descriptor, std::string* result);
32std::string PrettyDescriptor(const char* descriptor);
33std::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.
37std::string MangleForJni(const std::string& s);
38
39std::string GetJniShortName(const std::string& class_name, const std::string& method_name);
40
41// Turn "java.lang.String" into "Ljava/lang/String;".
42std::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().
46std::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().
50std::string DescriptorToName(const char* descriptor);
51
52// Tests for whether 's' is a valid class name in the three common forms:
53bool IsValidBinaryClassName(const char* s); // "java.lang.String"
54bool IsValidJniClassName(const char* s); // "java/lang/String"
55bool 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 '>'.
59bool IsValidMemberName(const char* s);
60
61} // namespace art
62
David Sehr334b9d72018-02-12 18:27:56 -080063#endif // ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_