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 16import { 17 global, 18 passNode, 19 passNodeArray, 20 unpackNonNullableNode, 21 unpackNode, 22 unpackNodeArray, 23 assertValidPeer, 24 AstNode, 25 Es2pandaAstNodeType, 26 KNativePointer, 27 nodeByType, 28 ArktsObject, 29 unpackString 30} from "../../reexport-for-generated" 31 32import { AnnotatedExpression } from "./AnnotatedExpression" 33import { TypeNode } from "./TypeNode" 34import { Decorator } from "./Decorator" 35import { ValidationInfo } from "./ValidationInfo" 36export class Identifier extends AnnotatedExpression { 37 constructor(pointer: KNativePointer) { 38 assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_IDENTIFIER) 39 super(pointer) 40 41 } 42 static createIdentifier(): Identifier { 43 return new Identifier(global.generatedEs2panda._CreateIdentifier(global.context)) 44 } 45 static updateIdentifier(original?: Identifier): Identifier { 46 return new Identifier(global.generatedEs2panda._UpdateIdentifier(global.context, passNode(original))) 47 } 48 static create1Identifier(name: string): Identifier { 49 return new Identifier(global.generatedEs2panda._CreateIdentifier1(global.context, name)) 50 } 51 static update1Identifier(original: Identifier | undefined, name: string): Identifier { 52 return new Identifier(global.generatedEs2panda._UpdateIdentifier1(global.context, passNode(original), name)) 53 } 54 static create2Identifier(name: string, typeAnnotation?: TypeNode): Identifier { 55 return new Identifier(global.generatedEs2panda._CreateIdentifier2(global.context, name, passNode(typeAnnotation))) 56 } 57 static update2Identifier(original: Identifier | undefined, name: string, typeAnnotation?: TypeNode): Identifier { 58 return new Identifier(global.generatedEs2panda._UpdateIdentifier2(global.context, passNode(original), name, passNode(typeAnnotation))) 59 } 60 get name(): string { 61 return unpackString(global.generatedEs2panda._IdentifierNameConst(global.context, this.peer)) 62 } 63 /** @deprecated */ 64 setName(newName: string): this { 65 global.generatedEs2panda._IdentifierSetName(global.context, this.peer, newName) 66 return this 67 } 68 get decorators(): readonly Decorator[] { 69 return unpackNodeArray(global.generatedEs2panda._IdentifierDecoratorsConst(global.context, this.peer)) 70 } 71 get isErrorPlaceHolder(): boolean { 72 return global.generatedEs2panda._IdentifierIsErrorPlaceHolderConst(global.context, this.peer) 73 } 74 get isOptional(): boolean { 75 return global.generatedEs2panda._IdentifierIsOptionalConst(global.context, this.peer) 76 } 77 /** @deprecated */ 78 setOptional(optional_arg: boolean): this { 79 global.generatedEs2panda._IdentifierSetOptional(global.context, this.peer, optional_arg) 80 return this 81 } 82 get isReference(): boolean { 83 return global.generatedEs2panda._IdentifierIsReferenceConst(global.context, this.peer) 84 } 85 get isTdz(): boolean { 86 return global.generatedEs2panda._IdentifierIsTdzConst(global.context, this.peer) 87 } 88 /** @deprecated */ 89 setTdz(): this { 90 global.generatedEs2panda._IdentifierSetTdz(global.context, this.peer) 91 return this 92 } 93 /** @deprecated */ 94 setAccessor(): this { 95 global.generatedEs2panda._IdentifierSetAccessor(global.context, this.peer) 96 return this 97 } 98 get isAccessor(): boolean { 99 return global.generatedEs2panda._IdentifierIsAccessorConst(global.context, this.peer) 100 } 101 /** @deprecated */ 102 setMutator(): this { 103 global.generatedEs2panda._IdentifierSetMutator(global.context, this.peer) 104 return this 105 } 106 get isMutator(): boolean { 107 return global.generatedEs2panda._IdentifierIsMutatorConst(global.context, this.peer) 108 } 109 get isReceiver(): boolean { 110 return global.generatedEs2panda._IdentifierIsReceiverConst(global.context, this.peer) 111 } 112 get isPrivateIdent(): boolean { 113 return global.generatedEs2panda._IdentifierIsPrivateIdentConst(global.context, this.peer) 114 } 115 /** @deprecated */ 116 setPrivate(isPrivate: boolean): this { 117 global.generatedEs2panda._IdentifierSetPrivate(global.context, this.peer, isPrivate) 118 return this 119 } 120 get isIgnoreBox(): boolean { 121 return global.generatedEs2panda._IdentifierIsIgnoreBoxConst(global.context, this.peer) 122 } 123 /** @deprecated */ 124 setIgnoreBox(): this { 125 global.generatedEs2panda._IdentifierSetIgnoreBox(global.context, this.peer) 126 return this 127 } 128 get isAnnotationDecl(): boolean { 129 return global.generatedEs2panda._IdentifierIsAnnotationDeclConst(global.context, this.peer) 130 } 131 /** @deprecated */ 132 setAnnotationDecl(): this { 133 global.generatedEs2panda._IdentifierSetAnnotationDecl(global.context, this.peer) 134 return this 135 } 136 get isAnnotationUsage(): boolean { 137 return global.generatedEs2panda._IdentifierIsAnnotationUsageConst(global.context, this.peer) 138 } 139 /** @deprecated */ 140 setAnnotationUsage(): this { 141 global.generatedEs2panda._IdentifierSetAnnotationUsage(global.context, this.peer) 142 return this 143 } 144 get typeAnnotation(): TypeNode | undefined { 145 return unpackNode(global.generatedEs2panda._IdentifierTypeAnnotationConst(global.context, this.peer)) 146 } 147 /** @deprecated */ 148 setTsTypeAnnotation(typeAnnotation: TypeNode): this { 149 global.generatedEs2panda._IdentifierSetTsTypeAnnotation(global.context, this.peer, passNode(typeAnnotation)) 150 return this 151 } 152} 153export function isIdentifier(node: AstNode): node is Identifier { 154 return node instanceof Identifier 155} 156if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_IDENTIFIER)) { 157 nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_IDENTIFIER, Identifier) 158} 159