77
88namespace Semmle . Extraction . CSharp . Entities
99{
10- internal class Parameter : CachedSymbol < IParameterSymbol > , IExpressionParentEntity
10+ internal class Parameter : CachedSymbol < IParameterSymbol > , IExpressionParentEntity , IParameter
1111 {
1212 protected IEntity ? Parent { get ; set ; }
1313 protected Parameter Original { get ; }
14+ private int PositionOffset { get ; set ; }
1415
15- protected Parameter ( Context cx , IParameterSymbol init , IEntity ? parent , Parameter ? original )
16+ private Parameter ( Context cx , IParameterSymbol init , IEntity ? parent , Parameter ? original , int positionOffset )
1617 : base ( cx , init )
1718 {
1819 Parent = parent ;
1920 Original = original ?? this ;
21+ PositionOffset = positionOffset ;
22+ }
23+
24+ protected Parameter ( Context cx , IParameterSymbol init , IEntity ? parent , Parameter ? original )
25+ : this ( cx , init , parent , original , 0 )
26+ {
2027 }
2128
2229 public override Microsoft . CodeAnalysis . Location ReportingLocation => Symbol . GetSymbolLocation ( ) ;
@@ -32,7 +39,7 @@ public enum Kind
3239 RefReadOnly = 6
3340 }
3441
35- protected virtual int Ordinal => Symbol . Ordinal ;
42+ protected virtual int Ordinal => Symbol . Ordinal + PositionOffset ;
3643
3744 private Kind ParamKind
3845 {
@@ -55,30 +62,35 @@ private Kind ParamKind
5562 if ( Ordinal == 0 )
5663 {
5764 if ( Symbol . ContainingSymbol is IMethodSymbol method && method . IsExtensionMethod )
65+ {
5866 return Kind . This ;
67+ }
5968 }
6069 return Kind . None ;
6170 }
6271 }
6372 }
6473
65- public static Parameter Create ( Context cx , IParameterSymbol param , IEntity parent , Parameter ? original = null )
74+ public static Parameter Create ( Context cx , IParameterSymbol param , IEntity parent , Parameter ? original = null , int positionOffset = 0 )
6675 {
6776 var cachedSymbol = cx . GetPossiblyCachedParameterSymbol ( param ) ;
68- return ParameterFactory . Instance . CreateEntity ( cx , cachedSymbol , ( cachedSymbol , parent , original ) ) ;
77+ return ParameterFactory . Instance . CreateEntity ( cx , cachedSymbol , ( cachedSymbol , parent , original , positionOffset ) ) ;
6978 }
7079
7180 public static Parameter Create ( Context cx , IParameterSymbol param )
7281 {
7382 var cachedSymbol = cx . GetPossiblyCachedParameterSymbol ( param ) ;
74- return ParameterFactory . Instance . CreateEntity ( cx , cachedSymbol , ( cachedSymbol , null , null ) ) ;
83+ return ParameterFactory . Instance . CreateEntity ( cx , cachedSymbol , ( cachedSymbol , null , null , 0 ) ) ;
7584 }
7685
7786 public override void WriteId ( EscapingTextWriter trapFile )
7887 {
7988 if ( Parent is null )
8089 Parent = Method . Create ( Context , Symbol . ContainingSymbol as IMethodSymbol ) ;
8190
91+ if ( Parent is null && Symbol . ContainingSymbol is INamedTypeSymbol type && type . IsExtension )
92+ Parent = Type . Create ( Context , type ) ;
93+
8294 if ( Parent is null )
8395 throw new InternalError ( Symbol , "Couldn't get parent of symbol." ) ;
8496
@@ -194,11 +206,11 @@ Symbol.ContainingSymbol is IMethodSymbol ms &&
194206 return syntax ? . Default ;
195207 }
196208
197- private class ParameterFactory : CachedEntityFactory < ( IParameterSymbol , IEntity ? , Parameter ? ) , Parameter >
209+ private class ParameterFactory : CachedEntityFactory < ( IParameterSymbol , IEntity ? , Parameter ? , int ) , Parameter >
198210 {
199211 public static ParameterFactory Instance { get ; } = new ParameterFactory ( ) ;
200212
201- public override Parameter Create ( Context cx , ( IParameterSymbol , IEntity ? , Parameter ? ) init ) => new Parameter ( cx , init . Item1 , init . Item2 , init . Item3 ) ;
213+ public override Parameter Create ( Context cx , ( IParameterSymbol , IEntity ? , Parameter ? , int ) init ) => new Parameter ( cx , init . Item1 , init . Item2 , init . Item3 , init . Item4 ) ;
202214 }
203215
204216 public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour . OptionalLabel ;
0 commit comments