Skip to content

Commit 513b6cd

Browse files
weepingyndu13
authored andcommitted
Feat: fix empty()
1 parent 1c9b989 commit 513b6cd

File tree

102 files changed

+5514
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+5514
-36
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
with:
2626
node-version: ${{ matrix.node-version }}
2727
- run: npm install
28-
- run: npm run ci
28+
- run: npm run test

lib/generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ class Visitor {
18121812

18131813
visitIncludeModelFunc(ast, modelName, level) {
18141814
// empty method
1815-
this.emit(`virtual bool empty() const override { ${ast.nodes.map((node, index) => { return 'return this->' + _name(node.fieldName) + '_ == nullptr' + (index % 5 === 0 && index !== ast.nodes.length - 1 ? '\n ' : ''); }).join(' && ')}; };\n`, level);
1815+
this.emit(`virtual bool empty() const override { return ${ast.nodes.map((node, index) => { return 'this->' + _name(node.fieldName) + '_ == nullptr' + (index % 5 === 0 && index !== ast.nodes.length - 1 ? '\n ' : ''); }).join(' && ')}; };\n`, level);
18161816

18171817
for (let i = 0; i < ast.nodes.length; i++) {
18181818
const node = ast.nodes[i];

tests/fixtures/alias/Darafile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@
2020
"author": "Alibaba",
2121
"email": "[email protected]"
2222
}
23+
},
24+
"cpp": {
25+
"namespace": "Darabonba",
26+
"header": "darabonba/test.hpp"
27+
},
28+
"releases": {
29+
"cpp": "darabonba/test:1.0.0"
2330
}
2431
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is auto-generated, don't edit it. Thanks.
2+
#ifndef DARABONBA_TEST_HPP_
3+
#define DARABONBA_TEST_HPP_
4+
#include <darabonba/Core.hpp>
5+
using namespace std;
6+
using json = nlohmann::json;
7+
namespace Darabonba
8+
{
9+
class Client {
10+
public:
11+
Client() {}
12+
static void emptyModel();
13+
};
14+
} // namespace Darabonba
15+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <darabonba/Core.hpp>
2+
#include <darabonba/test.hpp>
3+
#include <darabonba/import.hpp>
4+
#include <darabonba/srouce.hpp>
5+
#include <darabonba/alias.hpp>
6+
#include <darabonba/alias/source.hpp>
7+
#include <darabonba/alias/symbol.hpp>
8+
using namespace std;
9+
using namespace Alias;
10+
using json = nlohmann::json;
11+
using ImportClient = Import::Client;
12+
using SourceClient = Source::Client;
13+
using namespace AliasSymbol::Models;
14+
using AliasSymbolClient = AliasSymbol::Client;
15+
using AliasSourceSourceClient = AliasSource::SourceClient;
16+
namespace Darabonba
17+
{
18+
19+
void Client::emptyModel() {
20+
ImportClient::test();
21+
SourceClient::test();
22+
AliasClient::test();
23+
AliasSourceSourceClient::test();
24+
AliasSymbolClient::test();
25+
TestModel model = TestModel();
26+
}
27+
} // namespace Darabonba

tests/fixtures/annotation/Darafile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@
22
"scope": "darabonba",
33
"name": "main",
44
"version": "0.0.1",
5-
"main": "./main.dara"
5+
"main": "./main.dara",
6+
"libraries": {},
7+
"cpp": {
8+
"namespace": "Darabonba",
9+
"header": "darabonba/test.hpp"
10+
},
11+
"releases": {
12+
"cpp": "darabonba/test:1.0.0"
13+
}
614
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file is auto-generated, don't edit it. Thanks.
2+
#ifndef DARABONBA_MODELS_TEST_HPP_
3+
#define DARABONBA_MODELS_TEST_HPP_
4+
#include <darabonba/Core.hpp>
5+
using namespace std;
6+
using json = nlohmann::json;
7+
namespace Darabonba
8+
{
9+
namespace Models
10+
{
11+
/**
12+
TestModel
13+
*/
14+
class Test : public Darabonba::Model {
15+
public:
16+
friend void to_json(Darabonba::Json& j, const Test& obj) {
17+
DARABONBA_PTR_TO_JSON(test, test_);
18+
};
19+
friend void from_json(const Darabonba::Json& j, Test& obj) {
20+
DARABONBA_PTR_FROM_JSON(test, test_);
21+
};
22+
Test() = default ;
23+
Test(const Test &) = default ;
24+
Test(Test &&) = default ;
25+
Test(const Darabonba::Json & obj) { from_json(obj, *this); };
26+
virtual ~Test() = default ;
27+
Test& operator=(const Test &) = default ;
28+
Test& operator=(Test &&) = default ;
29+
virtual void validate() const override {
30+
DARABONBA_VALIDATE_REQUIRED(test_);
31+
};
32+
virtual void fromMap(const Darabonba::Json &obj) override { from_json(obj, *this); validate(); };
33+
virtual Darabonba::Json toMap() const override { Darabonba::Json obj; to_json(obj, *this); return obj; };
34+
virtual bool empty() const override { return this->test_ == nullptr; };
35+
// test Field Functions
36+
bool hasTest() const { return this->test_ != nullptr;};
37+
void deleteTest() { this->test_ = nullptr;};
38+
inline string test() const { DARABONBA_PTR_GET_DEFAULT(test_, "") };
39+
inline Test& setTest(string test) { DARABONBA_PTR_SET_VALUE(test_, test) };
40+
41+
42+
protected:
43+
// Alichange app id
44+
std::shared_ptr<string> test_ = nullptr;
45+
};
46+
47+
} // namespace Models
48+
} // namespace Darabonba
49+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file is auto-generated, don't edit it. Thanks.
2+
#ifndef DARABONBA_TEST_HPP_
3+
#define DARABONBA_TEST_HPP_
4+
#include <darabonba/Core.hpp>
5+
#include <darabonba/testModel.hpp>
6+
using namespace std;
7+
using json = nlohmann::json;
8+
namespace Darabonba
9+
{
10+
class Client {
11+
public:
12+
13+
/**
14+
Init Func
15+
*/
16+
Client();
17+
18+
void testAPI();
19+
/**
20+
testFunc
21+
*/
22+
static void testFunc();
23+
protected:
24+
string _a;
25+
};
26+
} // namespace Darabonba
27+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This file is auto-generated, don't edit it. Thanks.
2+
#ifndef DARABONBA_TESTMODEL_HPP_
3+
#define DARABONBA_TESTMODEL_HPP_
4+
#include <darabonba/Core.hpp>
5+
#include <darabonba/models/Test.hpp>
6+
7+
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <darabonba/Core.hpp>
2+
#include <darabonba/test.hpp>
3+
#include <darabonba/policy/Retry.hpp>
4+
#include <darabonba/Runtime.hpp>
5+
#include <darabonba/Exception.hpp>
6+
using namespace std;
7+
using json = nlohmann::json;
8+
namespace Darabonba
9+
{
10+
11+
/**
12+
Init Func
13+
*/
14+
Darabonba::Client::Client(){
15+
}
16+
17+
18+
void Client::testAPI() {
19+
Darabonba::RuntimeOptions runtime_(json({
20+
}));
21+
22+
shared_ptr<Darabonba::Http::Request> _lastRequest = nullptr;
23+
shared_ptr<Darabonba::Http::MCurlResponse> _lastResponse = nullptr;
24+
Darabonba::Exception _lastException;
25+
int _retriesAttempted = 0;
26+
Darabonba::Policy::RetryPolicyContext _context = json({
27+
{"retriesAttempted" , _retriesAttempted}
28+
});
29+
while (Darabonba::allowRetry(runtime_.retryOptions(), _context)) {
30+
if (_retriesAttempted > 0) {
31+
int _backoffTime = Darabonba::getBackoffTime(runtime_.retryOptions(), _context);
32+
if (_backoffTime > 0) {
33+
Darabonba::sleep(_backoffTime);
34+
}
35+
}
36+
_retriesAttempted++;
37+
try {
38+
Darabonba::Http::Request request_ = Darabonba::Http::Request();
39+
_lastRequest = make_shared<Darabonba::Http::Request>(request_);
40+
auto futureResp_ = Darabonba::Core::doAction(request_, runtime_);
41+
shared_ptr<Darabonba::Http::MCurlResponse> response_ = futureResp_.get();
42+
_lastResponse = response_;
43+
44+
return ;
45+
} catch (const Darabonba::Exception& ex) {
46+
_context = Darabonba::Policy::RetryPolicyContext(json({
47+
{"retriesAttempted" , _retriesAttempted},
48+
{"lastRequest" , _lastRequest},
49+
{"lastResponse" , _lastResponse},
50+
{"exception" , ex},
51+
}));
52+
continue;
53+
}
54+
}
55+
56+
throw *_context.exception();
57+
}
58+
59+
/**
60+
testFunc
61+
*/
62+
void Client::testFunc() {
63+
}
64+
} // namespace Darabonba

0 commit comments

Comments
 (0)