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 | |
| 20 | #include "util/StringPiece.h" |
| 21 | |
| 22 | #include <string> |
| 23 | |
| 24 | namespace aapt { |
| 25 | |
| 26 | /** |
| 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 | * * @SystemApi |
| 46 | * *\/ |
| 47 | * |
| 48 | * Output Annotations: |
| 49 | * |
| 50 | * @Deprecated |
| 51 | * @android.annotation.SystemApi |
| 52 | * |
| 53 | */ |
| 54 | class AnnotationProcessor { |
| 55 | public: |
| 56 | /** |
| 57 | * Creates an AnnotationProcessor with a given prefix for each line generated. |
| 58 | * This is usually a set of spaces for indentation. |
| 59 | */ |
| 60 | AnnotationProcessor(const StringPiece& prefix) : mPrefix(prefix.toString()) { |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Adds more comments. Since resources can have various values with different configurations, |
| 65 | * we need to collect all the comments. |
| 66 | */ |
| 67 | void appendComment(const StringPiece16& comment); |
| 68 | |
| 69 | /** |
| 70 | * Finishes the comment and moves it to the caller. Subsequent calls to buildComment() have |
| 71 | * undefined results. |
| 72 | */ |
| 73 | std::string buildComment(); |
| 74 | |
| 75 | /** |
| 76 | * Finishes the annotation and moves it to the caller. Subsequent calls to buildAnnotations() |
| 77 | * have undefined results. |
| 78 | */ |
| 79 | std::string buildAnnotations(); |
| 80 | |
| 81 | private: |
| 82 | std::string mPrefix; |
| 83 | std::string mComment; |
| 84 | std::string mAnnotations; |
| 85 | bool mDeprecated = false; |
| 86 | bool mSystemApi = false; |
| 87 | |
| 88 | void appendCommentLine(const StringPiece16& line); |
| 89 | }; |
| 90 | |
| 91 | } // namespace aapt |
| 92 | |
| 93 | #endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */ |