blob: a06eda0f9c5c742c47674a72435268b0965dff17 [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
Adam Lesinskib274e352015-11-06 15:14:35 -080020#include <sstream>
Adam Lesinskica5638f2015-10-21 14:42:43 -070021#include <string>
22
Adam Lesinskid5083f62017-01-16 15:07:21 -080023#include "androidfw/StringPiece.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070024
Adam Lesinskica5638f2015-10-21 14:42:43 -070025namespace 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
Adam Lesinskica5638f2015-10-21 14:42:43 -070046 * *\/
47 *
48 * Output Annotations:
49 *
50 * @Deprecated
51 * @android.annotation.SystemApi
52 *
53 */
54class AnnotationProcessor {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070055 public:
Adam Lesinski18dc03a2017-07-24 18:19:36 -070056 static android::StringPiece ExtractFirstSentence(const android::StringPiece& comment);
57
Adam Lesinskicacb28f2016-10-19 12:18:14 -070058 /**
59 * Adds more comments. Since resources can have various values with different
60 * configurations,
61 * we need to collect all the comments.
62 */
Adam Lesinskid5083f62017-01-16 15:07:21 -080063 void AppendComment(const android::StringPiece& comment);
Adam Lesinskica5638f2015-10-21 14:42:43 -070064
Adam Lesinskice5e56e2016-10-21 17:56:45 -070065 void AppendNewLine();
Adam Lesinski76565542016-03-10 21:55:04 -080066
Adam Lesinskicacb28f2016-10-19 12:18:14 -070067 /**
68 * Writes the comments and annotations to the stream, with the given prefix
69 * before each line.
70 */
Adam Lesinskid5083f62017-01-16 15:07:21 -080071 void WriteToStream(std::ostream* out, const android::StringPiece& prefix) const;
Adam Lesinskica5638f2015-10-21 14:42:43 -070072
Adam Lesinskicacb28f2016-10-19 12:18:14 -070073 private:
74 enum : uint32_t {
75 kDeprecated = 0x01,
76 kSystemApi = 0x02,
77 };
Adam Lesinskib274e352015-11-06 15:14:35 -080078
Adam Lesinskice5e56e2016-10-21 17:56:45 -070079 std::stringstream comment_;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070080 std::stringstream mAnnotations;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070081 bool has_comments_ = false;
82 uint32_t annotation_bit_mask_ = 0;
Adam Lesinskica5638f2015-10-21 14:42:43 -070083
Adam Lesinskice5e56e2016-10-21 17:56:45 -070084 void AppendCommentLine(std::string& line);
Adam Lesinskica5638f2015-10-21 14:42:43 -070085};
86
Adam Lesinskicacb28f2016-10-19 12:18:14 -070087} // namespace aapt
Adam Lesinskica5638f2015-10-21 14:42:43 -070088
89#endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */