Skip to content

Commit

Permalink
Use Dictionary as const& to Rewriter constructors.
Browse files Browse the repository at this point in the history
#codehealth

PiperOrigin-RevId: 723744125
  • Loading branch information
hiroyuki-komatsu committed Feb 6, 2025
1 parent 2fd4185 commit 380f4f3
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/converter/converter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ TEST_F(ConverterTest, IntegrationWithDateRewriter) {
// Since DateRewriter is not used in some build targets, the test needs to
// explicitly add it to the converter.
std::unique_ptr<Converter> converter = CreateConverter(
std::make_unique<DateRewriter>(&dictionary), STUB_PREDICTOR);
std::make_unique<DateRewriter>(dictionary), STUB_PREDICTOR);

{
Segments segments;
Expand Down
4 changes: 2 additions & 2 deletions src/rewriter/date_rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ struct DateCandidate {
class DateRewriter : public RewriterInterface {
public:
DateRewriter() = default;
explicit DateRewriter(const dictionary::DictionaryInterface *dictionary)
: dictionary_(dictionary) {}
explicit DateRewriter(const dictionary::DictionaryInterface &dictionary)
: dictionary_(&dictionary) {}

int capability(const ConversionRequest &request) const override;

Expand Down
8 changes: 4 additions & 4 deletions src/rewriter/date_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ TEST_F(DateRewriterTest, ExtraFormatTest) {
.WillOnce(InvokeCallbackWithUserDictionaryToken{"{YEAR}{MONTH}{DATE}"});

MockConverter converter;
DateRewriter rewriter(&dictionary);
DateRewriter rewriter(dictionary);

Segments segments;
InitSegment("きょう", "今日", &segments);
Expand Down Expand Up @@ -1158,7 +1158,7 @@ TEST_F(DateRewriterTest, ExtraFormatSyntaxTest) {
LookupExact(StrEq(DateRewriter::kExtraFormatKey), _, _))
.WillOnce(InvokeCallbackWithUserDictionaryToken{std::string(input)});
MockConverter converter;
DateRewriter rewriter(&dictionary);
DateRewriter rewriter(dictionary);
Segments segments;
InitSegment("きょう", "今日", &segments);
const ConversionRequest request;
Expand Down Expand Up @@ -1278,7 +1278,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST_P(RewriteAdTest, MockConverter) {
const RewriteAdData &data = GetParam();
MockDictionary dictionary;
DateRewriter rewriter(&dictionary);
DateRewriter rewriter(dictionary);
Segments segments;
for (const auto &[key, value] : data.segments) {
AppendSegment(key, value, &segments);
Expand Down Expand Up @@ -1314,7 +1314,7 @@ TEST_P(RewriteAdTest, MockConverter) {
// Test if `Segments::set_resized(true)` prevents merging segments.
TEST_F(DateRewriterTest, RewriteAdResizedSegments) {
MockDictionary dictionary;
DateRewriter rewriter(&dictionary);
DateRewriter rewriter(dictionary);
Segments segments;
InitSegment("へいせい", "平成", &segments);
AppendSegment("23", "23", &segments);
Expand Down
4 changes: 2 additions & 2 deletions src/rewriter/language_aware_rewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ using dictionary::DictionaryInterface;
using dictionary::PosMatcher;

LanguageAwareRewriter::LanguageAwareRewriter(
const PosMatcher &pos_matcher, const DictionaryInterface *dictionary)
: unknown_id_(pos_matcher.GetUnknownId()), dictionary_(dictionary) {}
const PosMatcher &pos_matcher, const DictionaryInterface &dictionary)
: unknown_id_(pos_matcher.GetUnknownId()), dictionary_(&dictionary) {}

LanguageAwareRewriter::~LanguageAwareRewriter() = default;

Expand Down
2 changes: 1 addition & 1 deletion src/rewriter/language_aware_rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace mozc {
class LanguageAwareRewriter : public RewriterInterface {
public:
LanguageAwareRewriter(const dictionary::PosMatcher &pos_matcher,
const dictionary::DictionaryInterface *dictionary);
const dictionary::DictionaryInterface &dictionary);
LanguageAwareRewriter(const LanguageAwareRewriter &) = delete;
LanguageAwareRewriter &operator=(const LanguageAwareRewriter &) = delete;
~LanguageAwareRewriter() override;
Expand Down
8 changes: 4 additions & 4 deletions src/rewriter/language_aware_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ constexpr auto IsLangAwareCandidate =
TEST_F(LanguageAwareRewriterTest, LanguageAwareInput) {
MockDictionary dictionary;
LanguageAwareRewriter rewriter(PosMatcher(data_manager_.GetPosMatcherData()),
&dictionary);
dictionary);
{
// "python" is composed to "pyてょn", but "python" should be suggested,
// because alphabet characters are in the middle of the word.
Expand Down Expand Up @@ -304,7 +304,7 @@ TEST_F(LanguageAwareRewriterTest, LanguageAwareInput) {
TEST_F(LanguageAwareRewriterTest, LanguageAwareInputUsageStats) {
MockDictionary dictionary;
LanguageAwareRewriter rewriter(PosMatcher(data_manager_.GetPosMatcherData()),
&dictionary);
dictionary);

EXPECT_STATS_NOT_EXIST("LanguageAwareSuggestionTriggered");
EXPECT_STATS_NOT_EXIST("LanguageAwareSuggestionCommitted");
Expand Down Expand Up @@ -368,7 +368,7 @@ TEST_F(LanguageAwareRewriterTest, LanguageAwareInputUsageStats) {
TEST_F(LanguageAwareRewriterTest, NotRewriteFullWidthAsciiToHalfWidthAscii) {
MockDictionary dictionary;
LanguageAwareRewriter rewriter(PosMatcher(data_manager_.GetPosMatcherData()),
&dictionary);
dictionary);
{
// "1d*=" is composed to "1d*=", which are the full width ascii
// characters of "1d*=". We do not want to rewrite full width ascii to
Expand Down Expand Up @@ -413,7 +413,7 @@ TEST_F(LanguageAwareRewriterTest, IsDisabledInTwelveKeyLayout) {

MockDictionary dictionary;
LanguageAwareRewriter rewriter(PosMatcher(data_manager_.GetPosMatcherData()),
&dictionary);
dictionary);
for (const auto &param : kParams) {
commands::Request request;
request.set_language_aware_input(
Expand Down
2 changes: 1 addition & 1 deletion src/rewriter/rewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace mozc {

Rewriter::Rewriter(const engine::Modules &modules) {
const DataManager &data_manager = modules.GetDataManager();
const dictionary::DictionaryInterface *dictionary = modules.GetDictionary();
const dictionary::DictionaryInterface &dictionary = *modules.GetDictionary();
const dictionary::PosMatcher &pos_matcher = *modules.GetPosMatcher();
const dictionary::PosGroup *pos_group = modules.GetPosGroup();

Expand Down
4 changes: 2 additions & 2 deletions src/rewriter/usage_rewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ namespace mozc {
using ::mozc::dictionary::DictionaryInterface;

UsageRewriter::UsageRewriter(const DataManager &data_manager,
const DictionaryInterface *dictionary)
const DictionaryInterface &dictionary)
: pos_matcher_(data_manager.GetPosMatcherData()),
dictionary_(dictionary),
dictionary_(&dictionary),
base_conjugation_suffix_(nullptr) {
absl::string_view base_conjugation_suffix_data;
absl::string_view conjugation_suffix_data;
Expand Down
2 changes: 1 addition & 1 deletion src/rewriter/usage_rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace mozc {
class UsageRewriter : public RewriterInterface {
public:
UsageRewriter(const DataManager &data_manager,
const dictionary::DictionaryInterface *dictionary);
const dictionary::DictionaryInterface &dictionary);
~UsageRewriter() override = default;
bool Rewrite(const ConversionRequest &request,
Segments *segments) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/rewriter/usage_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ class UsageRewriterTest : public testing::TestWithTempUserProfile {
}

UsageRewriter *CreateUsageRewriter() const {
return new UsageRewriter(*data_manager_, user_dictionary_.get());
return new UsageRewriter(*data_manager_, *user_dictionary_);
}

UsageRewriter *CreateUsageRewriterWithTestDataManager() const {
return new UsageRewriter(*test_data_manager_, user_dictionary_.get());
return new UsageRewriter(*test_data_manager_, *user_dictionary_);
}

static ConversionRequest ConvReq(const config::Config &config,
Expand Down

0 comments on commit 380f4f3

Please sign in to comment.