Skip to content

Commit

Permalink
✨ feat: Add create() v13
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Jun 5, 2024
1 parent 256a60e commit 7116c86
Show file tree
Hide file tree
Showing 23 changed files with 381 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ public Swc4jAstTsMappedType(
setTypeParam(typeParam);
}

public static Swc4jAstTsMappedType create(Swc4jAstTsTypeParam typeParam) {
return create(null, typeParam);
}

public static Swc4jAstTsMappedType create(Swc4jAstTruePlusMinus readonly, Swc4jAstTsTypeParam typeParam) {
return create(readonly, typeParam, null);
}

public static Swc4jAstTsMappedType create(
Swc4jAstTruePlusMinus readonly,
Swc4jAstTsTypeParam typeParam,
ISwc4jAstTsType nameType) {
return create(readonly, typeParam, nameType, null);
}

public static Swc4jAstTsMappedType create(
Swc4jAstTruePlusMinus readonly,
Swc4jAstTsTypeParam typeParam,
ISwc4jAstTsType nameType,
Swc4jAstTruePlusMinus optional) {
return create(readonly, typeParam, nameType, optional, null);
}

public static Swc4jAstTsMappedType create(
Swc4jAstTruePlusMinus readonly,
Swc4jAstTsTypeParam typeParam,
ISwc4jAstTsType nameType,
Swc4jAstTruePlusMinus optional,
ISwc4jAstTsType typeAnn) {
return new Swc4jAstTsMappedType(readonly, typeParam, nameType, optional, typeAnn, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.of(typeParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,61 @@ public Swc4jAstTsMethodSignature(
this.params.forEach(node -> node.setParent(this));
}

public static Swc4jAstTsMethodSignature create(ISwc4jAstExpr key) {
return create(key, SimpleList.of());
}

public static Swc4jAstTsMethodSignature create(ISwc4jAstExpr key, List<ISwc4jAstTsFnParam> params) {
return create(false, key, params);
}

public static Swc4jAstTsMethodSignature create(
boolean readonly,
ISwc4jAstExpr key,
List<ISwc4jAstTsFnParam> params) {
return create(readonly, key, false, params);
}

public static Swc4jAstTsMethodSignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
List<ISwc4jAstTsFnParam> params) {
return create(readonly, key, computed, false, params);
}

public static Swc4jAstTsMethodSignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
List<ISwc4jAstTsFnParam> params) {
return create(readonly, key, computed, optional, params, null);
}

public static Swc4jAstTsMethodSignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn) {
return create(readonly, key, computed, optional, params, typeAnn, null);
}

public static Swc4jAstTsMethodSignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn,
Swc4jAstTsTypeParamDecl typeParams) {
return new Swc4jAstTsMethodSignature(
readonly, key, computed, optional, 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 @@ -47,6 +47,10 @@ public Swc4jAstTsOptionalType(
setTypeAnn(typeAnn);
}

public static Swc4jAstTsOptionalType create(ISwc4jAstTsType typeAnn) {
return new Swc4jAstTsOptionalType(typeAnn, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(typeAnn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.caoccao.javet.swc4j.ast.clazz.Swc4jAstDecorator;
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstAccessibility;
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstType;
import com.caoccao.javet.swc4j.ast.interfaces.*;
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAst;
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAstParamOrTsParamProp;
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAstTsParamPropParam;
import com.caoccao.javet.swc4j.ast.visitors.ISwc4jAstVisitor;
import com.caoccao.javet.swc4j.ast.visitors.Swc4jAstVisitorResponse;
import com.caoccao.javet.swc4j.jni2rust.*;
Expand Down Expand Up @@ -59,6 +61,38 @@ public Swc4jAstTsParamProp(
this.decorators.forEach(node -> node.setParent(this));
}

public static Swc4jAstTsParamProp create(ISwc4jAstTsParamPropParam param) {
return create(SimpleList.of(), param);
}

public static Swc4jAstTsParamProp create(List<Swc4jAstDecorator> decorators, ISwc4jAstTsParamPropParam param) {
return create(decorators, null, param);
}

public static Swc4jAstTsParamProp create(
List<Swc4jAstDecorator> decorators,
Swc4jAstAccessibility accessibility,
ISwc4jAstTsParamPropParam param) {
return create(decorators, accessibility, false, param);
}

public static Swc4jAstTsParamProp create(
List<Swc4jAstDecorator> decorators,
Swc4jAstAccessibility accessibility,
boolean _override,
ISwc4jAstTsParamPropParam param) {
return create(decorators, accessibility, _override, false, param);
}

public static Swc4jAstTsParamProp create(
List<Swc4jAstDecorator> decorators,
Swc4jAstAccessibility accessibility,
boolean _override,
boolean readonly,
ISwc4jAstTsParamPropParam param) {
return new Swc4jAstTsParamProp(decorators, accessibility, _override, readonly, param, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public Optional<Swc4jAstAccessibility> getAccessibility() {
return accessibility;
Expand Down Expand Up @@ -86,6 +120,16 @@ public Swc4jAstType getType() {
return Swc4jAstType.TsParamProp;
}

@Jni2RustMethod
public boolean isOverride() {
return _override;
}

@Jni2RustMethod
public boolean isReadonly() {
return readonly;
}

@Override
public boolean replaceNode(ISwc4jAst oldNode, ISwc4jAst newNode) {
if (!decorators.isEmpty() && newNode instanceof Swc4jAstDecorator) {
Expand All @@ -105,16 +149,6 @@ public boolean replaceNode(ISwc4jAst oldNode, ISwc4jAst newNode) {
return false;
}

@Jni2RustMethod
public boolean isOverride() {
return _override;
}

@Jni2RustMethod
public boolean isReadonly() {
return readonly;
}

public Swc4jAstTsParamProp setAccessibility(Swc4jAstAccessibility accessibility) {
this.accessibility = Optional.ofNullable(accessibility);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public Swc4jAstTsParenthesizedType(
setTypeAnn(typeAnn);
}

public static Swc4jAstTsParenthesizedType create(ISwc4jAstTsType typeAnn) {
return new Swc4jAstTsParenthesizedType(typeAnn, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(typeAnn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,73 @@ public Swc4jAstTsPropertySignature(
this.params.forEach(node -> node.setParent(this));
}

public static Swc4jAstTsPropertySignature create(ISwc4jAstExpr key) {
return create(key, SimpleList.of());
}

public static Swc4jAstTsPropertySignature create(ISwc4jAstExpr key, List<ISwc4jAstTsFnParam> params) {
return create(false, key, params);
}

public static Swc4jAstTsPropertySignature create(
boolean readonly,
ISwc4jAstExpr key,
List<ISwc4jAstTsFnParam> params) {
return create(readonly, key, false, params);
}

public static Swc4jAstTsPropertySignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
List<ISwc4jAstTsFnParam> params) {
return create(readonly, key, computed, false, params);
}

public static Swc4jAstTsPropertySignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
List<ISwc4jAstTsFnParam> params) {
return create(readonly, key, computed, optional, null, params);
}

public static Swc4jAstTsPropertySignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
ISwc4jAstExpr init,
List<ISwc4jAstTsFnParam> params) {
return create(readonly, key, computed, optional, init, params, null);
}

public static Swc4jAstTsPropertySignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
ISwc4jAstExpr init,
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn) {
return create(readonly, key, computed, optional, init, params, typeAnn, null);
}

public static Swc4jAstTsPropertySignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
ISwc4jAstExpr init,
List<ISwc4jAstTsFnParam> params,
Swc4jAstTsTypeAnn typeAnn,
Swc4jAstTsTypeParamDecl typeParams) {
return new Swc4jAstTsPropertySignature(
readonly, key, computed, optional, init,
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 @@ -49,6 +49,10 @@ public Swc4jAstTsQualifiedName(
setRight(right);
}

public static Swc4jAstTsQualifiedName create(ISwc4jAstTsEntityName left, Swc4jAstIdent right) {
return new Swc4jAstTsQualifiedName(left, right, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(left, right);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public Swc4jAstTsRestType(
setTypeAnn(typeAnn);
}

public static Swc4jAstTsRestType create(ISwc4jAstTsType typeAnn) {
return new Swc4jAstTsRestType(typeAnn, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(typeAnn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ public Swc4jAstTsSetterSignature(
setReadonly(readonly);
}

public static Swc4jAstTsSetterSignature create(ISwc4jAstExpr key, ISwc4jAstTsFnParam param) {
return create(false, key, param);
}

public static Swc4jAstTsSetterSignature create(
boolean readonly,
ISwc4jAstExpr key,
ISwc4jAstTsFnParam param) {
return create(readonly, key, false, param);
}

public static Swc4jAstTsSetterSignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
ISwc4jAstTsFnParam param) {
return create(readonly, key, computed, false, param);
}

public static Swc4jAstTsSetterSignature create(
boolean readonly,
ISwc4jAstExpr key,
boolean computed,
boolean optional,
ISwc4jAstTsFnParam param) {
return new Swc4jAstTsSetterSignature(readonly, key, computed, optional, param, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(key, param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public Swc4jAstTsThisType(
super(span);
}

public static Swc4jAstTsThisType create() {
return new Swc4jAstTsThisType(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 @@ -54,6 +54,14 @@ public Swc4jAstTsTplLitType(
this.types.forEach(node -> node.setParent(this));
}

public static Swc4jAstTsTplLitType create(List<ISwc4jAstTsType> types) {
return create(types, SimpleList.of());
}

public static Swc4jAstTsTplLitType create(List<ISwc4jAstTsType> types, List<Swc4jAstTplElement> quasis) {
return new Swc4jAstTsTplLitType(types, quasis, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(types);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public Swc4jAstTsTupleElement(
setTy(ty);
}

public static Swc4jAstTsTupleElement create(ISwc4jAstTsType ty) {
return create(null, ty);
}

public static Swc4jAstTsTupleElement create(ISwc4jAstPat label, ISwc4jAstTsType ty) {
return new Swc4jAstTsTupleElement(label, ty, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.of(ty);
Expand Down
Loading

0 comments on commit 7116c86

Please sign in to comment.