@@ -6,11 +6,15 @@ namespace Semmle.Extraction.CSharp.Entities
6
6
{
7
7
internal class Accessor : Method
8
8
{
9
- protected Accessor ( Context cx , IMethodSymbol init )
10
- : base ( cx , init ) { }
9
+ private readonly IPropertySymbol property ;
10
+ protected Accessor ( Context cx , IMethodSymbol init , IPropertySymbol property )
11
+ : base ( cx , init )
12
+ {
13
+ this . property = property ;
14
+ }
11
15
12
16
/// <summary>
13
- /// Gets the property symbol associated accessor `symbol`, or `null`
17
+ /// Gets the property symbol associated with accessor `symbol`, or `null`
14
18
/// if there is no associated symbol.
15
19
/// </summary>
16
20
public static IPropertySymbol ? GetPropertySymbol ( IMethodSymbol symbol )
@@ -26,39 +30,26 @@ protected Accessor(Context cx, IMethodSymbol init)
26
30
return props . SingleOrDefault ( ) ;
27
31
}
28
32
29
- /// <summary>
30
- /// Gets the property symbol associated with this accessor.
31
- /// </summary>
32
- private IPropertySymbol ? PropertySymbol => GetPropertySymbol ( Symbol ) ;
33
-
34
- public new Accessor OriginalDefinition => Create ( Context , Symbol . OriginalDefinition ) ;
35
-
36
33
public override void Populate ( TextWriter trapFile )
37
34
{
38
35
PopulateMethod ( trapFile ) ;
39
36
PopulateModifiers ( trapFile ) ;
40
37
ContainingType ! . PopulateGenerics ( ) ;
41
38
42
- var prop = PropertySymbol ;
43
- if ( prop is null )
44
- {
45
- var type = Symbol . AssociatedSymbol ? . GetType ( ) . ToString ( ) ?? "null" ;
46
- Context . ModelError ( Symbol , $ "Unhandled accessor associated symbol of type { type } ") ;
47
- return ;
48
- }
49
-
50
- var parent = Property . Create ( Context , prop ) ;
39
+ var parent = Property . Create ( Context , property ) ;
51
40
int kind ;
52
41
Accessor unboundAccessor ;
53
- if ( SymbolEqualityComparer . Default . Equals ( Symbol , prop . GetMethod ) )
42
+ if ( SymbolEqualityComparer . Default . Equals ( Symbol , property . GetMethod ) )
54
43
{
55
44
kind = 1 ;
56
- unboundAccessor = Create ( Context , prop . OriginalDefinition . GetMethod ! ) ;
45
+ var orig = property . OriginalDefinition ;
46
+ unboundAccessor = Create ( Context , orig . GetMethod ! , orig ) ;
57
47
}
58
- else if ( SymbolEqualityComparer . Default . Equals ( Symbol , prop . SetMethod ) )
48
+ else if ( SymbolEqualityComparer . Default . Equals ( Symbol , property . SetMethod ) )
59
49
{
60
50
kind = 2 ;
61
- unboundAccessor = Create ( Context , prop . OriginalDefinition . SetMethod ! ) ;
51
+ var orig = property . OriginalDefinition ;
52
+ unboundAccessor = Create ( Context , orig . SetMethod ! , orig ) ;
62
53
}
63
54
else
64
55
{
@@ -84,14 +75,14 @@ public override void Populate(TextWriter trapFile)
84
75
}
85
76
}
86
77
87
- public static new Accessor Create ( Context cx , IMethodSymbol symbol ) =>
88
- AccessorFactory . Instance . CreateEntityFromSymbol ( cx , symbol ) ;
78
+ public static Accessor Create ( Context cx , IMethodSymbol symbol , IPropertySymbol prop ) =>
79
+ AccessorFactory . Instance . CreateEntity ( cx , symbol , ( symbol , prop ) ) ;
89
80
90
- private class AccessorFactory : CachedEntityFactory < IMethodSymbol , Accessor >
81
+ private class AccessorFactory : CachedEntityFactory < ( IMethodSymbol , IPropertySymbol ) , Accessor >
91
82
{
92
83
public static AccessorFactory Instance { get ; } = new AccessorFactory ( ) ;
93
84
94
- public override Accessor Create ( Context cx , IMethodSymbol init ) => new Accessor ( cx , init ) ;
85
+ public override Accessor Create ( Context cx , ( IMethodSymbol , IPropertySymbol ) init ) => new ( cx , init . Item1 , init . Item2 ) ;
95
86
}
96
87
}
97
88
}
0 commit comments