mirror of
https://github.com/openharmony/ark_runtime_core.git
synced 2026-07-01 13:17:23 -04:00
Add interface to modify annotation elements by index
For the adaption of type system in ts2abc, we need provide interface to modify annotation elements by index Issue: #I5E22F Signed-off-by: qiuyu <qiuyu22@huawei.com> Change-Id: I86487106e5f71e0bf7f93588ec02838989cfb86e
This commit is contained in:
@@ -60,6 +60,26 @@ public:
|
||||
elements_.push_back(std::forward<AnnotationElement>(element));
|
||||
}
|
||||
|
||||
void SetOrAddElementByIndex(size_t ele_idx, AnnotationElement &&element)
|
||||
{
|
||||
// did not find a simple way to replace element directly because of circular dependency of class definition
|
||||
auto len = elements_.size();
|
||||
ASSERT(ele_idx <= len);
|
||||
if (ele_idx == len) {
|
||||
AddElement(std::move(element));
|
||||
return;
|
||||
}
|
||||
std::vector<AnnotationElement> eles;
|
||||
for (size_t i = 0; i < ele_idx; i++) {
|
||||
eles.push_back(std::forward<AnnotationElement>(elements_[i]));
|
||||
}
|
||||
eles.push_back(std::forward<AnnotationElement>(element));
|
||||
for (size_t i = ele_idx + 1; i < len; i++) {
|
||||
eles.push_back(std::forward<AnnotationElement>(elements_[i]));
|
||||
}
|
||||
elements_ = std::forward<std::vector<AnnotationElement>>(eles);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string record_name_;
|
||||
std::vector<AnnotationElement> elements_;
|
||||
|
||||
@@ -207,6 +207,12 @@ public:
|
||||
annotations_.insert(annotations_.end(), annotations.begin(), annotations.end());
|
||||
}
|
||||
|
||||
void SetOrAddAnnotationElementByIndex(size_t anno_idx, size_t ele_idx, AnnotationElement &&element)
|
||||
{
|
||||
ASSERT(anno_idx < annotations_.size());
|
||||
annotations_[anno_idx].SetOrAddElementByIndex(ele_idx, std::forward<AnnotationElement>(element));
|
||||
}
|
||||
|
||||
std::optional<Error> ValidateData() override;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user