[Dart] Dart-02-18: Comments
| Dart-02: Language Tour | ||
|---|---|---|
| Dart-02-01 | Important concepts | |
| Dart-02-02 | Keywords | |
| Dart-02-03 | Variables | |
| Dart-02-04 | Built-in types | |
| Dart-02-05 | Functions | |
| Dart-02-06 | Operators | |
| Dart-02-07 | Control flow statements | |
| Dart-02-08 | Exceptions | |
| Dart-02-09 | Classes | |
| Dart-02-10 | Generics | |
| Dart-02-11 | Libraries and visibility | |
| Dart-02-12 | Asynchrony support | |
| Dart-02-13 | Generators | |
| Dart-02-14 | Callable classes | |
| Dart-02-15 | Isolates | |
| Dart-02-16 | Typedefs | |
| Dart-02-17 | Metadata | |
| Dart-02-18 | Comments |
Comments
Dart는 single-line 주석, multi-line 주석 및 documentation 주석을 지원한다.
0. Example
// This is a normal, one-line comment.
/// This is a documentation comment, used to document libraries,
/// classes, and their members. Tools like IDEs and dartdoc treat
/// doc comments specially.
/* Comments like these are also supported. */
1. Single-line comments
한 줄 주석은 //로 시작한다. //와 줄 끝 사이의 모든 것은 Dart compiler에서 무시된다.
void main() {
// TODO: refactor into an AbstractLlamaGreetingFactory?
print('Welcome to my Llama farm!');
}
2. Multi-line comments
여러 줄 주석은 /*로 시작하고 */로 끝난다. /*와 */ 사이의 모든 것은 (주석이 documentation 주석이 아닌 경우) Dart compiler에서 무시된다. 여러 줄 주석은 중첩될 수 있다.
void main() {
/*
* This is a lot of work. Consider raising chickens.
Llama larry = Llama();
larry.feed();
larry.exercise();
larry.clean();
*/
}
3. Documentation comments
documentation 주석은 /// 또는 /**로 시작하는 여러 줄 또는 한 줄 주석이다. ///를 사용하면 여러 줄의 documentation 주석과 같은 효과가 있다.
documentation 주석 내에서 analyzer는 대괄호로 묶이지 않는 한 모든 text를 무시한다. 대괄호를 사용하여 class, method, field, top-level 변수, function, parameter를 참조할 수 있다. 괄호 안의 name은 document화된 program element의 어휘 범위에서 확인된다.
다음은 다른 class 및 argument에 대한 참조가 포함된 documentation 주석의 예이다:
/// A domesticated South American camelid (lama glama).
///
/// Andean cultures have used llamas as meat and pack
/// animals since pre-Hispanic times.
///
/// Just like any other animal, llamas need to eat,
/// so don't forget to [feed] them some [Food].
class Llama {
String? name;
/// Feeds you llama [food].
///
/// The typical llama eats one bale of hay per week.
void feed(Food food) {
// ...
}
/// Exercises you llama with an [activity] for
/// [timeLimit] minutes.
void exercise(Activity activity, int timeLimit) {
// ...
}
}
class의 생성된 documentation에서, [feed]는 feed method 문서에 대한 link가 되고, [Food]는 Food class 문서에 대한 link가 된다.
Dart code를 구문 분석하고 HTML 문서를 생성하려면, Dart의 문서 생성 도구인 dart doc를 사용할 수 있다.
댓글남기기