diff options
| author | 2016-10-19 12:18:14 -0700 | |
|---|---|---|
| committer | 2016-10-19 12:18:14 -0700 | |
| commit | cacb28f2d60858106e2819cc7d95a65e8bda890b (patch) | |
| tree | c8ac4af72b0a9599983567029e5680c40f9883a3 /tools/aapt2/java | |
| parent | 733f0bc08ea0c93d095016a791c2914658d0cdde (diff) | |
Use Google3 style guide with .clang-format
Test: style change only, builds ok
Change-Id: I885180e24cb2e7b58cfb4967c3bcb40058ce4078
Diffstat (limited to 'tools/aapt2/java')
| -rw-r--r-- | tools/aapt2/java/AnnotationProcessor.h | 46 | ||||
| -rw-r--r-- | tools/aapt2/java/ClassDefinition.h | 192 | ||||
| -rw-r--r-- | tools/aapt2/java/JavaClassGenerator.h | 116 | ||||
| -rw-r--r-- | tools/aapt2/java/ManifestClassGenerator.h | 5 | ||||
| -rw-r--r-- | tools/aapt2/java/ProguardRules.h | 34 |
5 files changed, 195 insertions, 198 deletions
diff --git a/tools/aapt2/java/AnnotationProcessor.h b/tools/aapt2/java/AnnotationProcessor.h index cfc32f3c6477..54196085db17 100644 --- a/tools/aapt2/java/AnnotationProcessor.h +++ b/tools/aapt2/java/AnnotationProcessor.h @@ -52,34 +52,36 @@ namespace aapt { * */ class AnnotationProcessor { -public: - /** - * Adds more comments. Since resources can have various values with different configurations, - * we need to collect all the comments. - */ - void appendComment(const StringPiece& comment); + public: + /** + * Adds more comments. Since resources can have various values with different + * configurations, + * we need to collect all the comments. + */ + void appendComment(const StringPiece& comment); - void appendNewLine(); + void appendNewLine(); - /** - * Writes the comments and annotations to the stream, with the given prefix before each line. - */ - void writeToStream(std::ostream* out, const StringPiece& prefix) const; + /** + * Writes the comments and annotations to the stream, with the given prefix + * before each line. + */ + void writeToStream(std::ostream* out, const StringPiece& prefix) const; -private: - enum : uint32_t { - kDeprecated = 0x01, - kSystemApi = 0x02, - }; + private: + enum : uint32_t { + kDeprecated = 0x01, + kSystemApi = 0x02, + }; - std::stringstream mComment; - std::stringstream mAnnotations; - bool mHasComments = false; - uint32_t mAnnotationBitMask = 0; + std::stringstream mComment; + std::stringstream mAnnotations; + bool mHasComments = false; + uint32_t mAnnotationBitMask = 0; - void appendCommentLine(std::string& line); + void appendCommentLine(std::string& line); }; -} // namespace aapt +} // namespace aapt #endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */ diff --git a/tools/aapt2/java/ClassDefinition.h b/tools/aapt2/java/ClassDefinition.h index e84c2741e4ce..bd7e7b277fe5 100644 --- a/tools/aapt2/java/ClassDefinition.h +++ b/tools/aapt2/java/ClassDefinition.h @@ -33,46 +33,43 @@ constexpr static size_t kAttribsPerLine = 4; constexpr static const char* kIndent = " "; class ClassMember { -public: - virtual ~ClassMember() = default; + public: + virtual ~ClassMember() = default; - AnnotationProcessor* getCommentBuilder() { - return &mProcessor; - } + AnnotationProcessor* getCommentBuilder() { return &mProcessor; } - virtual bool empty() const = 0; + virtual bool empty() const = 0; - virtual void writeToStream(const StringPiece& prefix, bool final, std::ostream* out) const { - mProcessor.writeToStream(out, prefix); - } + virtual void writeToStream(const StringPiece& prefix, bool final, + std::ostream* out) const { + mProcessor.writeToStream(out, prefix); + } -private: - AnnotationProcessor mProcessor; + private: + AnnotationProcessor mProcessor; }; template <typename T> class PrimitiveMember : public ClassMember { -public: - PrimitiveMember(const StringPiece& name, const T& val) : - mName(name.toString()), mVal(val) { - } + public: + PrimitiveMember(const StringPiece& name, const T& val) + : mName(name.toString()), mVal(val) {} - bool empty() const override { - return false; - } + bool empty() const override { return false; } - void writeToStream(const StringPiece& prefix, bool final, std::ostream* out) const override { - ClassMember::writeToStream(prefix, final, out); + void writeToStream(const StringPiece& prefix, bool final, + std::ostream* out) const override { + ClassMember::writeToStream(prefix, final, out); - *out << prefix << "public static " << (final ? "final " : "") - << "int " << mName << "=" << mVal << ";"; - } + *out << prefix << "public static " << (final ? "final " : "") << "int " + << mName << "=" << mVal << ";"; + } -private: - std::string mName; - T mVal; + private: + std::string mName; + T mVal; - DISALLOW_COPY_AND_ASSIGN(PrimitiveMember); + DISALLOW_COPY_AND_ASSIGN(PrimitiveMember); }; /** @@ -80,27 +77,25 @@ private: */ template <> class PrimitiveMember<std::string> : public ClassMember { -public: - PrimitiveMember(const StringPiece& name, const std::string& val) : - mName(name.toString()), mVal(val) { - } + public: + PrimitiveMember(const StringPiece& name, const std::string& val) + : mName(name.toString()), mVal(val) {} - bool empty() const override { - return false; - } + bool empty() const override { return false; } - void writeToStream(const StringPiece& prefix, bool final, std::ostream* out) const override { - ClassMember::writeToStream(prefix, final, out); + void writeToStream(const StringPiece& prefix, bool final, + std::ostream* out) const override { + ClassMember::writeToStream(prefix, final, out); - *out << prefix << "public static " << (final ? "final " : "") - << "String " << mName << "=\"" << mVal << "\";"; - } + *out << prefix << "public static " << (final ? "final " : "") << "String " + << mName << "=\"" << mVal << "\";"; + } -private: - std::string mName; - std::string mVal; + private: + std::string mName; + std::string mVal; - DISALLOW_COPY_AND_ASSIGN(PrimitiveMember); + DISALLOW_COPY_AND_ASSIGN(PrimitiveMember); }; using IntMember = PrimitiveMember<uint32_t>; @@ -109,80 +104,75 @@ using StringMember = PrimitiveMember<std::string>; template <typename T> class PrimitiveArrayMember : public ClassMember { -public: - explicit PrimitiveArrayMember(const StringPiece& name) : - mName(name.toString()) { - } + public: + explicit PrimitiveArrayMember(const StringPiece& name) + : mName(name.toString()) {} - void addElement(const T& val) { - mElements.push_back(val); - } + void addElement(const T& val) { mElements.push_back(val); } - bool empty() const override { - return false; - } + bool empty() const override { return false; } - void writeToStream(const StringPiece& prefix, bool final, std::ostream* out) const override { - ClassMember::writeToStream(prefix, final, out); + void writeToStream(const StringPiece& prefix, bool final, + std::ostream* out) const override { + ClassMember::writeToStream(prefix, final, out); - *out << prefix << "public static final int[] " << mName << "={"; + *out << prefix << "public static final int[] " << mName << "={"; - const auto begin = mElements.begin(); - const auto end = mElements.end(); - for (auto current = begin; current != end; ++current) { - if (std::distance(begin, current) % kAttribsPerLine == 0) { - *out << "\n" << prefix << kIndent << kIndent; - } + const auto begin = mElements.begin(); + const auto end = mElements.end(); + for (auto current = begin; current != end; ++current) { + if (std::distance(begin, current) % kAttribsPerLine == 0) { + *out << "\n" << prefix << kIndent << kIndent; + } - *out << *current; - if (std::distance(current, end) > 1) { - *out << ", "; - } - } - *out << "\n" << prefix << kIndent <<"};"; + *out << *current; + if (std::distance(current, end) > 1) { + *out << ", "; + } } + *out << "\n" << prefix << kIndent << "};"; + } -private: - std::string mName; - std::vector<T> mElements; + private: + std::string mName; + std::vector<T> mElements; - DISALLOW_COPY_AND_ASSIGN(PrimitiveArrayMember); + DISALLOW_COPY_AND_ASSIGN(PrimitiveArrayMember); }; using ResourceArrayMember = PrimitiveArrayMember<ResourceId>; -enum class ClassQualifier { - None, - Static -}; +enum class ClassQualifier { None, Static }; class ClassDefinition : public ClassMember { -public: - static bool writeJavaFile(const ClassDefinition* def, - const StringPiece& package, - bool final, - std::ostream* out); - - ClassDefinition(const StringPiece& name, ClassQualifier qualifier, bool createIfEmpty) : - mName(name.toString()), mQualifier(qualifier), mCreateIfEmpty(createIfEmpty) { - } - - void addMember(std::unique_ptr<ClassMember> member) { - mMembers.push_back(std::move(member)); - } - - bool empty() const override; - void writeToStream(const StringPiece& prefix, bool final, std::ostream* out) const override; - -private: - std::string mName; - ClassQualifier mQualifier; - bool mCreateIfEmpty; - std::vector<std::unique_ptr<ClassMember>> mMembers; - - DISALLOW_COPY_AND_ASSIGN(ClassDefinition); + public: + static bool writeJavaFile(const ClassDefinition* def, + const StringPiece& package, bool final, + std::ostream* out); + + ClassDefinition(const StringPiece& name, ClassQualifier qualifier, + bool createIfEmpty) + : mName(name.toString()), + mQualifier(qualifier), + mCreateIfEmpty(createIfEmpty) {} + + void addMember(std::unique_ptr<ClassMember> member) { + mMembers.push_back(std::move(member)); + } + + bool empty() const override; + void writeToStream(const StringPiece& prefix, bool final, + std::ostream* out) const override; + + private: + std::string mName; + ClassQualifier mQualifier; + bool mCreateIfEmpty; + std::vector<std::unique_ptr<ClassMember>> mMembers; + + DISALLOW_COPY_AND_ASSIGN(ClassDefinition); }; -} // namespace aapt +} // namespace aapt #endif /* AAPT_JAVA_CLASSDEFINITION_H */ diff --git a/tools/aapt2/java/JavaClassGenerator.h b/tools/aapt2/java/JavaClassGenerator.h index 901a86ed5b1d..2fdf2682a162 100644 --- a/tools/aapt2/java/JavaClassGenerator.h +++ b/tools/aapt2/java/JavaClassGenerator.h @@ -31,72 +31,74 @@ class AnnotationProcessor; class ClassDefinition; struct JavaClassGeneratorOptions { - /* - * Specifies whether to use the 'final' modifier - * on resource entries. Default is true. - */ - bool useFinal = true; - - enum class SymbolTypes { - kAll, - kPublicPrivate, - kPublic, - }; - - SymbolTypes types = SymbolTypes::kAll; - - /** - * A list of JavaDoc annotations to add to the comments of all generated classes. - */ - std::vector<std::string> javadocAnnotations; + /* + * Specifies whether to use the 'final' modifier + * on resource entries. Default is true. + */ + bool useFinal = true; + + enum class SymbolTypes { + kAll, + kPublicPrivate, + kPublic, + }; + + SymbolTypes types = SymbolTypes::kAll; + + /** + * A list of JavaDoc annotations to add to the comments of all generated + * classes. + */ + std::vector<std::string> javadocAnnotations; }; /* * Generates the R.java file for a resource table. */ class JavaClassGenerator { -public: - JavaClassGenerator(IAaptContext* context, ResourceTable* table, - const JavaClassGeneratorOptions& options); - - /* - * Writes the R.java file to `out`. Only symbols belonging to `package` are written. - * All symbols technically belong to a single package, but linked libraries will - * have their names mangled, denoting that they came from a different package. - * We need to generate these symbols in a separate file. - * Returns true on success. - */ - bool generate(const StringPiece& packageNameToGenerate, std::ostream* out); - - bool generate(const StringPiece& packageNameToGenerate, - const StringPiece& outputPackageName, - std::ostream* out); - - const std::string& getError() const; - -private: - bool addMembersToTypeClass(const StringPiece& packageNameToGenerate, - const ResourceTablePackage* package, - const ResourceTableType* type, - ClassDefinition* outTypeClassDef); - - void addMembersToStyleableClass(const StringPiece& packageNameToGenerate, - const std::string& entryName, - const Styleable* styleable, - ClassDefinition* outStyleableClassDef); - - bool skipSymbol(SymbolState state); - - IAaptContext* mContext; - ResourceTable* mTable; - JavaClassGeneratorOptions mOptions; - std::string mError; + public: + JavaClassGenerator(IAaptContext* context, ResourceTable* table, + const JavaClassGeneratorOptions& options); + + /* + * Writes the R.java file to `out`. Only symbols belonging to `package` are + * written. + * All symbols technically belong to a single package, but linked libraries + * will + * have their names mangled, denoting that they came from a different package. + * We need to generate these symbols in a separate file. + * Returns true on success. + */ + bool generate(const StringPiece& packageNameToGenerate, std::ostream* out); + + bool generate(const StringPiece& packageNameToGenerate, + const StringPiece& outputPackageName, std::ostream* out); + + const std::string& getError() const; + + private: + bool addMembersToTypeClass(const StringPiece& packageNameToGenerate, + const ResourceTablePackage* package, + const ResourceTableType* type, + ClassDefinition* outTypeClassDef); + + void addMembersToStyleableClass(const StringPiece& packageNameToGenerate, + const std::string& entryName, + const Styleable* styleable, + ClassDefinition* outStyleableClassDef); + + bool skipSymbol(SymbolState state); + + IAaptContext* mContext; + ResourceTable* mTable; + JavaClassGeneratorOptions mOptions; + std::string mError; }; inline const std::string& JavaClassGenerator::getError() const { - return mError; + return mError; } -} // namespace aapt +} // namespace aapt -#endif // AAPT_JAVA_CLASS_GENERATOR_H +#endif // AAPT_JAVA_CLASS_GENERATOR_H diff --git a/tools/aapt2/java/ManifestClassGenerator.h b/tools/aapt2/java/ManifestClassGenerator.h index f565289393fb..18176483fa01 100644 --- a/tools/aapt2/java/ManifestClassGenerator.h +++ b/tools/aapt2/java/ManifestClassGenerator.h @@ -26,8 +26,9 @@ namespace aapt { -std::unique_ptr<ClassDefinition> generateManifestClass(IDiagnostics* diag, xml::XmlResource* res); +std::unique_ptr<ClassDefinition> generateManifestClass(IDiagnostics* diag, + xml::XmlResource* res); -} // namespace aapt +} // namespace aapt #endif /* AAPT_JAVA_MANIFESTCLASSGENERATOR_H */ diff --git a/tools/aapt2/java/ProguardRules.h b/tools/aapt2/java/ProguardRules.h index c2d2bd928f90..7578ec2abf58 100644 --- a/tools/aapt2/java/ProguardRules.h +++ b/tools/aapt2/java/ProguardRules.h @@ -30,29 +30,31 @@ namespace aapt { namespace proguard { class KeepSet { -public: - inline void addClass(const Source& source, const std::string& className) { - mKeepSet[className].insert(source); - } + public: + inline void addClass(const Source& source, const std::string& className) { + mKeepSet[className].insert(source); + } - inline void addMethod(const Source& source, const std::string& methodName) { - mKeepMethodSet[methodName].insert(source); - } + inline void addMethod(const Source& source, const std::string& methodName) { + mKeepMethodSet[methodName].insert(source); + } -private: - friend bool writeKeepSet(std::ostream* out, const KeepSet& keepSet); + private: + friend bool writeKeepSet(std::ostream* out, const KeepSet& keepSet); - std::map<std::string, std::set<Source>> mKeepSet; - std::map<std::string, std::set<Source>> mKeepMethodSet; + std::map<std::string, std::set<Source>> mKeepSet; + std::map<std::string, std::set<Source>> mKeepMethodSet; }; -bool collectProguardRulesForManifest(const Source& source, xml::XmlResource* res, KeepSet* keepSet, +bool collectProguardRulesForManifest(const Source& source, + xml::XmlResource* res, KeepSet* keepSet, bool mainDexOnly = false); -bool collectProguardRules(const Source& source, xml::XmlResource* res, KeepSet* keepSet); +bool collectProguardRules(const Source& source, xml::XmlResource* res, + KeepSet* keepSet); bool writeKeepSet(std::ostream* out, const KeepSet& keepSet); -} // namespace proguard -} // namespace aapt +} // namespace proguard +} // namespace aapt -#endif // AAPT_PROGUARD_RULES_H +#endif // AAPT_PROGUARD_RULES_H |