Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 23 | #include "util/StringPiece.h" |
| 24 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 25 | #include <ostream> |
| 26 | #include <string> |
| 27 | |
| 28 | namespace aapt { |
| 29 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 30 | struct JavaClassGeneratorOptions { |
| 31 | /* |
| 32 | * Specifies whether to use the 'final' modifier |
| 33 | * on resource entries. Default is true. |
| 34 | */ |
| 35 | bool useFinal = true; |
| 36 | }; |
| 37 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 38 | /* |
| 39 | * Generates the R.java file for a resource table. |
| 40 | */ |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 41 | class JavaClassGenerator { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 42 | public: |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 43 | JavaClassGenerator(ResourceTable* table, JavaClassGeneratorOptions options); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 44 | |
| 45 | /* |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 46 | * Writes the R.java file to `out`. Only symbols belonging to `package` are written. |
| 47 | * All symbols technically belong to a single package, but linked libraries will |
| 48 | * have their names mangled, denoting that they came from a different package. |
| 49 | * We need to generate these symbols in a separate file. |
| 50 | * Returns true on success. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 51 | */ |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 52 | bool generate(const StringPiece16& package, std::ostream* out); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 53 | |
| 54 | const std::string& getError() const; |
| 55 | |
| 56 | private: |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 57 | bool generateType(const StringPiece16& packageNameToGenerate, |
| 58 | const ResourceTablePackage* package, |
| 59 | const ResourceTableType* type, |
| 60 | std::ostream* out); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 61 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 62 | void generateStyleable(const StringPiece16& packageNameToGenerate, |
| 63 | const std::u16string& entryName, |
| 64 | const Styleable* styleable, |
| 65 | std::ostream* out); |
| 66 | |
| 67 | ResourceTable* mTable; |
| 68 | JavaClassGeneratorOptions mOptions; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 69 | std::string mError; |
| 70 | }; |
| 71 | |
| 72 | inline const std::string& JavaClassGenerator::getError() const { |
| 73 | return mError; |
| 74 | } |
| 75 | |
| 76 | } // namespace aapt |
| 77 | |
| 78 | #endif // AAPT_JAVA_CLASS_GENERATOR_H |