Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
assert to enforce no nesting with scoped
  • Loading branch information
tarrinneal committed Jan 23, 2023
commit d8a1a0b199e18011cb1a257376014e541649f373
23 changes: 15 additions & 8 deletions packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import 'dart:mirrors';

import 'ast.dart';

/// The current version of pigeon. This must match the version in pubspec.yaml.
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '7.0.2';

/// Read all the content from [stdin] to a String.
Expand Down Expand Up @@ -81,15 +83,17 @@ class Indent {
}
}

/// Scoped increase of the ident level. For the execution of [func] the
/// indentation will be incremented.
/// Scoped increase of the ident level.
///
/// For the execution of [func] the indentation will be incremented.
void addScoped(
String? begin,
String? end,
Function func, {
bool addTrailingNewline = true,
int nestCount = 1,
}) {
assert(begin != '' || end != '');
if (begin != null) {
_sink.write(begin + newline);
}
Expand All @@ -109,12 +113,14 @@ class Indent {
Function func, {
bool addTrailingNewline = true,
}) {
assert(begin != '' || end != '');
addScoped(str() + (begin ?? ''), end, func,
addTrailingNewline: addTrailingNewline);
}

/// Scoped increase of the ident level. For the execution of [func] the
/// indentation will be incremented by the given amount.
/// Scoped increase of the ident level.
///
/// For the execution of [func] the indentation will be incremented by the given amount.
void nest(int count, Function func) {
inc(count);
func(); // ignore: avoid_dynamic_calls
Expand Down Expand Up @@ -270,9 +276,10 @@ void addLines(Indent indent, Iterable<String> lines, {String? linePrefix}) {
}
}

/// Recursively merges [modification] into [base]. In other words, whenever
/// there is a conflict over the value of a key path, [modification]'s value for
/// that key path is selected.
/// Recursively merges [modification] into [base].
///
/// In other words, whenever there is a conflict over the value of a key path,
/// [modification]'s value for that key path is selected.
Map<String, Object> mergeMaps(
Map<String, Object> base,
Map<String, Object> modification,
Expand Down