@@ -66,10 +66,10 @@ public override bool VisitClassDecl(Class @class)
66
66
return false ;
67
67
}
68
68
69
- protected virtual HashSet < Property > GenerateProperties ( Class @class )
69
+ protected virtual IEnumerable < Property > GenerateProperties ( Class @class )
70
70
{
71
- var newProperties = new HashSet < Property > ( ) ;
72
- foreach ( var method in @class . Methods . Where (
71
+ var newProperties = new List < Property > ( ) ;
72
+ foreach ( Method method in @class . Methods . Where (
73
73
m => ! m . IsConstructor && ! m . IsDestructor && ! m . IsOperator && m . IsGenerated &&
74
74
m . SynthKind != FunctionSynthKind . DefaultValueOverload &&
75
75
m . SynthKind != FunctionSynthKind . ComplementOperator &&
@@ -80,7 +80,7 @@ protected virtual HashSet<Property> GenerateProperties(Class @class)
80
80
string name = GetPropertyName ( method . Name ) ;
81
81
QualifiedType type = method . OriginalReturnType ;
82
82
Property property = GetProperty ( method , name , type ) ;
83
- if ( property . GetMethod == null )
83
+ if ( ! property . HasGetter )
84
84
{
85
85
property . GetMethod = method ;
86
86
property . QualifiedType = method . OriginalReturnType ;
@@ -100,6 +100,34 @@ protected virtual HashSet<Property> GenerateProperties(Class @class)
100
100
}
101
101
}
102
102
103
+ return CleanUp ( @class , newProperties ) ;
104
+ }
105
+
106
+ private IEnumerable < Property > CleanUp ( Class @class , List < Property > newProperties )
107
+ {
108
+ if ( ! Options . UsePropertyDetectionHeuristics )
109
+ return newProperties ;
110
+
111
+ for ( int i = newProperties . Count - 1 ; i >= 0 ; i -- )
112
+ {
113
+ Property property = newProperties [ i ] ;
114
+ if ( property . HasSetter )
115
+ continue ;
116
+
117
+ string firstWord = GetFirstWord ( property . GetMethod . Name ) ;
118
+ if ( firstWord . Length < property . GetMethod . Name . Length &&
119
+ Match ( firstWord , new [ ] { "get" , "is" , "has" } ) )
120
+ continue ;
121
+
122
+ if ( Match ( firstWord , new [ ] { "to" , "new" } ) ||
123
+ verbs . Contains ( firstWord ) )
124
+ {
125
+ property . GetMethod . GenerationKind = GenerationKind . Generate ;
126
+ @class . Properties . Remove ( property ) ;
127
+ newProperties . RemoveAt ( i ) ;
128
+ }
129
+ }
130
+
103
131
return newProperties ;
104
132
}
105
133
@@ -111,11 +139,11 @@ private static Property GetProperty(Method method, string name,
111
139
Property property = @class . Properties . Find (
112
140
p => p . Field == null &&
113
141
( p . Name == name ||
114
- ( isSetter && p . GetMethod != null &&
142
+ ( isSetter && p . HasGetter &&
115
143
GetReadWritePropertyName ( p . GetMethod , name ) == name ) ) &&
116
- ( ( p . GetMethod != null &&
144
+ ( ( p . HasGetter &&
117
145
GetUnderlyingType ( p . GetMethod . OriginalReturnType ) . Equals ( underlyingType ) ) ||
118
- ( p . SetMethod != null &&
146
+ ( p . HasSetter &&
119
147
GetUnderlyingType ( p . SetMethod . Parameters [ 0 ] . QualifiedType ) . Equals ( underlyingType ) ) ) ) ??
120
148
new Property { Name = name , QualifiedType = type } ;
121
149
@@ -139,20 +167,20 @@ private static Property GetProperty(Method method, string name,
139
167
return property ;
140
168
}
141
169
142
- private static void ProcessProperties ( Class @class , HashSet < Property > newProperties )
170
+ private static void ProcessProperties ( Class @class , IEnumerable < Property > newProperties )
143
171
{
144
- foreach ( var property in newProperties )
172
+ foreach ( Property property in newProperties )
145
173
{
146
174
ProcessOverridden ( @class , property ) ;
147
175
148
- if ( property . GetMethod == null )
176
+ if ( ! property . HasGetter )
149
177
{
150
- if ( property . SetMethod != null )
178
+ if ( property . HasSetter )
151
179
property . SetMethod . GenerationKind = GenerationKind . Generate ;
152
180
@class . Properties . Remove ( property ) ;
153
181
continue ;
154
182
}
155
- if ( property . SetMethod == null &&
183
+ if ( ! property . HasSetter &&
156
184
@class . GetOverloads ( property . GetMethod ) . Any (
157
185
m => m != property . GetMethod && ! m . Ignore ) )
158
186
{
@@ -174,7 +202,7 @@ private static void ProcessOverridden(Class @class, Property property)
174
202
Property baseProperty = GetBaseProperty ( @class , property ) ;
175
203
if ( baseProperty == null )
176
204
{
177
- if ( property . SetMethod != null )
205
+ if ( property . HasSetter )
178
206
{
179
207
property . SetMethod . GenerationKind = GenerationKind . Generate ;
180
208
property . SetMethod = null ;
@@ -185,11 +213,11 @@ private static void ProcessOverridden(Class @class, Property property)
185
213
property . GetMethod = null ;
186
214
}
187
215
}
188
- else if ( property . GetMethod == null && baseProperty . SetMethod != null )
216
+ else if ( ! property . HasGetter && baseProperty . HasSetter )
189
217
property . GetMethod = baseProperty . GetMethod ;
190
- else if ( property . SetMethod == null || baseProperty . SetMethod == null )
218
+ else if ( ! property . HasSetter || ! baseProperty . HasSetter )
191
219
{
192
- if ( property . SetMethod != null )
220
+ if ( property . HasSetter )
193
221
property . SetMethod . GenerationKind = GenerationKind . Generate ;
194
222
property . SetMethod = baseProperty . SetMethod ;
195
223
}
@@ -325,24 +353,10 @@ private static string GetPropertyNameFromSetter(string name)
325
353
return nameBuilder . ToString ( ) ;
326
354
}
327
355
328
- private bool IsGetter ( Method method )
329
- {
330
- if ( method . IsDestructor ||
331
- method . OriginalReturnType . Type . IsPrimitiveType ( PrimitiveType . Void ) ||
332
- method . Parameters . Any ( p => p . Kind != ParameterKind . IndirectReturnType ) )
333
- return false ;
334
- var firstWord = GetFirstWord ( method . Name ) ;
335
-
336
- if ( firstWord . Length < method . Name . Length &&
337
- Match ( firstWord , new [ ] { "get" , "is" , "has" } ) )
338
- return true ;
339
-
340
- if ( Options . UsePropertyDetectionHeuristics &&
341
- ! Match ( firstWord , new [ ] { "to" , "new" } ) && ! verbs . Contains ( firstWord ) )
342
- return true ;
343
-
344
- return false ;
345
- }
356
+ private bool IsGetter ( Method method ) =>
357
+ ! method . IsDestructor &&
358
+ ! method . OriginalReturnType . Type . IsPrimitiveType ( PrimitiveType . Void ) &&
359
+ ! method . Parameters . Any ( p => p . Kind != ParameterKind . IndirectReturnType ) ;
346
360
347
361
private static bool IsSetter ( Method method )
348
362
{
0 commit comments