| 3731 | } |
| 3732 | |
| 3733 | void BfAutoComplete::FixitAddCase(BfTypeInstance* typeInst, const StringImpl& caseName, const BfTypeVector& fieldTypes) |
| 3734 | { |
| 3735 | if (typeInst == mModule->mContext->mBfObjectType) |
| 3736 | return; |
| 3737 | |
| 3738 | auto parser = typeInst->mTypeDef->GetDefinition()->mSource->ToParser(); |
| 3739 | if (parser == NULL) |
| 3740 | return; |
| 3741 | |
| 3742 | String fullName = typeInst->mTypeDef->mFullName.ToString(); |
| 3743 | String fieldStr; |
| 3744 | |
| 3745 | int fileLoc = typeInst->mTypeDef->mTypeDeclaration->GetSrcEnd(); |
| 3746 | |
| 3747 | if (auto defineBlock = BfNodeDynCast<BfBlock>(typeInst->mTypeDef->mTypeDeclaration->mDefineNode)) |
| 3748 | fileLoc = BfFixitFinder::FindLineStartAfter(defineBlock->mOpenBrace); |
| 3749 | if (!typeInst->mTypeDef->mFields.empty()) |
| 3750 | { |
| 3751 | auto fieldDecl = typeInst->mTypeDef->mFields.back()->mFieldDeclaration; |
| 3752 | if (fieldDecl != NULL) |
| 3753 | { |
| 3754 | fileLoc = BfFixitFinder::FindLineStartAfter(fieldDecl); |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | bool isSimpleCase = false; |
| 3759 | if (!typeInst->mTypeDef->mFields.IsEmpty()) |
| 3760 | { |
| 3761 | if (auto block = BfNodeDynCast<BfBlock>(typeInst->mTypeDef->mTypeDeclaration->mDefineNode)) |
| 3762 | { |
| 3763 | bool endsInComma = false; |
| 3764 | |
| 3765 | if (!block->mChildArr.IsEmpty()) |
| 3766 | { |
| 3767 | auto lastNode = block->mChildArr.back(); |
| 3768 | if (auto tokenNode = BfNodeDynCast<BfTokenNode>(lastNode)) |
| 3769 | { |
| 3770 | if (tokenNode->mToken == BfToken_Comma) |
| 3771 | { |
| 3772 | isSimpleCase = true; |
| 3773 | endsInComma = true; |
| 3774 | } |
| 3775 | } |
| 3776 | else if (auto enumEntryDecl = BfNodeDynCast<BfEnumEntryDeclaration>(lastNode)) |
| 3777 | { |
| 3778 | isSimpleCase = true; |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | if (isSimpleCase) |
| 3783 | { |
| 3784 | if (endsInComma) |
| 3785 | { |
| 3786 | fieldStr += "|"; |
| 3787 | fieldStr += caseName; |
| 3788 | } |
| 3789 | else |
| 3790 | { |
no test coverage detected