• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 DOC_COMMENT_H_
18 
19 #define DOC_COMMENT_H_
20 
21 #include <hidl-util/Formatter.h>
22 
23 #include <string>
24 #include <vector>
25 
26 #include "Location.h"
27 
28 namespace android {
29 
30 enum class CommentType {
31     // when no particular style is specified
32     UNSPECIFIED,
33 
34     // multiline comment that begins with /**
35     DOC_MULTILINE,
36     // begins with /* (used for headers)
37     MULTILINE,
38     // begins with '//'
39     SINGLELINE,
40 };
41 
42 struct DocComment {
43     // parse comment and remove leading comment characters
44     DocComment(const std::string& comment, const Location& location,
45                CommentType type = CommentType::UNSPECIFIED);
46     // raw comment
47     DocComment(const std::vector<std::string>& lines, const Location& location,
48                CommentType type = CommentType::UNSPECIFIED);
49 
50     void merge(const DocComment* comment);
51 
52     void emit(Formatter& out, CommentType type = CommentType::UNSPECIFIED) const;
53 
linesDocComment54     const std::vector<std::string>& lines() const { return mLines; }
55 
locationDocComment56     const Location& location() const { return mLocation; }
57 
58   private:
59     std::vector<std::string> mLines;
60     CommentType mType;
61     Location mLocation;
62 };
63 
64 struct DocCommentable {
setDocCommentDocCommentable65     void setDocComment(const DocComment* docComment) { mDocComment = docComment; }
emitDocCommentDocCommentable66     void emitDocComment(Formatter& out) const {
67         if (mDocComment != nullptr) {
68             mDocComment->emit(out);
69         }
70     }
71 
getDocCommentDocCommentable72     const DocComment* getDocComment() const { return mDocComment; }
73 
74   private:
75     const DocComment* mDocComment = nullptr;
76 };
77 
78 }  // namespace android
79 
80 #endif  // DOC_COMMENT_H_
81