Skip to content

Commit

Permalink
✨ feat: Add create() v12
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Jun 3, 2024
1 parent 9da6fe1 commit 96d2db6
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public Swc4jAstTsArrayType(
setElemType(elemType);
}

public static Swc4jAstTsArrayType create(ISwc4jAstTsType elemType) {
return new Swc4jAstTsArrayType(elemType, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(elemType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAstTsFnParam> params) {
return create(params, null, null);
}

public static Swc4jAstTsCallSignatureDecl create(List<ISwc4jAstTsFnParam> params, Swc4jAstTsTypeAnn typeAnn) {
return create(params, typeAnn, null);
}

public static Swc4jAstTsCallSignatureDecl create(List<ISwc4jAstTsFnParam> params, Swc4jAstTsTypeParamDecl typeParams) {
return create(params, null, typeParams);
}

public static Swc4jAstTsCallSignatureDecl create(
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn,
Swc4jAstTsTypeParamDecl typeParams) {
return new Swc4jAstTsCallSignatureDecl(params, typeAnn, typeParams, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAstTsFnParam> params) {
return create(params, null, null);
}

public static Swc4jAstTsConstructSignatureDecl create(List<ISwc4jAstTsFnParam> params, Swc4jAstTsTypeAnn typeAnn) {
return create(params, typeAnn, null);
}

public static Swc4jAstTsConstructSignatureDecl create(List<ISwc4jAstTsFnParam> params, Swc4jAstTsTypeParamDecl typeParams) {
return create(params, null, typeParams);
}

public static Swc4jAstTsConstructSignatureDecl create(
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn,
Swc4jAstTsTypeParamDecl typeParams) {
return new Swc4jAstTsConstructSignatureDecl(params, typeAnn, typeParams, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAstTsFnParam> params, Swc4jAstTsTypeAnn typeAnn) {
return create(params, null, typeAnn);
}

public static Swc4jAstTsConstructorType create(
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeParamDecl typeParams,
Swc4jAstTsTypeAnn typeAnn) {
return create(params, typeParams, typeAnn, false);
}

public static Swc4jAstTsConstructorType create(
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeParamDecl typeParams,
Swc4jAstTsTypeAnn typeAnn,
boolean _abstract) {
return new Swc4jAstTsConstructorType(params, typeParams, typeAnn, _abstract, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.of(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.of(expr);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/caoccao/javet/swc4j/ast/ts/Swc4jAstTsFnType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAstTsFnParam> params, Swc4jAstTsTypeAnn typeAnn) {
return create(params, null, typeAnn);
}

public static Swc4jAstTsFnType create(
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeParamDecl typeParams,
Swc4jAstTsTypeAnn typeAnn) {
return new Swc4jAstTsFnType(params, typeParams, typeAnn, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.of(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAstTsFnParam> params) {
return create(params, null);
}

public static Swc4jAstTsIndexSignature create(List<ISwc4jAstTsFnParam> params, Swc4jAstTsTypeAnn typeAnn) {
return create(params, typeAnn, false);
}

public static Swc4jAstTsIndexSignature create(
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn,
boolean readonly) {
return create(params, typeAnn, readonly, false);
}

public static Swc4jAstTsIndexSignature create(
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn,
boolean readonly,
boolean _static) {
return new Swc4jAstTsIndexSignature(params, typeAnn, readonly, _static, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAst> getChildNodes() {
return SimpleList.of(objType, indexType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public Swc4jAstTsInferType(
setTypeParam(typeParam);
}

public static Swc4jAstTsInferType create(Swc4jAstTsTypeParam typeParam) {
return new Swc4jAstTsInferType(typeParam, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(typeParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAstTsTypeElement> body) {
return new Swc4jAstTsInterfaceBody(body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public List<ISwc4jAstTsTypeElement> getBody() {
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwc4jAstTsType> types) {
return new Swc4jAstTsIntersectionType(types, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.copyOf(types);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public Swc4jAstTsKeywordType(
setKind(kind);
}

public static Swc4jAstTsKeywordType create(Swc4jAstTsKeywordTypeKind kind) {
return new Swc4jAstTsKeywordType(kind, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return EMPTY_CHILD_NODES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public Swc4jAstTsLitType(
setLit(lit);
}

public static Swc4jAstTsLitType create(ISwc4jAstTsLit lit) {
return new Swc4jAstTsLitType(lit, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(lit);
Expand Down

0 comments on commit 96d2db6

Please sign in to comment.