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

Method execute

plugins/clang/duchain/headerguardassistant.cpp:51–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 }
50
51 void execute() override
52 {
53 KDevelop::DocumentChangeSet changes;
54 switch (m_type) {
55 case GuardType::Pragma:
56 {
57 KDevelop::DocumentChange change(m_path, KTextEditor::Range(m_startLine, 0, m_startLine, 0), QString(),
58 QStringLiteral("#pragma once\n\n"));
59 changes.addChange(change);
60 break;
61 }
62 case GuardType::Macro:
63 {
64 const QString macro = m_path.toUrl()
65 .fileName(QUrl::PrettyDecoded)
66 .replace(QRegularExpression(QStringLiteral("[^a-zA-Z0-9]")), QStringLiteral(" "))
67 .simplified()
68 .toUpper()
69 .replace(QLatin1Char(' '), QLatin1Char('_'))
70 .append(QLatin1String("_INCLUDED"));
71
72 const auto representation = KDevelop::createCodeRepresentation(m_path);
73 const auto lastLine = representation->lines() - 1;
74 const auto lastColumn = representation->line(lastLine).length();
75
76 // Add the #endif change before so that it applies correctly in case lastLine == m_startline
77 changes.addChange(KDevelop::DocumentChange(m_path,
78 KTextEditor::Range(lastLine, lastColumn, lastLine, lastColumn),
79 QString(),
80 QStringLiteral("\n#endif // %1").arg(macro)));
81 changes.addChange(KDevelop::DocumentChange(m_path,
82 KTextEditor::Range(m_startLine, 0, m_startLine, 0),
83 QString(),
84 QStringLiteral("#ifndef %1\n#define %1\n\n").arg(macro)));
85 break;
86 }
87 }
88
89 KDevelop::DUChainReadLocker lock;
90 changes.setReplacementPolicy(KDevelop::DocumentChangeSet::WarnOnFailedChange);
91 changes.applyAllChanges();
92 emit executed(this);
93 }
94
95private:
96 const GuardType m_type;

Callers

nothing calls this directly

Calls 13

createCodeRepresentationFunction · 0.85
addChangeMethod · 0.80
setReplacementPolicyMethod · 0.80
applyAllChangesMethod · 0.80
RangeClass · 0.70
QStringClass · 0.50
appendMethod · 0.45
replaceMethod · 0.45
fileNameMethod · 0.45
toUrlMethod · 0.45
linesMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected