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 #include "codegen/code_emitter.h"
17 
18 namespace OHOS {
19 namespace Idl {
20 const char* CodeEmitter::TAB = "    ";
CodeEmitter(MetaComponent * mc)21 CodeEmitter::CodeEmitter(MetaComponent* mc)
22     : metaComponent_(mc)
23 {
24     metaInterface_ = nullptr;
25     for (int i = 0; i < metaComponent_->interfaceNumber_; i++) {
26         metaInterface_ = metaComponent_->interfaces_[i];
27         if (metaInterface_ == nullptr) {
28             continue;
29         }
30         if (!metaInterface_->external_) {
31             break;
32         }
33     }
34 
35     if (metaInterface_ != nullptr) {
36         interfaceName_ = metaInterface_->name_;
37         interfaceFullName_ = metaInterface_->namespace_ + interfaceName_;
38         proxyName_ = interfaceName_.StartsWith("I") ?
39                 interfaceName_.Substring(1) + "Proxy" : interfaceName_ + "Proxy";
40         proxyFullName_ = metaInterface_->namespace_ + proxyName_;
41         stubName_ = interfaceName_.StartsWith("I") ?
42                 interfaceName_.Substring(1) + "Stub" : interfaceName_ + "Stub";
43         stubFullName_ = metaInterface_->namespace_ + stubName_;
44         deathRecipientName_ = interfaceName_.StartsWith("I") ?
45                 interfaceName_.Substring(1) + "Recipient" : interfaceName_ + "Recipient";
46     }
47 }
48 } // namespace Idl
49 } // namespace OHOS