• 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 #include "text/Printer.h"
26 
27 namespace aapt {
28 
29 // Builds a JavaDoc comment from a set of XML comments.
30 // This will also look for instances of @SystemApi and convert them to
31 // actual Java annotations.
32 //
33 // Example:
34 //
35 // Input XML:
36 //
37 // <!-- This is meant to be hidden because
38 //      It is system api. Also it is @deprecated
39 //      @SystemApi
40 //      -->
41 //
42 // Output JavaDoc:
43 //
44 //  /**
45 //   * This is meant to be hidden because
46 //   * It is system api. Also it is @deprecated
47 //   */
48 //
49 // Output Annotations:
50 //
51 // @Deprecated
52 // @android.annotation.SystemApi
53 class AnnotationProcessor {
54  public:
55   // Extracts the first sentence of a comment. The algorithm selects the substring starting from
56   // the beginning of the string, and ending at the first '.' character that is followed by a
57   // whitespace character. If these requirements are not met, the whole string is returned.
58   static android::StringPiece ExtractFirstSentence(const android::StringPiece& comment);
59 
60   // Adds more comments. Resources can have value definitions for various configurations, and
61   // each of the definitions may have comments that need to be processed.
62   void AppendComment(const android::StringPiece& comment);
63 
64   void AppendNewLine();
65 
66   // Writes the comments and annotations to the Printer.
67   void Print(text::Printer* printer) const;
68 
69  private:
70   std::stringstream comment_;
71   std::stringstream mAnnotations;
72   bool has_comments_ = false;
73   uint32_t annotation_bit_mask_ = 0;
74 
75   void AppendCommentLine(std::string line);
76 };
77 
78 }  // namespace aapt
79 
80 #endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */
81