Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [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_ANNOTATIONPROCESSOR_H |
| 18 | #define AAPT_JAVA_ANNOTATIONPROCESSOR_H |
| 19 | |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 20 | #include <sstream> |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 23 | #include "androidfw/StringPiece.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 24 | |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 25 | namespace aapt { |
| 26 | |
Adam Lesinski | 09f4d70 | 2017-08-08 10:39:55 -0700 | [diff] [blame] | 27 | // Builds a JavaDoc comment from a set of XML comments. |
| 28 | // This will also look for instances of @SystemApi and convert them to |
| 29 | // actual Java annotations. |
| 30 | // |
| 31 | // Example: |
| 32 | // |
| 33 | // Input XML: |
| 34 | // |
| 35 | // <!-- This is meant to be hidden because |
| 36 | // It is system api. Also it is @deprecated |
| 37 | // @SystemApi |
| 38 | // --> |
| 39 | // |
| 40 | // Output JavaDoc: |
| 41 | // |
| 42 | // /** |
| 43 | // * This is meant to be hidden because |
| 44 | // * It is system api. Also it is @deprecated |
| 45 | // */ |
| 46 | // |
| 47 | // Output Annotations: |
| 48 | // |
| 49 | // @Deprecated |
| 50 | // @android.annotation.SystemApi |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 51 | class AnnotationProcessor { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 52 | public: |
Adam Lesinski | 09f4d70 | 2017-08-08 10:39:55 -0700 | [diff] [blame] | 53 | // Extracts the first sentence of a comment. The algorithm selects the substring starting from |
| 54 | // the beginning of the string, and ending at the first '.' character that is followed by a |
| 55 | // whitespace character. If these requirements are not met, the whole string is returned. |
Adam Lesinski | e967d3f | 2017-07-24 18:19:36 -0700 | [diff] [blame] | 56 | static android::StringPiece ExtractFirstSentence(const android::StringPiece& comment); |
| 57 | |
Adam Lesinski | 09f4d70 | 2017-08-08 10:39:55 -0700 | [diff] [blame] | 58 | // Adds more comments. Resources can have value definitions for various configurations, and |
| 59 | // each of the definitions may have comments that need to be processed. |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 60 | void AppendComment(const android::StringPiece& comment); |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 61 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 62 | void AppendNewLine(); |
Adam Lesinski | 7656554 | 2016-03-10 21:55:04 -0800 | [diff] [blame] | 63 | |
Adam Lesinski | 09f4d70 | 2017-08-08 10:39:55 -0700 | [diff] [blame] | 64 | // Writes the comments and annotations to the stream, with the given prefix before each line. |
| 65 | void WriteToStream(const android::StringPiece& prefix, std::ostream* out) const; |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 66 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 67 | private: |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 68 | std::stringstream comment_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 69 | std::stringstream mAnnotations; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 70 | bool has_comments_ = false; |
| 71 | uint32_t annotation_bit_mask_ = 0; |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 72 | |
Adam Lesinski | 09f4d70 | 2017-08-08 10:39:55 -0700 | [diff] [blame] | 73 | void AppendCommentLine(std::string line); |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 76 | } // namespace aapt |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 77 | |
| 78 | #endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */ |