diff options
author | Eric Liu <ioeric@google.com> | 2016-08-01 10:16:37 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2016-08-01 10:16:37 +0000 |
commit | 85c0fa18d965d4ed91e037a085e4c20bcea7e27f (patch) | |
tree | c01feb771ce1fadf36ee0e2473b001d3405458bd /lib/Format/SortJavaScriptImports.cpp | |
parent | 1505139f741e601408dc4aaddf8e352d28085f00 (diff) |
Implement tooling::Replacements as a class.
Summary:
- Implement clang::tooling::Replacements as a class to provide interfaces to
control how replacements for a single file are combined and provide guarantee
on the order of replacements being applied.
- tooling::Replacements only contains replacements for the same file now.
Use std::map<std::string, tooling::Replacements> to represent multi-file
replacements.
- Error handling for the interface change will be improved in followup patches.
Reviewers: djasper, klimek
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D21748
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277335 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/SortJavaScriptImports.cpp')
-rw-r--r-- | lib/Format/SortJavaScriptImports.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Format/SortJavaScriptImports.cpp b/lib/Format/SortJavaScriptImports.cpp index 32d5d756a3..e800007f79 100644 --- a/lib/Format/SortJavaScriptImports.cpp +++ b/lib/Format/SortJavaScriptImports.cpp @@ -127,7 +127,8 @@ public: tooling::Replacements analyze(TokenAnnotator &Annotator, SmallVectorImpl<AnnotatedLine *> &AnnotatedLines, - FormatTokenLexer &Tokens, tooling::Replacements &Result) override { + FormatTokenLexer &Tokens, tooling::Replacements &) override { + tooling::Replacements Result; AffectedRangeMgr.computeAffectedLines(AnnotatedLines.begin(), AnnotatedLines.end()); @@ -192,9 +193,14 @@ public: DEBUG(llvm::dbgs() << "Replacing imports:\n" << getSourceText(InsertionPoint) << "\nwith:\n" << ReferencesText << "\n"); - Result.insert(tooling::Replacement( + auto Err = Result.add(tooling::Replacement( Env.getSourceManager(), CharSourceRange::getCharRange(InsertionPoint), ReferencesText)); + // FIXME: better error handling. For now, just print error message and skip + // the replacement for the release version. + if (Err) + llvm::errs() << llvm::toString(std::move(Err)) << "\n"; + assert(!Err); return Result; } |