Skip to content

Commit 82ef04d

Browse files
committed
[cleanup] Use addProperty instead of append (for most json object).
1 parent ef5f509 commit 82ef04d

File tree

14 files changed

+60
-67
lines changed

14 files changed

+60
-67
lines changed

CodeLite/LSP/InitializeRequest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ JSONItem LSP::InitializeRequest::ToJSON(const wxString& name) const
1313
JSONItem json = Request::ToJSON(name);
1414

1515
// add the 'params'
16-
JSONItem params = JSONItem::createObject("params");
17-
json.append(params);
16+
JSONItem params = JSONItem::createObject();
1817
params.addProperty("processId", GetProcessId());
1918
if (GetRootUri().IsEmpty()) {
2019
JSON nullItem(JsonType::Null);
@@ -79,6 +78,8 @@ JSONItem LSP::InitializeRequest::ToJSON(const wxString& name) const
7978
tokenModifiers.arrayAppend("documentation");
8079
tokenModifiers.arrayAppend("defaultLibrary");
8180
}
81+
82+
json.addProperty("params", params);
8283
return json;
8384
}
8485

CodeLite/LSP/MessageWithParams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ JSONItem LSP::MessageWithParams::ToJSON(const wxString& name) const
1010
JSONItem json = Message::ToJSON(name);
1111
json.addProperty("method", GetMethod());
1212
if (m_params) {
13-
json.append(m_params->ToJSON("params"));
13+
json.addProperty("params", m_params->ToJSON("params"));
1414
}
1515
return json;
1616
}

CodeLite/LSP/basic_types.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ JSONItem TextDocumentContentChangeEvent::ToJSON(const wxString& name) const
118118
{
119119
JSONItem json = JSONItem::createObject(name);
120120
if(m_range.IsOk()) {
121-
json.append(m_range.ToJSON("range"));
121+
json.addProperty("range", m_range.ToJSON("range"));
122122
}
123123
json.addProperty("text", m_text);
124124
return json;
@@ -133,8 +133,8 @@ void Range::FromJSON(const JSONItem& json)
133133
JSONItem Range::ToJSON(const wxString& name) const
134134
{
135135
JSONItem json = JSONItem::createObject(name);
136-
json.append(m_start.ToJSON("start"));
137-
json.append(m_end.ToJSON("end"));
136+
json.addProperty("start", m_start.ToJSON("start"));
137+
json.addProperty("end", m_end.ToJSON("end"));
138138
return json;
139139
}
140140

@@ -150,7 +150,7 @@ JSONItem Location::ToJSON(const wxString& name) const
150150
{
151151
JSONItem json = JSONItem::createObject(name);
152152
json.addProperty("uri", GetPathAsURI());
153-
json.append(m_range.ToJSON("range"));
153+
json.addProperty("range", m_range.ToJSON("range"));
154154
json.addProperty("pattern", m_pattern);
155155
json.addProperty("name", m_name);
156156
return json;
@@ -166,7 +166,7 @@ JSONItem TextEdit::ToJSON(const wxString& name) const
166166
{
167167
JSONItem json = JSONItem::createObject(name);
168168
json.addProperty("newText", m_newText);
169-
json.append(m_range.ToJSON("range"));
169+
json.addProperty("range", m_range.ToJSON("range"));
170170
return json;
171171
}
172172

@@ -270,8 +270,8 @@ void Hover::FromJSON(const JSONItem& json)
270270
JSONItem Hover::ToJSON(const wxString& name) const
271271
{
272272
JSONItem json = JSONItem::createObject(name);
273-
json.append(m_contents.ToJSON("contents"));
274-
json.append(m_range.ToJSON("range"));
273+
json.addProperty("contents", m_contents.ToJSON("contents"));
274+
json.addProperty("range", m_range.ToJSON("range"));
275275
return json;
276276
}
277277

@@ -288,7 +288,7 @@ void Diagnostic::FromJSON(const JSONItem& json)
288288
JSONItem Diagnostic::ToJSON(const wxString& name) const
289289
{
290290
JSONItem json = JSONItem::createObject(name);
291-
json.append(m_range.ToJSON("range"));
291+
json.addProperty("range", m_range.ToJSON("range"));
292292
json.addProperty("message", GetMessage());
293293
json.addProperty("severity", (int)m_severity);
294294
return json;
@@ -361,7 +361,7 @@ JSONItem SymbolInformation::ToJSON(const wxString& name) const
361361
JSONItem json = JSONItem::createObject(name);
362362
json.addProperty("kind", (int)kind);
363363
json.addProperty("containerName", containerName);
364-
json.append(location.ToJSON("location"));
364+
json.addProperty("location", location.ToJSON("location"));
365365
json.addProperty("name", this->name);
366366
return json;
367367
}

CodeLite/LSP/json_rpc_params.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ void TextDocumentPositionParams::FromJSON(const JSONItem& json)
1515
JSONItem TextDocumentPositionParams::ToJSON(const wxString& name) const
1616
{
1717
JSONItem json = JSONItem::createObject(name);
18-
json.append(m_textDocument.ToJSON("textDocument"));
19-
json.append(m_position.ToJSON("position"));
18+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
19+
json.addProperty("position", m_position.ToJSON("position"));
2020
return json;
2121
}
2222

@@ -29,7 +29,7 @@ void SemanticTokensParams::FromJSON(const JSONItem& json) { m_textDocument.FromJ
2929
JSONItem SemanticTokensParams::ToJSON(const wxString& name) const
3030
{
3131
JSONItem json = JSONItem::createObject(name);
32-
json.append(m_textDocument.ToJSON("textDocument"));
32+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
3333
return json;
3434
}
3535

@@ -42,7 +42,7 @@ void DidOpenTextDocumentParams::FromJSON(const JSONItem& json) { m_textDocument.
4242
JSONItem DidOpenTextDocumentParams::ToJSON(const wxString& name) const
4343
{
4444
JSONItem json = JSONItem::createObject(name);
45-
json.append(m_textDocument.ToJSON("textDocument"));
45+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
4646
return json;
4747
}
4848

@@ -55,7 +55,7 @@ void DidCloseTextDocumentParams::FromJSON(const JSONItem& json) { m_textDocument
5555
JSONItem DidCloseTextDocumentParams::ToJSON(const wxString& name) const
5656
{
5757
JSONItem json = JSONItem::createObject(name);
58-
json.append(m_textDocument.ToJSON("textDocument"));
58+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
5959
return json;
6060
}
6161

@@ -81,7 +81,7 @@ void DidChangeTextDocumentParams::FromJSON(const JSONItem& json)
8181
JSONItem DidChangeTextDocumentParams::ToJSON(const wxString& name) const
8282
{
8383
JSONItem json = JSONItem::createObject(name);
84-
json.append(m_textDocument.ToJSON("textDocument"));
84+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
8585
JSONItem arr = JSONItem::createArray();
8686
for (const auto& contentChange : m_contentChanges) {
8787
arr.arrayAppend(contentChange.ToJSON(""));
@@ -103,7 +103,7 @@ void DidSaveTextDocumentParams::FromJSON(const JSONItem& json)
103103
JSONItem DidSaveTextDocumentParams::ToJSON(const wxString& name) const
104104
{
105105
JSONItem json = JSONItem::createObject(name);
106-
json.append(m_textDocument.ToJSON("textDocument"));
106+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
107107
json.addProperty("text", m_text);
108108
return json;
109109
}
@@ -153,8 +153,8 @@ void CodeActionParams::FromJSON(const JSONItem& json) { wxUnusedVar(json); }
153153
JSONItem CodeActionParams::ToJSON(const wxString& name) const
154154
{
155155
JSONItem json = JSONItem::createObject(name);
156-
json.append(m_textDocument.ToJSON("textDocument"));
157-
json.append(m_range.ToJSON("range"));
156+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
157+
json.addProperty("range", m_range.ToJSON("range"));
158158

159159
// add empty context
160160
auto context = json.AddObject("context");
@@ -174,7 +174,7 @@ void DocumentSymbolParams::FromJSON(const JSONItem& json) { m_textDocument.FromJ
174174
JSONItem DocumentSymbolParams::ToJSON(const wxString& name) const
175175
{
176176
JSONItem json = JSONItem::createObject(name);
177-
json.append(m_textDocument.ToJSON("textDocument"));
177+
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
178178
return json;
179179
}
180180

CodeLite/cl_config.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232
#include <wx/filefn.h>
3333
#include <wx/filename.h>
3434

35-
#define ADD_OBJ_IF_NOT_EXISTS(parent, objName) \
36-
if (!parent.hasNamedObject(objName)) { \
37-
JSONItem obj = JSONItem::createObject(objName); \
38-
parent.append(obj); \
35+
#define ADD_OBJ_IF_NOT_EXISTS(parent, objName) \
36+
if (!(parent).hasNamedObject((objName))) { \
37+
JSONItem obj = JSONItem::createObject(); \
38+
(parent).addProperty((objName), obj); \
3939
}
4040

41-
#define ADD_ARR_IF_NOT_EXISTS(parent, arrName) \
42-
if (!parent.hasNamedObject(arrName)) { \
43-
JSONItem arr = JSONItem::createArray(arrName); \
44-
parent.append(arr); \
41+
#define ADD_ARR_IF_NOT_EXISTS(parent, arrName) \
42+
if (!(parent).hasNamedObject((arrName))) { \
43+
JSONItem arr = JSONItem::createArray(); \
44+
(parent).addProperty((arrName), arr); \
4545
}
4646

4747
namespace
@@ -115,10 +115,10 @@ void clConfig::SetOutputTabOrder(const wxArrayString& tabs, int selected)
115115
DoDeleteProperty("outputTabOrder");
116116

117117
// first time
118-
JSONItem e = JSONItem::createObject("outputTabOrder");
118+
JSONItem e = JSONItem::createObject();
119119
e.addProperty("tabs", tabs);
120120
e.addProperty("selected", selected);
121-
m_root->toElement().append(e);
121+
m_root->toElement().addProperty("outputTabOrder", e);
122122
m_root->save(m_filename);
123123
}
124124

@@ -138,10 +138,10 @@ void clConfig::SetWorkspaceTabOrder(const wxArrayString& tabs, int selected)
138138
DoDeleteProperty("workspaceTabOrder");
139139

140140
// first time
141-
JSONItem e = JSONItem::createObject("workspaceTabOrder");
141+
JSONItem e = JSONItem::createObject();
142142
e.addProperty("tabs", tabs);
143143
e.addProperty("selected", selected);
144-
m_root->toElement().append(e);
144+
m_root->toElement().addProperty("workspaceTabOrder", e);
145145

146146
m_root->save(m_filename);
147147
}
@@ -173,8 +173,7 @@ bool clConfig::Write(const wxString& name, std::function<JSONItem()> serialiser_
173173
} else {
174174
// add it to the global configuration file
175175
DoDeleteProperty(name);
176-
item.SetPropertyName(name);
177-
m_root->toElement().append(item);
176+
m_root->toElement().addProperty(name, item);
178177
return true;
179178
}
180179
}
@@ -263,10 +262,7 @@ void clConfig::Save(const wxFileName& fn)
263262

264263
JSONItem clConfig::GetGeneralSetting()
265264
{
266-
if (!m_root->toElement().hasNamedObject("General")) {
267-
JSONItem general = JSONItem::createObject("General");
268-
m_root->toElement().append(general);
269-
}
265+
ADD_OBJ_IF_NOT_EXISTS(m_root->toElement(), "General")
270266
return m_root->toElement().namedObject("General");
271267
}
272268

@@ -342,10 +338,7 @@ int clConfig::GetAnnoyingDlgAnswer(const wxString& name, int defaultValue)
342338

343339
void clConfig::SetAnnoyingDlgAnswer(const wxString& name, int value)
344340
{
345-
if (!m_root->toElement().hasNamedObject("AnnoyingDialogsAnswers")) {
346-
JSONItem element = JSONItem::createObject("AnnoyingDialogsAnswers");
347-
m_root->toElement().append(element);
348-
}
341+
ADD_OBJ_IF_NOT_EXISTS(m_root->toElement(), "AnnoyingDialogsAnswers")
349342

350343
JSONItem element = m_root->toElement().namedObject("AnnoyingDialogsAnswers");
351344
if (element.hasNamedObject(name)) {
@@ -524,14 +517,13 @@ wxFont clConfig::Read(const wxString& name, const wxFont& defaultValue)
524517

525518
void clConfig::Write(const wxString& name, const wxFont& value)
526519
{
527-
JSONItem font = JSONItem::createObject(name);
528-
font.addProperty("fontDesc", FontUtils::GetFontInfo(value));
529-
530520
JSONItem general = GetGeneralSetting();
531521
if (general.hasNamedObject(name)) {
532522
general.removeProperty(name);
533523
}
534-
general.append(font);
524+
JSONItem font = JSONItem::createObject();
525+
font.addProperty("fontDesc", FontUtils::GetFontInfo(value));
526+
general.addProperty(name, font);
535527
Save();
536528
}
537529

MemCheck/memchecksettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ JSONItem MemCheckSettings::ToJSON() const
9999
element.addProperty("m_omitDuplications", m_omitDuplications);
100100
element.addProperty("m_omitSuppressed", m_omitSuppressed);
101101

102-
element.append(m_valgrindSettings.ToJSON());
102+
element.addProperty(CONFIG_ITEM_NAME_VALGRIND, m_valgrindSettings.ToJSON());
103103
return element;
104104
}

PHPLint/lintoptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ LintOptions::LintOptions()
3333

3434
// Save it
3535
JSON newRoot(newConfigFile);
36-
JSONItem e = JSONItem::createObject(GetName());
36+
JSONItem e = JSONItem::createObject();
3737
e.addProperty("lintOnFileSave", m_lintOnFileSave);
3838
e.addProperty("lintOnFileLoad", m_lintOnFileLoad);
39-
newRoot.toElement().append(e);
39+
newRoot.toElement().addProperty(GetName(), e);
4040
newRoot.save(newConfigFile);
4141
}
4242
}

Plugin/phpoptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ PhpOptions::PhpOptions()
4444
}
4545

4646
JSON newRoot(newConfigFile);
47-
JSONItem e = JSONItem::createObject(GetName());
47+
JSONItem e = JSONItem::createObject();
4848
e.addProperty("m_phpExe", m_phpExe);
4949
e.addProperty("m_includePaths", m_includePaths);
5050
e.addProperty("m_errorReporting", m_errorReporting);
51-
newRoot.toElement().append(e);
51+
newRoot.toElement().addProperty(GetName(), e);
5252
newRoot.save(newConfigFile);
5353
}
5454
}

codelitephp/PHPParser/php_workspace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ void PHPWorkspace::FromJSON(const JSONItem& e)
342342

343343
JSONItem PHPWorkspace::ToJSON(JSONItem& e) const
344344
{
345-
JSONItem metadata = JSONItem::createObject("metadata");
346-
e.append(metadata);
345+
JSONItem metadata = JSONItem::createObject();
347346

348347
metadata.addProperty("version", PHP_WORKSPACE_VERSION);
349348
metadata.addProperty("ide", PHP_WORKSPACE_IDE);
350349
metadata.addProperty("type", wxString("php"));
350+
e.addProperty("metadata", metadata);
351351

352352
// Store the list of files
353353
JSONItem projectsArr = JSONItem::createArray();

wxcrafter/aui/aui_pane_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void AuiPaneInfo::FromJSON(const JSONItem& json)
139139

140140
JSONItem AuiPaneInfo::ToJSON() const
141141
{
142-
JSONItem element = JSONItem::createObject("wxAuiPaneInfo");
142+
JSONItem element = JSONItem::createObject();
143143
element.addProperty(wxT("m_name"), m_name);
144144
element.addProperty(wxT("m_caption"), m_caption);
145145
element.addProperty(wxT("m_dockDirection"), m_dockDirection);

0 commit comments

Comments
 (0)