• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 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 ES2PANDA_LSP_CLASS_HIERARCHY_ITEM_H
17 #define ES2PANDA_LSP_CLASS_HIERARCHY_ITEM_H
18 
19 #include <string>
20 
21 namespace ark::es2panda::lsp {
22 enum class SetterStyle { NONE = 0, SETTER, GETTER };
23 
24 enum class AccessModifierStyle { PUBLIC = 0, PROTECTED, PRIVATE };
25 
26 enum class ClassDefinitionStyle { FIELD = 0, METHOD };
27 
28 class ClassHierarchyItem {
29 public:
ClassHierarchyItem(AccessModifierStyle access,std::string detail)30     ClassHierarchyItem(AccessModifierStyle access, std::string detail)
31         : accessModifier_(access), detail_(std::move(detail))
32     {
33     }
34 
35     virtual ~ClassHierarchyItem() = default;
36 
37     ClassHierarchyItem(const ClassHierarchyItem &other) = default;
38     ClassHierarchyItem(ClassHierarchyItem &&other) = default;
39     ClassHierarchyItem &operator=(const ClassHierarchyItem &other) = default;
40     ClassHierarchyItem &operator=(ClassHierarchyItem &&other) = default;
41 
42     virtual ClassDefinitionStyle GetClassDefinitionStyle() const = 0;
43 
GetAccessModifierStyle()44     AccessModifierStyle GetAccessModifierStyle() const
45     {
46         return accessModifier_;
47     }
48 
GetDetail()49     const std::string &GetDetail() const
50     {
51         return detail_;
52     }
53 
54 private:
55     AccessModifierStyle accessModifier_;
56     std::string detail_;
57 };
58 
59 class ClassPropertyItem : public ClassHierarchyItem {
60 public:
ClassPropertyItem(AccessModifierStyle access,std::string detail)61     ClassPropertyItem(AccessModifierStyle access, std::string detail) : ClassHierarchyItem(access, std::move(detail)) {}
62 
63     ~ClassPropertyItem() override = default;
64 
65     ClassPropertyItem(const ClassPropertyItem &other) = default;
66     ClassPropertyItem(ClassPropertyItem &&other) = default;
67     ClassPropertyItem &operator=(const ClassPropertyItem &other) = default;
68     ClassPropertyItem &operator=(ClassPropertyItem &&other) = default;
69 
GetClassDefinitionStyle()70     ClassDefinitionStyle GetClassDefinitionStyle() const override
71     {
72         return ClassDefinitionStyle::FIELD;
73     }
74 
SetVariableName(const std::string & variableName)75     void SetVariableName(const std::string &variableName)
76     {
77         if (variableName.empty()) {
78             return;
79         }
80         variableName_ = variableName;
81     }
82 
GetVariableName()83     const std::string &GetVariableName() const
84     {
85         return variableName_;
86     }
87 
88 private:
89     std::string variableName_;
90 };
91 
92 class ClassMethodItem : public ClassHierarchyItem {
93 public:
ClassMethodItem(AccessModifierStyle access,std::string detail,SetterStyle setter)94     ClassMethodItem(AccessModifierStyle access, std::string detail, SetterStyle setter)
95         : ClassHierarchyItem(access, std::move(detail)), setter_(setter)
96     {
97     }
98 
99     ~ClassMethodItem() override = default;
100 
101     ClassMethodItem(const ClassMethodItem &other) = default;
102     ClassMethodItem(ClassMethodItem &&other) = default;
103     ClassMethodItem &operator=(const ClassMethodItem &other) = default;
104     ClassMethodItem &operator=(ClassMethodItem &&other) = default;
105 
GetClassDefinitionStyle()106     ClassDefinitionStyle GetClassDefinitionStyle() const override
107     {
108         return ClassDefinitionStyle::METHOD;
109     }
110 
SetFunctionName(const std::string & functionName)111     void SetFunctionName(const std::string &functionName)
112     {
113         if (functionName.empty()) {
114             return;
115         }
116         funcName_ = functionName;
117     }
118 
GetFunctionName()119     const std::string &GetFunctionName() const
120     {
121         return funcName_;
122     }
123 
GetSetterStyle()124     SetterStyle GetSetterStyle() const
125     {
126         return setter_;
127     }
128 
129 private:
130     std::string funcName_;
131     SetterStyle setter_;
132 };
133 }  // namespace ark::es2panda::lsp
134 
135 #endif
136