@@ -253,22 +253,19 @@ class ChunkBuilder {
253253 // Edge case: if the comments are completely inline (i.e. just a series of
254254 // block comments with no newlines before, after, or between them), then
255255 // they will eat any pending newlines. Make sure that doesn't happen by
256- // putting the pending whitespace before the first comment and moving them
257- // to their own line. Turns this:
256+ // putting the pending whitespace before the first comment. Turns this:
258257 //
259258 // library foo; /* a */ /* b */ import 'a.dart';
260259 //
261260 // into:
262261 //
263262 // library foo;
264263 //
265- // /* a */ /* b */
266- // import 'a.dart';
264+ // /* a */ /* b */ import 'a.dart';
267265 if (linesBeforeToken == 0 &&
268- comments. every ((comment) => comment.isInline) &&
269- _pendingWhitespace.minimumLines > 0 ) {
266+ _pendingWhitespace.minimumLines > comments.first.linesBefore &&
267+ comments. every ((comment) => comment.type == CommentType .inlineBlock) ) {
270268 comments.first.linesBefore = _pendingWhitespace.minimumLines;
271- linesBeforeToken = 1 ;
272269 }
273270
274271 // Write each comment and the whitespace between them.
@@ -284,18 +281,19 @@ class ChunkBuilder {
284281 }
285282 _emitPendingWhitespace ();
286283
287- if (comment.linesBefore == 0 ) {
284+ // See if the comment should follow text on the current line.
285+ if (comment.linesBefore == 0 || comment.type == CommentType .inlineBlock) {
288286 // If we're sitting on a split, move the comment before it to adhere it
289287 // to the preceding text.
290- if (_shouldMoveCommentBeforeSplit (comment.text )) {
288+ if (_shouldMoveCommentBeforeSplit (comment)) {
291289 _chunks.last.allowText ();
292290 }
293291
294292 // The comment follows other text, so we need to decide if it gets a
295293 // space before it or not.
296294 if (_needsSpaceBeforeComment (comment)) _writeText (' ' );
297295 } else {
298- // The comment starts a line , so make sure it stays on its own line.
296+ // The comment is not inline , so start a new line.
299297 _writeHardSplit (
300298 flushLeft: comment.flushLeft,
301299 isDouble: comment.linesBefore > 1 ,
@@ -743,17 +741,23 @@ class ChunkBuilder {
743741
744742 /// Returns `true` if the last chunk is a split that should be moved after the
745743 /// comment that is about to be written.
746- bool _shouldMoveCommentBeforeSplit (String comment) {
744+ bool _shouldMoveCommentBeforeSplit (SourceComment comment) {
747745 // Not if there is nothing before it.
748746 if (_chunks.isEmpty) return false ;
749747
748+ // Don't move a comment to a preceding line.
749+ if (comment.linesBefore != 0 ) return false ;
750+
750751 // Multi-line comments are always pushed to the next line.
751- if (comment.contains ('\n ' )) return false ;
752+ if (comment.type == CommentType .doc) return false ;
753+ if (comment.type == CommentType .block) return false ;
752754
753755 var text = _chunks.last.text;
754756
755757 // A block comment following a comma probably refers to the following item.
756- if (text.endsWith (',' ) && comment.startsWith ('/*' )) return false ;
758+ if (text.endsWith (',' ) && comment.type == CommentType .inlineBlock) {
759+ return false ;
760+ }
757761
758762 // If the text before the split is an open grouping character, it looks
759763 // better to keep it with the elements than with the bracket itself.
@@ -788,13 +792,11 @@ class ChunkBuilder {
788792 // Not at the start of a line.
789793 if (! _chunks.last.canAddText) return false ;
790794
791- var text = _chunks.last.text;
792- if (text.endsWith ('\n ' )) return false ;
793-
794795 // Always put a space before line comments.
795- if (comment.isLineComment ) return true ;
796+ if (comment.type == CommentType .line ) return true ;
796797
797798 // Magic generic method comments like "Foo/*<T>*/" don't get spaces.
799+ var text = _chunks.last.text;
798800 if (_isGenericMethodComment (comment) &&
799801 _trailingIdentifierChar.hasMatch (text)) {
800802 return false ;
0 commit comments