Skip to content

Commit 464703c

Browse files
committed
Remove TrimmerBaseline config option
1 parent e9b2377 commit 464703c

1 file changed

Lines changed: 79 additions & 127 deletions

File tree

sources/SilkTouch/SilkTouch/Mods/PrettifyNames.cs

Lines changed: 79 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public class PrettifyNames(
3535
/// </summary>
3636
public Dictionary<string, string> NameOverrides { get; init; } = [];
3737

38-
/// <summary>
39-
/// The base trimmer version. If null, trimming is disabled.
40-
/// </summary>
41-
public Version? TrimmerBaseline { get; init; } = new(3, 0);
42-
4338
/// <summary>
4439
/// The maximum length of an all capitals string to be treated as a single acronym, rather than as an all
4540
/// capitals word.
@@ -129,138 +124,95 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
129124
var nameAffixer = new PrettifyNamesAffixer(visitor.AffixTypes, cfg.Affixes);
130125
var namePrettifier = new NamePrettifier(cfg.LongAcronymThreshold);
131126

132-
// Trim the trimmable names if the trimmer baseline is set
133-
// Otherwise, we just prettify the trimmable names
134-
if (cfg.TrimmerBaseline is null)
135-
{
136-
// Only prettify the trimmable names
137-
foreach (var (name, (nonFunctions, functions)) in visitor.TrimmableTypes)
138-
{
139-
newNames[name] = new RenamedType(
140-
ApplyPrettifyOnlyPipeline(
141-
null,
142-
name,
143-
cfg.NameOverrides,
144-
nameAffixer,
145-
namePrettifier
146-
),
147-
nonFunctions.ToDictionary(
148-
x => x,
149-
x =>
150-
ApplyPrettifyOnlyPipeline(
151-
name,
152-
x,
153-
cfg.NameOverrides,
154-
nameAffixer,
155-
namePrettifier
156-
)
157-
),
158-
functions.ToDictionary(
159-
x => x.Name,
160-
x =>
161-
ApplyPrettifyOnlyPipeline(
162-
name,
163-
x.Name,
164-
cfg.NameOverrides,
165-
nameAffixer,
166-
namePrettifier
167-
)
168-
)
169-
);
170-
}
171-
}
172-
else
173-
{
174-
// Trim and prettify the trimmable names
127+
// Trim and prettify the trimmable names
175128

176-
// Define trimmers
177-
var trimmers = new INameTrimmer[]
178-
{
179-
new NameAffixerEarlyTrimmer(nameAffixer),
180-
new NameTrimmer(),
181-
new PrettifyNamesTrimmer(namePrettifier),
182-
new NameAffixerLateTrimmer(nameAffixer),
183-
new PrefixIfStartsWithNumberTrimmer(),
184-
};
129+
// Define trimmers
130+
var trimmers = new INameTrimmer[]
131+
{
132+
new NameAffixerEarlyTrimmer(nameAffixer),
133+
new NameTrimmer(),
134+
new PrettifyNamesTrimmer(namePrettifier),
135+
new NameAffixerLateTrimmer(nameAffixer),
136+
new PrefixIfStartsWithNumberTrimmer(),
137+
};
138+
139+
// Create a type name dictionary to trim the type names.
140+
var typeNames = visitor.TrimmableTypes.ToDictionary(
141+
x => x.Key,
142+
x => new CandidateNames(x.Key, [])
143+
);
185144

186-
// Create a type name dictionary to trim the type names.
187-
var typeNames = visitor.TrimmableTypes.ToDictionary(
188-
x => x.Key,
189-
x => new CandidateNames(x.Key, [])
145+
// If we don't have a prefix hint and don't have more than one type, we can't determine a prefix so don't
146+
// trim.
147+
if (typeNames.Count > 1 || cfg.GlobalPrefixHints is not null)
148+
{
149+
Trim(
150+
new NameTrimmerContext
151+
{
152+
Container = null,
153+
Names = typeNames,
154+
Configuration = cfg,
155+
JobKey = ctx.JobKey,
156+
NonDeterminant = visitor.NonDeterminant,
157+
},
158+
trimmers
190159
);
160+
}
191161

192-
// If we don't have a prefix hint and don't have more than one type, we can't determine a prefix so don't
193-
// trim.
194-
if (typeNames.Count > 1 || cfg.GlobalPrefixHints is not null)
195-
{
196-
Trim(
197-
new NameTrimmerContext
198-
{
199-
Container = null,
200-
Names = typeNames,
201-
Configuration = cfg,
202-
JobKey = ctx.JobKey,
203-
NonDeterminant = visitor.NonDeterminant,
204-
},
205-
trimmers
206-
);
207-
}
208-
209-
// Now rename everything within each type.
210-
foreach (var (typeName, (newTypeName, _)) in typeNames)
211-
{
212-
var (_, (consts, functions)) = visitor.TrimmableTypes.First(x => x.Key == typeName);
162+
// Now rename everything within each type.
163+
foreach (var (typeName, (newTypeName, _)) in typeNames)
164+
{
165+
var (_, (consts, functions)) = visitor.TrimmableTypes.First(x => x.Key == typeName);
213166

214-
// Rename the "constants" i.e. all the consts/static readonlys in this type. These are treated
215-
// individually because everything that isn't a constant or a function is only prettified instead of prettified & trimmed.
216-
var constNames = consts.ToDictionary(x => x, x => new CandidateNames(x, []));
167+
// Rename the "constants" i.e. all the consts/static readonlys in this type. These are treated
168+
// individually because everything that isn't a constant or a function is only prettified instead of prettified & trimmed.
169+
var constNames = consts.ToDictionary(x => x, x => new CandidateNames(x, []));
217170

218-
// Trim the constants.
219-
Trim(
220-
new NameTrimmerContext
221-
{
222-
Container = typeName,
223-
Names = constNames,
224-
Configuration = cfg,
225-
JobKey = ctx.JobKey,
226-
NonDeterminant = visitor.NonDeterminant,
227-
},
228-
trimmers
229-
);
171+
// Trim the constants.
172+
Trim(
173+
new NameTrimmerContext
174+
{
175+
Container = typeName,
176+
Names = constNames,
177+
Configuration = cfg,
178+
JobKey = ctx.JobKey,
179+
NonDeterminant = visitor.NonDeterminant,
180+
},
181+
trimmers
182+
);
230183

231-
// Rename the functions. More often that not functions have different nomenclature to constants, so we
232-
// treat them separately.
233-
var functionNames = functions
234-
.DistinctBy(x => x.Name)
235-
.ToDictionary(x => x.Name, x => new CandidateNames(x.Name, []));
184+
// Rename the functions. More often that not functions have different nomenclature to constants, so we
185+
// treat them separately.
186+
var functionNames = functions
187+
.DistinctBy(x => x.Name)
188+
.ToDictionary(x => x.Name, x => new CandidateNames(x.Name, []));
236189

237-
// Collect the syntax as this is used for conflict resolution in the Trim function.
238-
var functionSyntax = functionNames.Keys.ToDictionary(
239-
x => x,
240-
x => functions.Where(y => y.Name == x).Select(y => y.Syntax)
241-
);
190+
// Collect the syntax as this is used for conflict resolution in the Trim function.
191+
var functionSyntax = functionNames.Keys.ToDictionary(
192+
x => x,
193+
x => functions.Where(y => y.Name == x).Select(y => y.Syntax)
194+
);
242195

243-
// Trim the functions.
244-
Trim(
245-
new NameTrimmerContext
246-
{
247-
Container = typeName,
248-
Names = functionNames,
249-
Configuration = cfg,
250-
JobKey = ctx.JobKey,
251-
NonDeterminant = visitor.NonDeterminant,
252-
},
253-
trimmers,
254-
functionSyntax
255-
);
196+
// Trim the functions.
197+
Trim(
198+
new NameTrimmerContext
199+
{
200+
Container = typeName,
201+
Names = functionNames,
202+
Configuration = cfg,
203+
JobKey = ctx.JobKey,
204+
NonDeterminant = visitor.NonDeterminant,
205+
},
206+
trimmers,
207+
functionSyntax
208+
);
256209

257-
// Add it to the rewriter's list of names to... rewrite...
258-
newNames[typeName] = new RenamedType(
259-
newTypeName,
260-
constNames.ToDictionary(x => x.Key, x => x.Value.Primary),
261-
functionNames.ToDictionary(x => x.Key, x => x.Value.Primary)
262-
);
263-
}
210+
// Add it to the rewriter's list of names to... rewrite...
211+
newNames[typeName] = new RenamedType(
212+
newTypeName,
213+
constNames.ToDictionary(x => x.Key, x => x.Value.Primary),
214+
functionNames.ToDictionary(x => x.Key, x => x.Value.Primary)
215+
);
264216
}
265217

266218
// Prettify the prettify only names

0 commit comments

Comments
 (0)