• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sstream>
21 #include <string>
22 
23 #include "androidfw/StringPiece.h"
24 
25 namespace aapt {
26 
27 /**
28  * Builds a JavaDoc comment from a set of XML comments.
29  * This will also look for instances of @SystemApi and convert them to
30  * actual Java annotations.
31  *
32  * Example:
33  *
34  * Input XML:
35  *
36  * <!-- This is meant to be hidden because
37  *      It is system api. Also it is @deprecated
38  *      @SystemApi
39  *      -->
40  *
41  * Output JavaDoc:
42  *
43  *  /\*
44  *   * This is meant to be hidden because
45  *   * It is system api. Also it is @deprecated
46  *   *\/
47  *
48  * Output Annotations:
49  *
50  * @Deprecated
51  * @android.annotation.SystemApi
52  *
53  */
54 class AnnotationProcessor {
55  public:
56   /**
57    * Adds more comments. Since resources can have various values with different
58    * configurations,
59    * we need to collect all the comments.
60    */
61   void AppendComment(const android::StringPiece& comment);
62 
63   void AppendNewLine();
64 
65   /**
66    * Writes the comments and annotations to the stream, with the given prefix
67    * before each line.
68    */
69   void WriteToStream(std::ostream* out, const android::StringPiece& prefix) const;
70 
71  private:
72   enum : uint32_t {
73     kDeprecated = 0x01,
74     kSystemApi = 0x02,
75   };
76 
77   std::stringstream comment_;
78   std::stringstream mAnnotations;
79   bool has_comments_ = false;
80   uint32_t annotation_bit_mask_ = 0;
81 
82   void AppendCommentLine(std::string& line);
83 };
84 
85 }  // namespace aapt
86 
87 #endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */
88