-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from smoogipoo/settingsource-attribute
Add analyser + codefix for SettingSourceAttribute
- Loading branch information
Showing
14 changed files
with
166 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
LocalisationAnalyser.Tests/Resources/Analysers/SettingSourceAttribute/Program.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using osu.Game.Configuration; | ||
|
||
namespace Test | ||
{ | ||
class Program | ||
{ | ||
[SettingSource(typeof(object), [|"a"|])] | ||
[SettingSource(typeof(object), [|"a"|], [|"b"|])] | ||
[SettingSource([|"a"|])] | ||
[SettingSource([|"a"|], [|"b"|])] | ||
[SettingSource(typeof(object), [|"a"|], [|"b"|], 0)] | ||
[SettingSource([|"a"|], [|"b"|], 0)] | ||
static void Main() | ||
{ | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ser.Tests/Resources/CodeFixes/SettingSourceAttribute/Fixed/Localisation/Class1Strings.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using osu.Framework.Localisation; | ||
|
||
namespace TestProject.Localisation | ||
{ | ||
public static class Class1Strings | ||
{ | ||
private const string prefix = @"TestProject.Localisation.Class1"; | ||
|
||
/// <summary> | ||
/// "abc" | ||
/// </summary> | ||
public static LocalisableString Abc => new TranslatableString(getKey(@"abc"), @"abc"); | ||
|
||
/// <summary> | ||
/// "def" | ||
/// </summary> | ||
public static LocalisableString Def => new TranslatableString(getKey(@"def"), @"def"); | ||
|
||
private static string getKey(string key) => $@"{prefix}:{key}"; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
LocalisationAnalyser.Tests/Resources/CodeFixes/SettingSourceAttribute/Fixed/Program.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.ComponentModel; | ||
using osu.Game.Configuration; | ||
using TestProject.Localisation; | ||
|
||
namespace Test | ||
{ | ||
[SettingSource(typeof(Class1Strings), nameof(Class1Strings.Abc))] | ||
[SettingSource(typeof(Class1Strings), nameof(Class1Strings.Abc), nameof(Class1Strings.Def))] | ||
[SettingSource(typeof(Class1Strings), nameof(Class1Strings.Abc), nameof(Class1Strings.Def), 1)] | ||
class Class1 | ||
{ | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...r.Tests/Resources/CodeFixes/SettingSourceAttribute/Sources/Localisation/Class1Strings.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using osu.Framework.Localisation; | ||
|
||
namespace TestProject.Localisation | ||
{ | ||
public static class Class1Strings | ||
{ | ||
private const string prefix = @"TestProject.Localisation.Class1"; | ||
|
||
/// <summary> | ||
/// "abc" | ||
/// </summary> | ||
public static LocalisableString Abc => new TranslatableString(getKey(@"abc"), @"abc"); | ||
|
||
/// <summary> | ||
/// "def" | ||
/// </summary> | ||
public static LocalisableString Def => new TranslatableString(getKey(@"def"), @"def"); | ||
|
||
private static string getKey(string key) => $@"{prefix}:{key}"; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
LocalisationAnalyser.Tests/Resources/CodeFixes/SettingSourceAttribute/Sources/Program.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.ComponentModel; | ||
using osu.Game.Configuration; | ||
|
||
namespace Test | ||
{ | ||
[SettingSource([|"abc"|])] | ||
[SettingSource([|"abc"|], [|"def"|])] | ||
[SettingSource([|"abc"|], [|"def"|], 1)] | ||
class Class1 | ||
{ | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
LocalisationAnalyser.Tests/Resources/SettingSourceAttribute.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace osu.Game.Configuration | ||
{ | ||
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple = true)] | ||
public class SettingSourceAttribute : System.Attribute | ||
{ | ||
public string Label { get; } | ||
|
||
public string Description { get; } | ||
|
||
public SettingSourceAttribute(System.Type declaringType, string label, string? description = null) | ||
{ | ||
} | ||
|
||
public SettingSourceAttribute(string? label, string? description = null) | ||
{ | ||
} | ||
|
||
public SettingSourceAttribute(System.Type declaringType, string label, string description, int orderPosition) | ||
: this(declaringType, label, description) | ||
{ | ||
} | ||
|
||
public SettingSourceAttribute(string label, string description, int orderPosition) | ||
: this(label, description) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters