blob: 81a6f6e4275919ab08ad427c0c445bdd059c8435 [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
22#include <string>
23
24namespace 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 */
54class AnnotationProcessor {
55public:
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);
Adam Lesinski3b4cd942015-10-30 16:31:42 -070068 void appendComment(const StringPiece& comment);
Adam Lesinskica5638f2015-10-21 14:42:43 -070069
70 /**
71 * Finishes the comment and moves it to the caller. Subsequent calls to buildComment() have
72 * undefined results.
73 */
74 std::string buildComment();
75
76 /**
77 * Finishes the annotation and moves it to the caller. Subsequent calls to buildAnnotations()
78 * have undefined results.
79 */
80 std::string buildAnnotations();
81
82private:
83 std::string mPrefix;
84 std::string mComment;
85 std::string mAnnotations;
86 bool mDeprecated = false;
87 bool mSystemApi = false;
88
Adam Lesinski3b4cd942015-10-30 16:31:42 -070089 void appendCommentLine(const std::string& line);
Adam Lesinskica5638f2015-10-21 14:42:43 -070090};
91
92} // namespace aapt
93
94#endif /* AAPT_JAVA_ANNOTATIONPROCESSOR_H */