| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_JAVA_CLASS_GENERATOR_H |
| 18 |
#define AAPT_JAVA_CLASS_GENERATOR_H |
| 19 |
|
| 20 |
#include <string> |
| 21 |
|
| 22 |
#include "androidfw/StringPiece.h" |
| 23 |
|
| 24 |
#include "ResourceTable.h" |
| 25 |
#include "ResourceValues.h" |
| 26 |
#include "io/Io.h" |
| 27 |
#include "process/IResourceTableConsumer.h" |
| 28 |
#include "process/SymbolTable.h" |
| 29 |
#include "text/Printer.h" |
| 30 |
|
| 31 |
namespace aapt { |
| 32 |
|
| 33 |
class AnnotationProcessor; |
| 34 |
class ClassDefinition; |
| 35 |
class MethodDefinition; |
| 36 |
|
| 37 |
|
| 38 |
struct OnResourcesLoadedCallbackOptions { |
| 39 |
|
| 40 |
std::vector<std::string> packages_to_callback; |
| 41 |
}; |
| 42 |
|
| 43 |
struct JavaClassGeneratorOptions { |
| 44 |
|
| 45 |
bool use_final = true; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
std::optional<OnResourcesLoadedCallbackOptions> rewrite_callback_options; |
| 50 |
|
| 51 |
enum class SymbolTypes { |
| 52 |
kAll, |
| 53 |
kPublicPrivate, |
| 54 |
kPublic, |
| 55 |
}; |
| 56 |
|
| 57 |
SymbolTypes types = SymbolTypes::kAll; |
| 58 |
|
| 59 |
|
| 60 |
std::vector<std::string> javadoc_annotations; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
class JavaClassGenerator { |
| 65 |
public: |
| 66 |
JavaClassGenerator(IAaptContext* context, ResourceTable* table, |
| 67 |
const JavaClassGeneratorOptions& options); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
bool Generate(const android::StringPiece& package_name_to_generate, io::OutputStream* out, |
| 74 |
io::OutputStream* out_r_txt = nullptr); |
| 75 |
|
| 76 |
bool Generate(const android::StringPiece& package_name_to_generate, |
| 77 |
const android::StringPiece& output_package_name, io::OutputStream* out, |
| 78 |
io::OutputStream* out_r_txt = nullptr); |
| 79 |
|
| 80 |
const std::string& GetError() const; |
| 81 |
|
| 82 |
static std::string TransformToFieldName(const android::StringPiece& symbol); |
| 83 |
|
| 84 |
private: |
| 85 |
bool SkipSymbol(Visibility::Level state); |
| 86 |
bool SkipSymbol(const std::optional<SymbolTable::Symbol>& symbol); |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
std::optional<std::string> UnmangleResource(const android::StringPiece& package_name, |
| 91 |
const android::StringPiece& package_name_to_generate, |
| 92 |
const ResourceEntry& entry); |
| 93 |
|
| 94 |
bool ProcessType(const android::StringPiece& package_name_to_generate, |
| 95 |
const ResourceTablePackage& package, const ResourceTableType& type, |
| 96 |
ClassDefinition* out_type_class_def, MethodDefinition* out_rewrite_method_def, |
| 97 |
text::Printer* r_txt_printer); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
void ProcessResource(const ResourceNameRef& name, const ResourceId& id, |
| 102 |
const ResourceEntry& entry, ClassDefinition* out_class_def, |
| 103 |
MethodDefinition* out_rewrite_method, text::Printer* r_txt_printer); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
bool ProcessStyleable(const ResourceNameRef& name, const ResourceId& id, |
| 109 |
const Styleable& styleable, |
| 110 |
const android::StringPiece& package_name_to_generate, |
| 111 |
ClassDefinition* out_class_def, MethodDefinition* out_rewrite_method, |
| 112 |
text::Printer* r_txt_printer); |
| 113 |
|
| 114 |
IAaptContext* context_; |
| 115 |
ResourceTable* table_; |
| 116 |
JavaClassGeneratorOptions options_; |
| 117 |
std::string error_; |
| 118 |
}; |
| 119 |
|
| 120 |
inline const std::string& JavaClassGenerator::GetError() const { |
| 121 |
return error_; |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
#endif |