Skip to content

Commit

Permalink
[ASTPrint] Print documentation comments for extensions and subscripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
akyrtzi committed Dec 3, 2015
1 parent 8659022 commit 7dd3046
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ void PrintAST::visitImportDecl(ImportDecl *decl) {
}

void PrintAST::visitExtensionDecl(ExtensionDecl *decl) {
printDocumentationComment(decl);
printAttributes(decl);
Printer << "extension ";
recordDeclLoc(decl,
Expand Down Expand Up @@ -1922,6 +1923,7 @@ void PrintAST::visitEnumElementDecl(EnumElementDecl *decl) {
}

void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
printDocumentationComment(decl);
printAttributes(decl);
printAccessibility(decl);
recordDeclLoc(decl,
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/RawComment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SingleRawComment::SingleRawComment(StringRef RawText, unsigned StartColumn)

static bool canHaveComment(const Decl *D) {
return !D->hasClangNode() &&
isa<ValueDecl>(D) &&
(isa<ValueDecl>(D) || isa<ExtensionDecl>(D)) &&
!isa<ParamDecl>(D) &&
(!isa<AbstractTypeParamDecl>(D) || isa<AssociatedTypeDecl>(D));
}
Expand Down
7 changes: 7 additions & 0 deletions test/IDE/print_source_file_interface_2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ public class MyClass {
func doit(x: Int) {}
}

/// This is a very nice extension.
extension MyClass {

/// and a nice subscript.
subscript(i: Int) -> Int { return 0 }
}

// RUN: %target-swift-ide-test -print-swift-file-interface -source-filename %s > %t.out
// RUN: diff -u %s.result %t.out
7 changes: 7 additions & 0 deletions test/IDE/print_source_file_interface_2.swift.result
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ public class MyClass {

internal func doit(x: Int)
}

/// This is a very nice extension.
extension MyClass {

/// and a nice subscript.
internal subscript (i: Int) -> Int { get }
}

0 comments on commit 7dd3046

Please sign in to comment.