1 /** 2 * Copyright (c) 2022-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 PANDA_TOOLING_INSPECTOR_TYPES_LOCATION_H 17 #define PANDA_TOOLING_INSPECTOR_TYPES_LOCATION_H 18 19 #include "json_serialization/serializable.h" 20 21 #include <cstddef> 22 #include <optional> 23 #include <string> 24 25 #include "utils/expected.h" 26 27 #include "types/numeric_id.h" 28 29 namespace ark { 30 class JsonObject; 31 class JsonObjectBuilder; 32 } // namespace ark 33 34 namespace ark::tooling::inspector { 35 class Location final : public JsonSerializable { 36 public: 37 Location(ScriptId scriptId, size_t lineNumber, std::optional<size_t> columnNumber = {}) scriptId_(scriptId)38 : scriptId_(scriptId), lineNumber_(lineNumber), columnNumber_(columnNumber) 39 { 40 } 41 42 static Expected<Location, std::string> FromJsonProperty(const JsonObject &object, const char *propertyName); 43 GetScriptId()44 ScriptId GetScriptId() const 45 { 46 return scriptId_; 47 } 48 GetLineNumber()49 size_t GetLineNumber() const 50 { 51 return lineNumber_; 52 } 53 SetLineNumber(size_t lineNumber)54 void SetLineNumber(size_t lineNumber) 55 { 56 lineNumber_ = lineNumber; 57 } 58 GetColumnNumber()59 std::optional<size_t> GetColumnNumber() const 60 { 61 return columnNumber_; 62 } 63 SetColumnNumber(size_t columnNumber)64 void SetColumnNumber(size_t columnNumber) 65 { 66 columnNumber_ = columnNumber; 67 } 68 69 void Serialize(JsonObjectBuilder &builder) const override; 70 71 private: 72 ScriptId scriptId_; 73 size_t lineNumber_; 74 std::optional<size_t> columnNumber_; 75 }; 76 } // namespace ark::tooling::inspector 77 78 #endif // PANDA_TOOLING_INSPECTOR_TYPES_LOCATION_H 79