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

Method execute

plugins/clang/codegen/adaptsignatureaction.cpp:69–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69void AdaptSignatureAction::execute()
70{
71 ENSURE_CHAIN_NOT_LOCKED
72 DUChainReadLocker lock;
73 IndexedString url = m_otherSideTopContext->url();
74 lock.unlock();
75 m_otherSideTopContext = DUChain::self()->waitForUpdate(url, TopDUContext::AllDeclarationsContextsAndUses);
76 if (!m_otherSideTopContext) {
77 clangDebug() << "failed to update" << url.str();
78 return;
79 }
80
81 lock.lock();
82
83 Declaration* otherSide = m_otherSideId.declaration(m_otherSideTopContext.data());
84 if (!otherSide) {
85 clangDebug() << "could not find definition";
86 return;
87 }
88 DUContext* functionContext = DUChainUtils::functionContext(otherSide);
89 if (!functionContext) {
90 clangDebug() << "no function context";
91 return;
92 }
93 if (!functionContext || functionContext->type() != DUContext::Function) {
94 clangDebug() << "no correct function context";
95 return;
96 }
97
98 DocumentChangeSet changes;
99 KTextEditor::Range parameterRange = ClangIntegration::DUChainUtils::functionSignatureRange(otherSide);
100 QString newText = CodegenHelper::makeSignatureString(otherSide, m_newSignature, !m_editingDefinition);
101 if (!m_editingDefinition) {
102 // append a newline after the method signature in case the method definition follows
103 newText += QLatin1Char('\n');
104 }
105
106 DocumentChange changeParameters(functionContext->url(), parameterRange, QString(), newText);
107 lock.unlock();
108 changeParameters.m_ignoreOldText = true;
109 changes.addChange(changeParameters);
110 changes.setReplacementPolicy(DocumentChangeSet::WarnOnFailedChange);
111 DocumentChangeSet::ChangeResult result = changes.applyAllChanges();
112 if (!result) {
113 const QString messageText = i18n("Failed to apply changes: %1", result.m_failureReason);
114 auto* message = new Sublime::Message(messageText, Sublime::Message::Error);
115 ICore::self()->uiController()->postMessage(message);
116 }
117 emit executed(this);
118
119 for (RenameAction* renAct : m_renameActions) {
120 renAct->execute();
121 }
122}
123
124#include "moc_adaptsignatureaction.cpp"

Callers

nothing calls this directly

Calls 15

makeSignatureStringFunction · 0.85
waitForUpdateMethod · 0.80
strMethod · 0.80
addChangeMethod · 0.80
setReplacementPolicyMethod · 0.80
applyAllChangesMethod · 0.80
uiControllerMethod · 0.80
QStringClass · 0.50
urlMethod · 0.45
unlockMethod · 0.45
lockMethod · 0.45
declarationMethod · 0.45

Tested by

no test coverage detected