blob: e7f2be0dc12bf205acd8e576538c127b5b1ba092 [file] [log] [blame]
Adam Lesinskica5638f2015-10-21 14:42:43 -07001/*
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
Adam Lesinskib274e352015-11-06 15:14:35 -080022#include <sstream>
Adam Lesinskica5638f2015-10-21 14:42:43 -070023#include <string>
24
25namespace 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 * * @SystemApi
47 * *\/
48 *
49 * Output Annotations:
50 *
51 * @Deprecated
52 * @android.annotation.SystemApi
53 *
54 */
55class AnnotationProcessor {
56public:
57 /**
Adam Lesinskica5638f2015-10-21 14:42:43 -070058 * Adds more comments. Since resources can have various values with different configurations,
59 * we need to collect all the comments.
60 */
61 void appendComment(const StringPiece16& comment);
Adam Lesinski3b4cd942015-10-30 16:31:42 -070062 void appendComment(const StringPiece& comment);
Adam Lesinskica5638f2015-10-21 14:42:43 -070063
64 /**
Adam Lesinskib274e352015-11-06 15:14:35 -080065 * Writes the comments and annotations to the stream, with the given prefix before each line.
Adam Lesinskica5638f2015-10-21 14:42:43 -070066 */
Adam Lesinskib274e352015-11-06 15:14:35 -080067 void writeToStream(std::ostream* out, const StringPiece& prefix);
Adam Lesinskica5638f2015-10-21 14:42:43 -070068
69private:
Adam Lesinskib274e352015-11-06 15:14:35 -080070 enum : uint32_t {
71 kDeprecated = 0x01,
72 kSystemApi = 0x02,
73 };
74
75 std::stringstream mComment;
76 std::stringstream mAnnotations;
77 bool mHasComments = false;
78 uint32_t mAnnotationBitMask = 0;
Adam Lesinskica5638f2015-10-21 14:42:43 -070079
Adam Lesinski3b4cd942015-10-30 16:31:42 -070080 void appendCommentLine(const std::string& line);
Adam Lesinskica5638f2015-10-21 14:42:43 -070081};
82
83} // namespace aapt
84
85#endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */