1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef CPP_ABCKIT_ARKTS_ANNOTATION_INTERFACE_IMPL_H
17 #define CPP_ABCKIT_ARKTS_ANNOTATION_INTERFACE_IMPL_H
18
19 #include "annotation_interface.h"
20 #include "annotation_interface_field.h"
21 #include "../core/annotation_interface.h"
22 #include "../core/annotation_interface_field.h"
23
24 // NOLINTBEGIN(performance-unnecessary-value-param)
25 namespace abckit::arkts {
26
TargetCast()27 inline AbckitArktsAnnotationInterface *AnnotationInterface::TargetCast() const
28 {
29 auto ret = GetApiConfig()->cArktsIapi_->coreAnnotationInterfaceToArktsAnnotationInterface(GetView());
30 CheckError(GetApiConfig());
31 return ret;
32 }
33
AnnotationInterface(const core::AnnotationInterface & coreOther)34 inline AnnotationInterface::AnnotationInterface(const core::AnnotationInterface &coreOther)
35 : core::AnnotationInterface(coreOther), targetChecker_(this)
36 {
37 }
38
AddField(std::string_view name,Type type,Value value)39 inline arkts::AnnotationInterfaceField AnnotationInterface::AddField(std::string_view name, Type type, Value value)
40 {
41 const struct AbckitArktsAnnotationInterfaceFieldCreateParams params {
42 name.data(), type.GetView(), value.GetView()
43 };
44 auto arktsAif = GetApiConfig()->cArktsMapi_->annotationInterfaceAddField(TargetCast(), ¶ms);
45 CheckError(GetApiConfig());
46 auto coreAif = GetApiConfig()->cArktsIapi_->arktsAnnotationInterfaceFieldToCoreAnnotationInterfaceField(arktsAif);
47 CheckError(GetApiConfig());
48 return AnnotationInterfaceField(core::AnnotationInterfaceField(coreAif, GetApiConfig(), GetResource()));
49 }
50
RemoveField(AnnotationInterfaceField field)51 inline AnnotationInterface AnnotationInterface::RemoveField(AnnotationInterfaceField field) const
52 {
53 GetApiConfig()->cArktsMapi_->annotationInterfaceRemoveField(TargetCast(), field.TargetCast());
54 CheckError(GetApiConfig());
55 return *this;
56 }
57
58 } // namespace abckit::arkts
59 // NOLINTEND(performance-unnecessary-value-param)
60
61 #endif // CPP_ABCKIT_ARKTS_ANNOTATION_INTERFACE_IMPL_H
62