1 /* 2 * Copyright (c) 2022 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 OHOS_IDL_ASTMETHOD_H 17 #define OHOS_IDL_ASTMETHOD_H 18 19 #include <cstddef> 20 #include <vector> 21 22 #include "ast/ast_node.h" 23 #include "ast/ast_parameter.h" 24 #include "ast/ast_type.h" 25 #include "util/autoptr.h" 26 #include "util/string.h" 27 28 namespace OHOS { 29 namespace Idl { 30 class ASTMethod : public ASTNode { 31 public: SetName(const String & name)32 void SetName(const String& name) 33 { 34 name_ = name; 35 } 36 GetName()37 String GetName() 38 { 39 return name_; 40 } 41 42 String GetSignature(); 43 SetOneway(bool oneway)44 void SetOneway(bool oneway) 45 { 46 oneway_ = oneway; 47 } 48 IsOneway()49 bool IsOneway() 50 { 51 return oneway_; 52 } 53 SetReturnType(ASTType * type)54 void SetReturnType(ASTType* type) 55 { 56 returnType_ = type; 57 } 58 GetReturnType()59 AutoPtr<ASTType> GetReturnType() 60 { 61 return returnType_; 62 } 63 64 void AddParameter(ASTParameter* parameter); 65 66 AutoPtr<ASTParameter> GetParameter(size_t index); 67 GetParameterNumber()68 size_t GetParameterNumber() 69 { 70 return parameters_.size(); 71 } 72 73 String Dump(const String& prefix) override; 74 SetCacheable(int cacheTime)75 void SetCacheable(int cacheTime) 76 { 77 cacheable_ = true; 78 cacheTime_ = cacheTime; 79 } 80 GetCacheableTime()81 int GetCacheableTime() const 82 { 83 return cacheTime_; 84 } 85 GetCacheable()86 bool GetCacheable() const 87 { 88 return cacheable_; 89 } 90 private: 91 void BuildSignature(); 92 93 String name_; 94 String signature_; 95 bool oneway_ = false; 96 AutoPtr<ASTType> returnType_; 97 std::vector<AutoPtr<ASTParameter>> parameters_; 98 int cacheTime_ = 0; 99 bool cacheable_ = false; 100 }; 101 } // namespace Idl 102 } // namespace OHOS 103 #endif // OHOS_IDL_ASTMETHOD_H 104