mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Add Prototype analyzer * Add Prototype fixer * Early return after finding prototype attribute * Add PrototypeEndsWithPrototypeRule diagnostic * Oops. Uncomment parallelizable. * Rework to ignore redundancy for non-literal string values * Allow redundancy when removal would expose class name not ending in "Prototype" * Promote PrototypeEndsWithPrototypeRule from warning to error, since it causes a runtime error. * No need to get the symbol to get the class identifier * Minor cleanup * A little more cleanup * More specific location for redundant name * Refactor redundant name fixer so argument order is no longer important * Add failing test * Use symbol analysis to fix alias handling * Oops! We have to go back to the previous syntax-based approach. Now it's a hybrid. Also fixed tests to not copy the prototype definitions. --------- Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
24 lines
753 B
C#
24 lines
753 B
C#
using System;
|
|
|
|
namespace Robust.Shared.Prototypes;
|
|
|
|
public static class PrototypeUtility
|
|
{
|
|
/// <summary>
|
|
/// Prototypes using autogenerated names are required to end in this string.
|
|
/// </summary>
|
|
public const string PrototypeNameEnding = "Prototype";
|
|
|
|
/// <summary>
|
|
/// Given the type name of a Prototype, returns an autogenerated name for it.
|
|
/// </summary>
|
|
public static string CalculatePrototypeName(string type)
|
|
{
|
|
var name = type.AsSpan();
|
|
if (!type.EndsWith(PrototypeNameEnding))
|
|
return $"{char.ToLowerInvariant(name[0])}{name.Slice(1).ToString()}";
|
|
|
|
return $"{char.ToLowerInvariant(name[0])}{name.Slice(1, name.Length - PrototypeNameEnding.Length - 1).ToString()}";
|
|
}
|
|
}
|