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

Function parseProperty

plugins/qmljs/kdevqmljsplugin.cpp:130–166  ·  view source on GitHub ↗

Take the given QML line and check if it's a line of the form foo.bar: value. Return ranges for the key and the value.

Source from the content-addressed store, hash-verified

128// Take the given QML line and check if it's a line of the form foo.bar: value.
129// Return ranges for the key and the value.
130const QPair<KTextEditor::Range, KTextEditor::Range> parseProperty(const QString& line, const KTextEditor::Cursor& position) {
131 const QStringList items = line.split(QLatin1Char(';'));
132 QString matchingItem;
133 int col_offset = -1;
134 // This is to also support FooAnimation { foo: bar; baz: bang; duration: 200 }
135 // or similar
136 for (const QString& item : items) {
137 col_offset += item.size() + 1;
138 if ( position.column() < col_offset ) {
139 matchingItem = item;
140 break;
141 }
142 }
143 QStringList split = matchingItem.split(QLatin1Char(':'));
144 if ( split.size() != 2 ) {
145 // The expression is not of the form foo:bar, thus invalid.
146 return qMakePair(KTextEditor::Range::invalid(), KTextEditor::Range::invalid());
147 }
148 QString key = split.at(0);
149 QString value = split.at(1);
150
151 // For animations or similar, remove the trailing '}' if there's no semicolon after the last entry
152 if (value.trimmed().endsWith(QLatin1Char('}'))) {
153 col_offset -= value.size() - value.lastIndexOf(QLatin1Char('}')) + 1;
154 value = value.left(value.lastIndexOf(QLatin1Char('}'))-1);
155 }
156
157 return qMakePair(
158 KTextEditor::Range(
159 KTextEditor::Cursor(position.line(), col_offset - value.size() - key.size() + spacesAtCorner(key, +1) - 1),
160 KTextEditor::Cursor(position.line(), col_offset - value.size() - 1 + spacesAtCorner(key, -1))
161 ),
162 KTextEditor::Range(
163 KTextEditor::Cursor(position.line(), col_offset - value.size() + spacesAtCorner(value, +1)),
164 KTextEditor::Cursor(position.line(), col_offset + spacesAtCorner(value, -1))
165 ));
166}
167
168QPair<QWidget*, KTextEditor::Range> KDevQmlJsPlugin::specialLanguageObjectNavigationWidget(const QUrl& url, const KTextEditor::Cursor& position)
169{

Calls 10

spacesAtCornerFunction · 0.85
endsWithMethod · 0.80
invalidFunction · 0.50
RangeFunction · 0.50
CursorClass · 0.50
splitMethod · 0.45
sizeMethod · 0.45
columnMethod · 0.45
atMethod · 0.45
lineMethod · 0.45

Tested by

no test coverage detected