| 877 | }; |
| 878 | |
| 879 | struct MemberAccessReplacer : public QObject |
| 880 | { |
| 881 | Q_OBJECT |
| 882 | |
| 883 | public: |
| 884 | enum Type { |
| 885 | None, |
| 886 | DotToArrow, |
| 887 | ArrowToDot |
| 888 | }; |
| 889 | Q_ENUM(Type) |
| 890 | |
| 891 | public Q_SLOTS: |
| 892 | void replaceCurrentAccess(MemberAccessReplacer::Type type) |
| 893 | { |
| 894 | if (auto document = ICore::self()->documentController()->activeDocument()) { |
| 895 | if (auto textDocument = document->textDocument()) { |
| 896 | auto activeView = document->activeTextView(); |
| 897 | if (!activeView) { |
| 898 | return; |
| 899 | } |
| 900 | |
| 901 | auto cursor = activeView->cursorPosition(); |
| 902 | |
| 903 | QString oldAccess, newAccess; |
| 904 | if (type == ArrowToDot) { |
| 905 | oldAccess = QStringLiteral("->"); |
| 906 | newAccess = QStringLiteral("."); |
| 907 | } else { |
| 908 | oldAccess = QStringLiteral("."); |
| 909 | newAccess = QStringLiteral("->"); |
| 910 | } |
| 911 | |
| 912 | auto oldRange = KTextEditor::Range(cursor - KTextEditor::Cursor(0, oldAccess.length()), cursor); |
| 913 | |
| 914 | // This code needed for testReplaceMemberAccess test |
| 915 | // Maybe we should do a similar thing for '->' to '.' direction, but this is not so important |
| 916 | while (textDocument->text(oldRange) == QLatin1String(" ") && oldRange.start().column() >= 0) { |
| 917 | oldRange = KTextEditor::Range({oldRange.start().line(), oldRange.start().column() - 1}, |
| 918 | {oldRange.end().line(), oldRange.end().column() - 1}); |
| 919 | } |
| 920 | |
| 921 | if (oldRange.start().column() >= 0 && textDocument->text(oldRange) == oldAccess) { |
| 922 | textDocument->replaceText(oldRange, newAccess); |
| 923 | } |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | }; |
| 928 | static MemberAccessReplacer s_memberAccessReplacer; |
| 929 | |
| 930 | bool areAllResultsOverloadCandidates(const CXCodeCompleteResults& results) |
nothing calls this directly
no test coverage detected