Skip to content

Commit 1507810

Browse files
authored
Update IViewFor Generator for Performance (#100)
* Update IViewFor Generator for Performance * Remove test apps
1 parent a76db90 commit 1507810

File tree

7 files changed

+433
-604
lines changed

7 files changed

+433
-604
lines changed

src/ReactiveUI.SourceGenerators.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 17
2+
# 17
33
VisualStudioVersion = 17.10.35027.167
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionConfig", "SolutionConfig", "{F29AF2F3-DEC8-58BC-043A-1447862C832D}"

src/ReactiveUI.SourceGenerators/AnalyzerReleases.Shipped.md

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,82 @@
1+
; Shipped analyzer releases
2+
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3+
4+
## Release 1.0
5+
6+
### New Rules
7+
8+
Rule ID | Category | Severity | Notes
9+
--------|----------|----------|-------
10+
RXUISG0001 | ReactiveUI.SourceGenerators.UnsupportedCSharpLanguageVersionAnalyzer | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
11+
RXUISG0002 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
12+
RXUISG0003 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
13+
RXUISG0004 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
14+
RXUISG0005 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
15+
RXUISG0006 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
16+
RXUISG0007 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
17+
RXUISG0008 | ReactiveUI.SourceGenerators.AsyncVoidReturningReactiveCommandMethodAnalyzer | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
18+
RXUISG0009 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
19+
RXUISG0010 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
20+
RXUISG0011 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
21+
RXUISG0012 | ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
22+
RXUISG0013 | ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
23+
RXUISG0014 | ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
24+
RXUISG0015 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
25+
RXUISG0016 | ReactiveUI.SourceGenerators.PropertyToReactiveFieldCodeFixProvider | Info | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
26+
RXUISG0017 | ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
27+
28+
129
## Rules
230
Shipped in ReactiveUI.SourceGenerators
331

4-
### RXUISG0001 - Unsupported C# Language Version
5-
This rule checks if the project is using an unsupported C# language version. The supported versions are C# 7.3 and above. If the project is using an unsupported version, the rule will raise an error.
32+
- RXUISG0001 - Unsupported C# Language Version
33+
This rule checks if the project is using an unsupported C# language version. The supported versions are C# 12.0 and above. If the project is using an unsupported version, the rule will raise an error.
634

7-
### RXUISG0002 - ReactiveCommandGenerator
35+
- RXUISG0002 - ReactiveCommandGenerator
836
This rule checks if the `ReactiveCommand` has a Invalid ReactiveCommand method signature.
937

10-
### RXUISG0003 - ReactiveCommandGenerator
38+
- RXUISG0003 - ReactiveCommandGenerator
1139
This rule checks if the `ReactiveCommand` has a Invalid ReactiveCommand.CanExecute member name.
1240

13-
### RXUISG0004 - ReactiveCommandGenerator
41+
- RXUISG0004 - ReactiveCommandGenerator
1442
This rule checks if the `ReactiveCommand` has Multiple ReactiveCommand.CanExecute member name matches.
1543

16-
### RXUISG0005 - ReactiveCommandGenerator
44+
- RXUISG0005 - ReactiveCommandGenerator
1745
This rule checks if the `ReactiveCommand` has No valid ReactiveCommand.CanExecute member match.
1846

19-
### RXUISG0006 - ReactiveCommandGenerator
47+
- RXUISG0006 - ReactiveCommandGenerator
2048
This rule checks if the `ReactiveCommand` has Invalid field or property targeted attribute type.
2149

22-
### RXUISG0007 - ReactiveCommandGenerator
50+
- RXUISG0007 - ReactiveCommandGenerator
2351
This rule checks if the `ReactiveCommand` has Invalid field or property targeted attribute expression.
2452

25-
### RXUISG0008 - AsyncVoidReturningReactiveCommandMethodAnalyzer
53+
- RXUISG0008 - AsyncVoidReturningReactiveCommandMethodAnalyzer
2654
This rule checks if the `ReactiveCommand` has Async void returning method annotated with ReactiveCommand.
2755

28-
### RXUISG0009 - ReactiveGenerator
56+
- RXUISG0009 - ReactiveGenerator
2957
This rule checks if the `Reactive` has Name collision for generated property.
3058

31-
### RXUISG0010 - ReactiveGenerator
59+
- RXUISG0010 - ReactiveGenerator
3260
This rule checks if the `Reactive` has Invalid property targeted attribute type.
3361

34-
### RXUISG0011 - ReactiveGenerator
62+
- RXUISG0011 - ReactiveGenerator
3563
This rule checks if the `Reactive` has Invalid property targeted attribute expression.
3664

37-
### RXUISG0012 - ObservableAsPropertyGenerator
65+
- RXUISG0012 - ObservableAsPropertyGenerator
3866
This rule checks if the `ObservableAsProperty` has Invalid property targeted attribute type.
3967

40-
### RXUISG0013 - ObservableAsPropertyGenerator
68+
- RXUISG0013 - ObservableAsPropertyGenerator
4169
This rule checks if the `ObservableAsProperty` has Invalid property targeted attribute expression.
4270

43-
### RXUISG0014 - ObservableAsPropertyGenerator
71+
- RXUISG0014 - ObservableAsPropertyGenerator
4472
This rule checks if the `ObservableAsProperty` has Invalid generated property declaration.
4573

46-
### RXUISG0015 - ReactiveGenerator
74+
- RXUISG0015 - ReactiveGenerator
4775
This rule checks if the `Reactive` attribute is being used correctly. If the `Reactive` has Invalid generated property declaration.
4876

49-
### RXUISG0016 - PropertyToReactiveFieldCodeFixProvider
77+
- RXUISG0016 - PropertyToReactiveFieldCodeFixProvider
5078
This rule checks if there are any Properties to change to Reactive Field, change to [Reactive] private type _fieldName;.
5179

52-
### RXUISG0017 - ObservableAsPropertyFromObservableGenerator
80+
- RXUISG0017 - ObservableAsPropertyFromObservableGenerator
5381
This rule checks if the `ObservableAsProperty` has Invalid generated property declaration.
5482

55-
56-
## Release 1.0
57-
58-
### New Rules
59-
60-
Rule ID | Category | Severity | Notes
61-
--------|----------|----------|-------
62-
RXUISG0001 | ReactiveUI.SourceGenerators.UnsupportedCSharpLanguageVersionAnalyzer | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
63-
RXUISG0002 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
64-
RXUISG0003 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
65-
RXUISG0004 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
66-
RXUISG0005 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
67-
RXUISG0006 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
68-
RXUISG0007 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
69-
RXUISG0008 | ReactiveUI.SourceGenerators.AsyncVoidReturningReactiveCommandMethodAnalyzer | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
70-
RXUISG0009 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
71-
RXUISG0010 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
72-
RXUISG0011 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
73-
RXUISG0012 | ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
74-
RXUISG0013 | ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
75-
RXUISG0014 | ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
76-
RXUISG0015 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
77-
RXUISG0016 | ReactiveUI.SourceGenerators.PropertyToReactiveFieldCodeFixProvider | Info | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
78-
RXUISG0017 | ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator | Error | See https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code.html
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
[Unshipped analyzer release](https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)
1+
; Unshipped analyzer releases
2+
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

src/ReactiveUI.SourceGenerators/Core/Extensions/AttributeDataExtensions.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,76 @@ public static string FormatAttributes(this PropertyAttributeData attr)
193193

194194
return $"[{namespacePrefix}{attr.AttributeSyntax}]";
195195
}
196+
197+
/// <summary>
198+
/// Gathers the forwarded attributes from class.
199+
/// </summary>
200+
/// <param name="attributeData">The attribute data.</param>
201+
/// <param name="semanticModel">The semantic model.</param>
202+
/// <param name="classDeclaration">The class declaration.</param>
203+
/// <param name="token">The token.</param>
204+
/// <param name="classAttributesInfo">The class attributes information.</param>
205+
public static void GatherForwardedAttributesFromClass(
206+
this AttributeData attributeData,
207+
SemanticModel semanticModel,
208+
ClassDeclarationSyntax classDeclaration,
209+
CancellationToken token,
210+
out ImmutableArray<AttributeInfo> classAttributesInfo)
211+
{
212+
using var classAttributesInfoBuilder = ImmutableArrayBuilder<AttributeInfo>.Rent();
213+
214+
static void GatherForwardedAttributes(
215+
AttributeData attributeData,
216+
SemanticModel semanticModel,
217+
ClassDeclarationSyntax classDeclaration,
218+
CancellationToken token,
219+
ImmutableArrayBuilder<AttributeInfo> classAttributesInfo)
220+
{
221+
// Gather explicit forwarded attributes info
222+
foreach (var attributeList in classDeclaration.AttributeLists)
223+
{
224+
foreach (var attribute in attributeList.Attributes)
225+
{
226+
if (!semanticModel.GetSymbolInfo(attribute, token).TryGetAttributeTypeSymbol(out var attributeTypeSymbol))
227+
{
228+
continue;
229+
}
230+
231+
var attributeArguments = attribute.ArgumentList?.Arguments ?? Enumerable.Empty<AttributeArgumentSyntax>();
232+
233+
// Try to extract the forwarded attribute
234+
if (!AttributeInfo.TryCreate(attributeTypeSymbol, semanticModel, attributeArguments, token, out var attributeInfo))
235+
{
236+
continue;
237+
}
238+
239+
var ignoreAttribute = attributeData.AttributeClass?.GetFullyQualifiedMetadataName();
240+
if (attributeInfo.TypeName.Contains(ignoreAttribute))
241+
{
242+
continue;
243+
}
244+
245+
// Add the new attribute info to the right builder
246+
classAttributesInfo.Add(attributeInfo);
247+
}
248+
}
249+
}
250+
251+
// If the method is not a partial definition/implementation, just gather attributes from the method with no modifications
252+
GatherForwardedAttributes(attributeData, semanticModel, classDeclaration, token, classAttributesInfoBuilder);
253+
254+
classAttributesInfo = classAttributesInfoBuilder.ToImmutable();
255+
}
256+
257+
/// <summary>
258+
/// Gets the type of the generic.
259+
/// </summary>
260+
/// <param name="attributeData">The attribute data.</param>
261+
/// <returns>A String.</returns>
262+
public static string? GetGenericType(this AttributeData attributeData)
263+
{
264+
var success = attributeData?.AttributeClass?.ToDisplayString();
265+
var start = success?.IndexOf('<') + 1 ?? 0;
266+
return success?.Substring(start, success.Length - start - 1);
267+
}
196268
}

0 commit comments

Comments
 (0)