1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #include "parser/file_detail.h" 10 #include "util/file.h" 11 #include "util/string_builder.h" 12 13 namespace OHOS { 14 namespace HDI { SetFilePath(const String & filePath)15void FileDetail::SetFilePath(const String& filePath) 16 { 17 idlFilePath_ = filePath; 18 #ifdef __MINGW32__ 19 int index = idlFilePath_.LastIndexOf('\\'); 20 #else 21 int index = idlFilePath_.LastIndexOf('/'); 22 #endif 23 int end = idlFilePath_.LastIndexOf(".idl"); 24 idlName_ = idlFilePath_.Substring((index == -1) ? 0 : (index + 1), end); 25 } 26 AddImport(const String & packageName)27bool FileDetail::AddImport(const String& packageName) 28 { 29 if (imports_.find(packageName) != imports_.end()) { 30 return false; 31 } 32 33 imports_.emplace(packageName); 34 return true; 35 } 36 Dump()37String FileDetail::Dump() 38 { 39 StringBuilder sb; 40 sb.AppendFormat("filePath:%s\n", idlFilePath_.string()); 41 sb.AppendFormat("package:%s\n", packageName_.string()); 42 sb.AppendFormat("import number:%d\n", imports_.size()); 43 for (const auto& importName : imports_) { 44 sb.AppendFormat("import %s\n", importName.string()); 45 } 46 return sb.ToString(); 47 } 48 } // namespace HDI 49 } // namespace OHOS