MCPcopy Create free account
hub / github.com/KDE/kdevelop / MemberAccessReplacer

Class MemberAccessReplacer

plugins/clang/codecompletion/context.cpp:879–927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

877};
878
879struct MemberAccessReplacer : public QObject
880{
881 Q_OBJECT
882
883public:
884 enum Type {
885 None,
886 DotToArrow,
887 ArrowToDot
888 };
889 Q_ENUM(Type)
890
891public 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};
928static MemberAccessReplacer s_memberAccessReplacer;
929
930bool areAllResultsOverloadCandidates(const CXCodeCompleteResults& results)

Callers

nothing calls this directly

Calls 13

activeDocumentMethod · 0.80
documentControllerMethod · 0.80
CursorClass · 0.70
RangeClass · 0.50
textDocumentMethod · 0.45
activeTextViewMethod · 0.45
cursorPositionMethod · 0.45
lengthMethod · 0.45
textMethod · 0.45
columnMethod · 0.45
startMethod · 0.45
lineMethod · 0.45

Tested by

no test coverage detected