blob: 5b8e50035a9cc4a1ce31be5f20e15a81c8936ca9 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 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 AAPT_JAVA_CLASS_GENERATOR_H
18#define AAPT_JAVA_CLASS_GENERATOR_H
19
20#include "ResourceTable.h"
21#include "ResourceValues.h"
22
23#include <ostream>
24#include <string>
25
26namespace aapt {
27
28/*
29 * Generates the R.java file for a resource table.
30 */
31class JavaClassGenerator : ConstValueVisitor {
32public:
33 /*
34 * A set of options for this JavaClassGenerator.
35 */
36 struct Options {
37 /*
38 * Specifies whether to use the 'final' modifier
39 * on resource entries. Default is true.
40 */
41 bool useFinal = true;
42 };
43
44 JavaClassGenerator(std::shared_ptr<const ResourceTable> table, Options options);
45
46 /*
47 * Writes the R.java file to `out`. Returns true on success.
48 */
49 bool generate(std::ostream& out);
50
51 /*
52 * ConstValueVisitor implementation.
53 */
54 void visit(const Styleable& styleable, ValueVisitorArgs& args);
55
56 const std::string& getError() const;
57
58private:
59 bool generateType(std::ostream& out, const ResourceTableType& type, size_t packageId);
60
61 std::shared_ptr<const ResourceTable> mTable;
62 Options mOptions;
63 std::string mError;
64};
65
66inline const std::string& JavaClassGenerator::getError() const {
67 return mError;
68}
69
70} // namespace aapt
71
72#endif // AAPT_JAVA_CLASS_GENERATOR_H