From 96d2db6363fb189659265ba87f71e39e26fe3c5a Mon Sep 17 00:00:00 2001 From: Sam Cao Date: Tue, 4 Jun 2024 07:38:39 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Add=20create()=20v12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swc4j/ast/ts/Swc4jAstTsArrayType.java | 4 +++ .../ast/ts/Swc4jAstTsCallSignatureDecl.java | 23 +++++++++++++++ .../ast/ts/Swc4jAstTsConditionalType.java | 8 +++++ .../ts/Swc4jAstTsConstructSignatureDecl.java | 23 +++++++++++++++ .../ast/ts/Swc4jAstTsConstructorType.java | 23 +++++++++++++++ .../swc4j/ast/ts/Swc4jAstTsEnumMember.java | 8 +++++ .../ast/ts/Swc4jAstTsExprWithTypeArgs.java | 8 +++++ .../javet/swc4j/ast/ts/Swc4jAstTsFnType.java | 15 ++++++++++ .../ast/ts/Swc4jAstTsGetterSignature.java | 29 +++++++++++++++++++ .../swc4j/ast/ts/Swc4jAstTsImportType.java | 19 ++++++++++++ .../ast/ts/Swc4jAstTsIndexSignature.java | 27 +++++++++++++++++ .../ast/ts/Swc4jAstTsIndexedAccessType.java | 11 +++++++ .../swc4j/ast/ts/Swc4jAstTsInferType.java | 4 +++ .../swc4j/ast/ts/Swc4jAstTsInterfaceBody.java | 8 +++++ .../ast/ts/Swc4jAstTsIntersectionType.java | 8 +++++ .../swc4j/ast/ts/Swc4jAstTsKeywordType.java | 4 +++ .../javet/swc4j/ast/ts/Swc4jAstTsLitType.java | 4 +++ 17 files changed, 226 insertions(+) diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsArrayType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsArrayType.java index f4271b91..c4fd64ba 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsArrayType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsArrayType.java @@ -47,6 +47,10 @@ public Swc4jAstTsArrayType( setElemType(elemType); } + public static Swc4jAstTsArrayType create(ISwc4jAstTsType elemType) { + return new Swc4jAstTsArrayType(elemType, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { return SimpleList.of(elemType); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsCallSignatureDecl.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsCallSignatureDecl.java index d2d06566..6947f49e 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsCallSignatureDecl.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsCallSignatureDecl.java @@ -54,6 +54,29 @@ public Swc4jAstTsCallSignatureDecl( this.params.forEach(node -> node.setParent(this)); } + public static Swc4jAstTsCallSignatureDecl create() { + return create(SimpleList.of()); + } + + public static Swc4jAstTsCallSignatureDecl create(List params) { + return create(params, null, null); + } + + public static Swc4jAstTsCallSignatureDecl create(List params, Swc4jAstTsTypeAnn typeAnn) { + return create(params, typeAnn, null); + } + + public static Swc4jAstTsCallSignatureDecl create(List params, Swc4jAstTsTypeParamDecl typeParams) { + return create(params, null, typeParams); + } + + public static Swc4jAstTsCallSignatureDecl create( + List params, + Swc4jAstTsTypeAnn typeAnn, + Swc4jAstTsTypeParamDecl typeParams) { + return new Swc4jAstTsCallSignatureDecl(params, typeAnn, typeParams, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.copyOf(params); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConditionalType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConditionalType.java index 4685c6bf..e2cc6a9d 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConditionalType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConditionalType.java @@ -59,6 +59,14 @@ public Swc4jAstTsConditionalType( setTrueType(trueType); } + public static Swc4jAstTsConditionalType create( + ISwc4jAstTsType checkType, + ISwc4jAstTsType extendsType, + ISwc4jAstTsType trueType, + ISwc4jAstTsType falseType) { + return new Swc4jAstTsConditionalType(checkType, extendsType, trueType, falseType, Swc4jSpan.DUMMY); + } + @Jni2RustMethod public ISwc4jAstTsType getCheckType() { return checkType; diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructSignatureDecl.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructSignatureDecl.java index fd80e851..602cfdd9 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructSignatureDecl.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructSignatureDecl.java @@ -54,6 +54,29 @@ public Swc4jAstTsConstructSignatureDecl( this.params.forEach(node -> node.setParent(this)); } + public static Swc4jAstTsConstructSignatureDecl create() { + return create(SimpleList.of()); + } + + public static Swc4jAstTsConstructSignatureDecl create(List params) { + return create(params, null, null); + } + + public static Swc4jAstTsConstructSignatureDecl create(List params, Swc4jAstTsTypeAnn typeAnn) { + return create(params, typeAnn, null); + } + + public static Swc4jAstTsConstructSignatureDecl create(List params, Swc4jAstTsTypeParamDecl typeParams) { + return create(params, null, typeParams); + } + + public static Swc4jAstTsConstructSignatureDecl create( + List params, + Swc4jAstTsTypeAnn typeAnn, + Swc4jAstTsTypeParamDecl typeParams) { + return new Swc4jAstTsConstructSignatureDecl(params, typeAnn, typeParams, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.copyOf(params); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructorType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructorType.java index 74fab423..203fbe94 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructorType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsConstructorType.java @@ -58,6 +58,29 @@ public Swc4jAstTsConstructorType( this.params.forEach(node -> node.setParent(this)); } + public static Swc4jAstTsConstructorType create(Swc4jAstTsTypeAnn typeAnn) { + return create(SimpleList.of(), typeAnn); + } + + public static Swc4jAstTsConstructorType create(List params, Swc4jAstTsTypeAnn typeAnn) { + return create(params, null, typeAnn); + } + + public static Swc4jAstTsConstructorType create( + List params, + Swc4jAstTsTypeParamDecl typeParams, + Swc4jAstTsTypeAnn typeAnn) { + return create(params, typeParams, typeAnn, false); + } + + public static Swc4jAstTsConstructorType create( + List params, + Swc4jAstTsTypeParamDecl typeParams, + Swc4jAstTsTypeAnn typeAnn, + boolean _abstract) { + return new Swc4jAstTsConstructorType(params, typeParams, typeAnn, _abstract, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.copyOf(params); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsEnumMember.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsEnumMember.java index faa9c6b1..01898ca9 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsEnumMember.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsEnumMember.java @@ -48,6 +48,14 @@ public Swc4jAstTsEnumMember( setInit(init); } + public static Swc4jAstTsEnumMember create(ISwc4jAstTsEnumMemberId id) { + return create(id, null); + } + + public static Swc4jAstTsEnumMember create(ISwc4jAstTsEnumMemberId id, ISwc4jAstExpr init) { + return new Swc4jAstTsEnumMember(id, init, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.of(id); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsExprWithTypeArgs.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsExprWithTypeArgs.java index 57a41d7a..d17abe26 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsExprWithTypeArgs.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsExprWithTypeArgs.java @@ -48,6 +48,14 @@ public Swc4jAstTsExprWithTypeArgs( setTypeArgs(typeArgs); } + public static Swc4jAstTsExprWithTypeArgs create(ISwc4jAstExpr expr) { + return create(expr, null); + } + + public static Swc4jAstTsExprWithTypeArgs create(ISwc4jAstExpr expr, Swc4jAstTsTypeParamInstantiation typeArgs) { + return new Swc4jAstTsExprWithTypeArgs(expr, typeArgs, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.of(expr); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsFnType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsFnType.java index de496c58..aacdc2c6 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsFnType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsFnType.java @@ -54,6 +54,21 @@ public Swc4jAstTsFnType( this.params.forEach(node -> node.setParent(this)); } + public static Swc4jAstTsFnType create(Swc4jAstTsTypeAnn typeAnn) { + return create(SimpleList.of(), typeAnn); + } + + public static Swc4jAstTsFnType create(List params, Swc4jAstTsTypeAnn typeAnn) { + return create(params, null, typeAnn); + } + + public static Swc4jAstTsFnType create( + List params, + Swc4jAstTsTypeParamDecl typeParams, + Swc4jAstTsTypeAnn typeAnn) { + return new Swc4jAstTsFnType(params, typeParams, typeAnn, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.copyOf(params); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsGetterSignature.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsGetterSignature.java index 906782a6..b81c83c1 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsGetterSignature.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsGetterSignature.java @@ -59,6 +59,35 @@ public Swc4jAstTsGetterSignature( setTypeAnn(typeAnn); } + public static Swc4jAstTsGetterSignature create(ISwc4jAstExpr key) { + return create(false, key); + } + + public static Swc4jAstTsGetterSignature create(boolean readonly, ISwc4jAstExpr key) { + return create(readonly, key, false); + } + + public static Swc4jAstTsGetterSignature create(boolean readonly, ISwc4jAstExpr key, boolean computed) { + return create(readonly, key, computed, false); + } + + public static Swc4jAstTsGetterSignature create( + boolean readonly, + ISwc4jAstExpr key, + boolean computed, + boolean optional) { + return create(readonly, key, computed, optional, null); + } + + public static Swc4jAstTsGetterSignature create( + boolean readonly, + ISwc4jAstExpr key, + boolean computed, + boolean optional, + Swc4jAstTsTypeAnn typeAnn) { + return new Swc4jAstTsGetterSignature(readonly, key, computed, optional, typeAnn, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.of(key); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsImportType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsImportType.java index b0861ad0..f631529c 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsImportType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsImportType.java @@ -54,6 +54,25 @@ public Swc4jAstTsImportType( setTypeArgs(typeArgs); } + public static Swc4jAstTsImportType create(Swc4jAstStr arg) { + return create(arg, null, null); + } + + public static Swc4jAstTsImportType create(Swc4jAstStr arg, ISwc4jAstTsEntityName qualifier) { + return create(arg, qualifier, null); + } + + public static Swc4jAstTsImportType create(Swc4jAstStr arg, Swc4jAstTsTypeParamInstantiation typeArgs) { + return create(arg, null, typeArgs); + } + + public static Swc4jAstTsImportType create( + Swc4jAstStr arg, + ISwc4jAstTsEntityName qualifier, + Swc4jAstTsTypeParamInstantiation typeArgs) { + return new Swc4jAstTsImportType(arg, qualifier, typeArgs, Swc4jSpan.DUMMY); + } + @Jni2RustMethod public Swc4jAstStr getArg() { return arg; diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexSignature.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexSignature.java index 02b53b1d..50f54d9e 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexSignature.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexSignature.java @@ -58,6 +58,33 @@ public Swc4jAstTsIndexSignature( this.params.forEach(node -> node.setParent(this)); } + public static Swc4jAstTsIndexSignature create() { + return create(SimpleList.of()); + } + + public static Swc4jAstTsIndexSignature create(List params) { + return create(params, null); + } + + public static Swc4jAstTsIndexSignature create(List params, Swc4jAstTsTypeAnn typeAnn) { + return create(params, typeAnn, false); + } + + public static Swc4jAstTsIndexSignature create( + List params, + Swc4jAstTsTypeAnn typeAnn, + boolean readonly) { + return create(params, typeAnn, readonly, false); + } + + public static Swc4jAstTsIndexSignature create( + List params, + Swc4jAstTsTypeAnn typeAnn, + boolean readonly, + boolean _static) { + return new Swc4jAstTsIndexSignature(params, typeAnn, readonly, _static, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { List childNodes = SimpleList.copyOf(params); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexedAccessType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexedAccessType.java index 743fc4ac..64995c2a 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexedAccessType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIndexedAccessType.java @@ -54,6 +54,17 @@ public Swc4jAstTsIndexedAccessType( setReadonly(readonly); } + public static Swc4jAstTsIndexedAccessType create(ISwc4jAstTsType objType, ISwc4jAstTsType indexType) { + return create(false, objType, indexType); + } + + public static Swc4jAstTsIndexedAccessType create( + boolean readonly, + ISwc4jAstTsType objType, + ISwc4jAstTsType indexType) { + return new Swc4jAstTsIndexedAccessType(readonly, objType, indexType, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { return SimpleList.of(objType, indexType); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInferType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInferType.java index b28a5d4f..cfb3c2a4 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInferType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInferType.java @@ -45,6 +45,10 @@ public Swc4jAstTsInferType( setTypeParam(typeParam); } + public static Swc4jAstTsInferType create(Swc4jAstTsTypeParam typeParam) { + return new Swc4jAstTsInferType(typeParam, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { return SimpleList.of(typeParam); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInterfaceBody.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInterfaceBody.java index a7e6921e..4942b7c2 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInterfaceBody.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsInterfaceBody.java @@ -45,6 +45,14 @@ public Swc4jAstTsInterfaceBody( this.body.forEach(node -> node.setParent(this)); } + public static Swc4jAstTsInterfaceBody create() { + return create(SimpleList.of()); + } + + public static Swc4jAstTsInterfaceBody create(List body) { + return new Swc4jAstTsInterfaceBody(body, Swc4jSpan.DUMMY); + } + @Jni2RustMethod public List getBody() { return body; diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIntersectionType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIntersectionType.java index 65a5b579..8c59c4e9 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIntersectionType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsIntersectionType.java @@ -49,6 +49,14 @@ public Swc4jAstTsIntersectionType( this.types.forEach(node -> node.setParent(this)); } + public static Swc4jAstTsIntersectionType create() { + return create(SimpleList.of()); + } + + public static Swc4jAstTsIntersectionType create(List types) { + return new Swc4jAstTsIntersectionType(types, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { return SimpleList.copyOf(types); diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsKeywordType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsKeywordType.java index d369811a..1645060c 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsKeywordType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsKeywordType.java @@ -45,6 +45,10 @@ public Swc4jAstTsKeywordType( setKind(kind); } + public static Swc4jAstTsKeywordType create(Swc4jAstTsKeywordTypeKind kind) { + return new Swc4jAstTsKeywordType(kind, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { return EMPTY_CHILD_NODES; diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsLitType.java b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsLitType.java index 659727f3..ee4c70bc 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsLitType.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsLitType.java @@ -46,6 +46,10 @@ public Swc4jAstTsLitType( setLit(lit); } + public static Swc4jAstTsLitType create(ISwc4jAstTsLit lit) { + return new Swc4jAstTsLitType(lit, Swc4jSpan.DUMMY); + } + @Override public List getChildNodes() { return SimpleList.of(lit);