| 1318 | } |
| 1319 | |
| 1320 | void BfAutoComplete::AddExtensionMethods(BfTypeInstance* targetType, BfTypeInstance* extensionContainer, const StringImpl & filter, bool allowProtected, bool allowPrivate) |
| 1321 | { |
| 1322 | if (!extensionContainer->mTypeDef->mHasExtensionMethods) |
| 1323 | return; |
| 1324 | |
| 1325 | mModule->PopulateType(extensionContainer, BfPopulateType_Data); |
| 1326 | |
| 1327 | BfShow checkShow = allowPrivate ? BfShow_Hide : BfShow_HideIndirect; |
| 1328 | |
| 1329 | for (auto methodDef : extensionContainer->mTypeDef->mMethods) |
| 1330 | { |
| 1331 | if (methodDef->mMethodType != BfMethodType_Extension) |
| 1332 | continue; |
| 1333 | if (methodDef->mShow >= checkShow) |
| 1334 | continue; |
| 1335 | if (methodDef->mName.IsEmpty()) |
| 1336 | continue; |
| 1337 | |
| 1338 | bool canUseMethod = true; |
| 1339 | canUseMethod &= CheckProtection(methodDef->mProtection, methodDef->mDeclaringType, allowProtected, allowPrivate); |
| 1340 | |
| 1341 | auto methodInstance = mModule->GetRawMethodInstanceAtIdx(extensionContainer, methodDef->mIdx); |
| 1342 | if (methodInstance == NULL) |
| 1343 | continue; |
| 1344 | |
| 1345 | int score; |
| 1346 | uint8 matches[256]; |
| 1347 | // Do filter match first- may be cheaper than generic validation |
| 1348 | if (!DoesFilterMatch(methodDef->mName.c_str(), filter.c_str(), score, matches, sizeof(matches))) |
| 1349 | continue; |
| 1350 | |
| 1351 | auto thisType = methodInstance->GetParamType(0); |
| 1352 | if (thisType->IsRef()) |
| 1353 | thisType = thisType->GetUnderlyingType(); |
| 1354 | |
| 1355 | bool paramValidated = false; |
| 1356 | if (methodInstance->GetNumGenericParams() > 0) |
| 1357 | { |
| 1358 | if ((thisType->IsGenericParam()) && (methodInstance->GetNumGenericParams() == 1)) |
| 1359 | { |
| 1360 | auto genericParamType = (BfGenericParamType*)thisType; |
| 1361 | if (genericParamType->mGenericParamKind == BfGenericParamKind_Method) |
| 1362 | { |
| 1363 | auto& genericParams = methodInstance->mMethodInfoEx->mGenericParams; |
| 1364 | if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance), targetType, NULL, genericParams[genericParamType->mGenericParamIdx], NULL, NULL)) |
| 1365 | continue; |
| 1366 | paramValidated = true; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | if (((thisType->IsUnspecializedTypeVariation()) || (thisType->IsGenericParam())) && |
| 1371 | (!paramValidated)) |
| 1372 | { |
| 1373 | BfTypeVector genericTypeVector; |
| 1374 | genericTypeVector.resize(methodInstance->GetNumGenericParams()); |
| 1375 | BfGenericInferContext genericInferContext; |
| 1376 | genericInferContext.mCheckMethodGenericArguments = &genericTypeVector; |
| 1377 | genericInferContext.mModule = mModule; |
nothing calls this directly
no test coverage detected