Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPLAT-4451 Reorder suggestors and improve the UI factory ignore remover #26

Merged
merged 2 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ class UiFactoryIgnoreCommentRemover extends RecursiveAstVisitor
if (_ignoreLines.contains(initializerLineNum)) {
final currentFactory = sourceFile
.span(
node.offset,
node.metadata.beginToken.offset,
node.end,
)
.text;
final updatedFactory = currentFactory.replaceFirst(ignorePattern, '');
yieldPatch(
node.offset,
node.metadata.beginToken.offset,
node.end,
updatedFactory,
);
Expand Down
71 changes: 40 additions & 31 deletions lib/src/executables/dart2_upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,51 +83,60 @@ void main(List<String> args) {
}

final needsOverReactLibraryCollector = NeedsOverReactLibraryCollector();
final phaseTwoSuggestors = <Suggestor>[
needsOverReactLibraryCollector,
UiFactoryInitializer(includeIgnore: backwardsCompat),
ComponentDefaultPropsMigrator(),
DollarPropsMigrator(),
DollarPropKeysMigrator(),
PropsAndStateClassesRenamer(renameMixins: !backwardsCompat),
]..addAll(backwardsCompat
? [

final suggestorSequence = <Suggestor>[
AggregateSuggestor(
<Suggestor>[
needsOverReactLibraryCollector,
UiFactoryInitializer(includeIgnore: backwardsCompat),
ComponentDefaultPropsMigrator(),
DollarPropsMigrator(),
DollarPropKeysMigrator(),
PropsAndStateClassesRenamer(renameMixins: !backwardsCompat),
].map((s) => Ignoreable(s)),
),
GeneratedPartDirectiveAdder(
needsOverReactLibraryCollector,
),
];

if (backwardsCompat) {
suggestorSequence.add(
AggregateSuggestor(
<Suggestor>[
PropsAndStateCompanionClassAdder(commentPrefix: commentPrefix),
PropsAndStateMixinMetaAdder(),
PropsAndStateMixinUsageDoubler(),
]
: [
].map((s) => Ignoreable(s)),
),
);
} else {
suggestorSequence.addAll([
AggregateSuggestor(
// These suggestors mainly clean up the transitional boilerplate
// introduced by the backwards-compat suggestors. As such, they do not
// need to be ignoreable.
<Suggestor>[
GeneratedPartDirectiveIgnoreRemover(),
UiFactoryIgnoreCommentRemover(),
PropsAndStateMixinMetaRemover(),
PropsAndStateMixinUsageConsolidator(),
GeneratedPartDirectiveIgnoreRemover(),
OrcmIgnoreRemover(),
]);

final phaseThreeSuggestors = <Suggestor>[
Ignoreable(
GeneratedPartDirectiveAdder(
needsOverReactLibraryCollector,
PropsAndStateCompanionClassRemover(),
],
),
),
];
if (!backwardsCompat) {
phaseThreeSuggestors.add(PropsAndStateCompanionClassRemover());
// The orcm_ignore comments could be anywhere in the source, which makes
// them a high-risk for producing overlapping patches with other
// suggestors. For that reason, we run it by itself and not in aggregate.
OrcmIgnoreRemover(),
]);
}

exitCode = runInteractiveCodemodSequence(
FileQuery.dir(
pathFilter: isDartFile,
recursive: true,
),
[
AggregateSuggestor(
phaseTwoSuggestors.map((s) => Ignoreable(s)),
),
AggregateSuggestor(
phaseThreeSuggestors.map((s) => Ignoreable(s)),
)
],
suggestorSequence,
args: args,
defaultYes: true,
changesRequiredOutput: _changesRequiredOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ UiFactory Foo =
UiFactory<_CustomColorInputProps> _CustomColorInput = _$_CustomColorInput;
<<<
@Factory()
UiFactory<_CustomColorInputProps> _CustomColorInput = _$_CustomColorInput;
UiFactory<_CustomColorInputProps> _CustomColorInput = _$_CustomColorInput;


>>> factory with doc comment (patches 1)
/// Doc comment.
/// Line 2.
/// Line 3.
@Factory()
UiFactory Foo =
// ignore: undefined_identifier
_$Foo;
<<<
/// Doc comment.
/// Line 2.
/// Line 3.
@Factory()
UiFactory Foo =
_$Foo;