-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
519 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/caoccao/javet/buddy/ts2java/ast/interfaces/ITs2JavaAstTsFnParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast.interfaces; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemo; | ||
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAstTsFnParam; | ||
|
||
public interface ITs2JavaAstTsFnParam<AST extends ISwc4jAstTsFnParam, Memo extends Ts2JavaMemo> | ||
extends ITs2JavaAst<AST, Memo> { | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/com/caoccao/javet/buddy/ts2java/ast/interfaces/ITs2JavaAstTsParamPropParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast.interfaces; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemo; | ||
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAstTsParamPropParam; | ||
|
||
public interface ITs2JavaAstTsParamPropParam<AST extends ISwc4jAstTsParamPropParam, Memo extends Ts2JavaMemo> | ||
extends ITs2JavaAst<AST, Memo> { | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/caoccao/javet/buddy/ts2java/ast/interfaces/ITs2JavaAstTsType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast.interfaces; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemo; | ||
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemoFunction; | ||
import com.caoccao.javet.buddy.ts2java.ast.ts.Ts2JavaAstTsKeywordType; | ||
import com.caoccao.javet.buddy.ts2java.ast.ts.Ts2JavaAstTsTypeRef; | ||
import com.caoccao.javet.buddy.ts2java.exceptions.Ts2JavaAstException; | ||
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAstTsType; | ||
import com.caoccao.javet.swc4j.ast.ts.Swc4jAstTsKeywordType; | ||
import com.caoccao.javet.swc4j.ast.ts.Swc4jAstTsTypeRef; | ||
import com.caoccao.javet.utils.SimpleFreeMarkerFormat; | ||
import com.caoccao.javet.utils.SimpleMap; | ||
|
||
public interface ITs2JavaAstTsType<AST extends ISwc4jAstTsType, Memo extends Ts2JavaMemo> | ||
extends ITs2JavaAst<AST, Memo> { | ||
static ITs2JavaAstTsType<?, ?> cast( | ||
ITs2JavaAst<?, ?> parent, | ||
ISwc4jAstTsType ast, | ||
Ts2JavaMemoFunction memo) { | ||
switch (ast.getType()) { | ||
case TsKeywordType: | ||
return new Ts2JavaAstTsKeywordType(parent, ast.as(Swc4jAstTsKeywordType.class), memo); | ||
case TsTypeRef: | ||
return new Ts2JavaAstTsTypeRef(parent, ast.as(Swc4jAstTsTypeRef.class), memo); | ||
default: | ||
throw new Ts2JavaAstException( | ||
ast, | ||
SimpleFreeMarkerFormat.format("Ts type ${type} is not supported.", | ||
SimpleMap.of("type", ast.getType().name()))); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/caoccao/javet/buddy/ts2java/ast/pat/Ts2JavaAstBindingIdent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast.pat; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.BaseTs2JavaAst; | ||
import com.caoccao.javet.buddy.ts2java.ast.expr.Ts2JavaAstIdent; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.*; | ||
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemoFunction; | ||
import com.caoccao.javet.buddy.ts2java.ast.ts.Ts2JavaAstTsTypeAnn; | ||
import com.caoccao.javet.swc4j.ast.pat.Swc4jAstBindingIdent; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.implementation.Implementation; | ||
import net.bytebuddy.jar.asm.MethodVisitor; | ||
|
||
import java.util.Optional; | ||
|
||
public class Ts2JavaAstBindingIdent | ||
extends BaseTs2JavaAst<Swc4jAstBindingIdent, Ts2JavaMemoFunction> | ||
implements ITs2JavaAstPat<Swc4jAstBindingIdent, Ts2JavaMemoFunction>, | ||
ITs2JavaAstTsFnParam<Swc4jAstBindingIdent, Ts2JavaMemoFunction>, | ||
ITs2JavaAstTsParamPropParam<Swc4jAstBindingIdent, Ts2JavaMemoFunction>, | ||
ITs2JavaAstSimpleAssignTarget<Swc4jAstBindingIdent, Ts2JavaMemoFunction> { | ||
protected final Ts2JavaAstIdent id; | ||
protected final Optional<Ts2JavaAstTsTypeAnn> typeAnn; | ||
|
||
public Ts2JavaAstBindingIdent( | ||
ITs2JavaAst<?, ?> parent, | ||
Swc4jAstBindingIdent ast, | ||
Ts2JavaMemoFunction memo) { | ||
super(parent, ast, memo); | ||
typeAnn = ast.getTypeAnn().map(t -> new Ts2JavaAstTsTypeAnn(this, t, memo)); | ||
type = typeAnn.map(Ts2JavaAstTsTypeAnn::getType).orElse(TypeDescription.ForLoadedType.of(void.class)); | ||
id = new Ts2JavaAstIdent(this, ast.getId(), type, memo); | ||
} | ||
|
||
@Override | ||
public Size apply(MethodVisitor methodVisitor, Implementation.Context context) { | ||
visitLineNumber(methodVisitor); | ||
return Size.ZERO; | ||
} | ||
|
||
@Override | ||
public void compile() { | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/caoccao/javet/buddy/ts2java/ast/stmt/Ts2JavaAstVarDecl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast.stmt; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.BaseTs2JavaAst; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAst; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstDecl; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstForHead; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstVarDeclOrExpr; | ||
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemoFunction; | ||
import com.caoccao.javet.swc4j.ast.stmt.Swc4jAstVarDecl; | ||
import net.bytebuddy.implementation.Implementation; | ||
import net.bytebuddy.jar.asm.MethodVisitor; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Ts2JavaAstVarDecl | ||
extends BaseTs2JavaAst<Swc4jAstVarDecl, Ts2JavaMemoFunction> | ||
implements ITs2JavaAstDecl<Swc4jAstVarDecl, Ts2JavaMemoFunction>, | ||
ITs2JavaAstVarDeclOrExpr<Swc4jAstVarDecl, Ts2JavaMemoFunction>, | ||
ITs2JavaAstForHead<Swc4jAstVarDecl, Ts2JavaMemoFunction> { | ||
protected final List<Ts2JavaAstVarDeclarator> decls; | ||
|
||
public Ts2JavaAstVarDecl( | ||
ITs2JavaAst<?, ?> parent, | ||
Swc4jAstVarDecl ast, | ||
Ts2JavaMemoFunction memo) { | ||
super(parent, ast, memo); | ||
decls = ast.getDecls().stream() | ||
.map(decl -> new Ts2JavaAstVarDeclarator(this, decl, memo)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public Size apply(MethodVisitor methodVisitor, Implementation.Context context) { | ||
visitLineNumber(methodVisitor); | ||
return Size.ZERO; | ||
} | ||
|
||
@Override | ||
public void compile() { | ||
decls.forEach(Ts2JavaAstVarDeclarator::compile); | ||
} | ||
|
||
public List<Ts2JavaAstVarDeclarator> getDecls() { | ||
return decls; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/caoccao/javet/buddy/ts2java/ast/stmt/Ts2JavaAstVarDeclarator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast.stmt; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.BaseTs2JavaAst; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAst; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstDecl; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstExpr; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstPat; | ||
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemoFunction; | ||
import com.caoccao.javet.swc4j.ast.stmt.Swc4jAstVarDeclarator; | ||
import net.bytebuddy.implementation.Implementation; | ||
import net.bytebuddy.jar.asm.MethodVisitor; | ||
|
||
import java.util.Optional; | ||
|
||
public class Ts2JavaAstVarDeclarator | ||
extends BaseTs2JavaAst<Swc4jAstVarDeclarator, Ts2JavaMemoFunction> | ||
implements ITs2JavaAstDecl<Swc4jAstVarDeclarator, Ts2JavaMemoFunction> { | ||
protected final Optional<ITs2JavaAstExpr> init; | ||
protected final ITs2JavaAstPat name; | ||
|
||
public Ts2JavaAstVarDeclarator( | ||
ITs2JavaAst<?, ?> parent, | ||
Swc4jAstVarDeclarator ast, | ||
Ts2JavaMemoFunction memo) { | ||
super(parent, ast, memo); | ||
name = ITs2JavaAstPat.cast(this, ast.getName(), memo); | ||
type = name.getType(); | ||
init = ast.getInit().map(expr -> ITs2JavaAstExpr.cast(this, expr, type, memo)); | ||
} | ||
|
||
@Override | ||
public Size apply(MethodVisitor methodVisitor, Implementation.Context context) { | ||
visitLineNumber(methodVisitor); | ||
return Size.ZERO; | ||
} | ||
|
||
@Override | ||
public void compile() { | ||
} | ||
|
||
public Optional<ITs2JavaAstExpr> getInit() { | ||
return init; | ||
} | ||
|
||
public ITs2JavaAstPat getName() { | ||
return name; | ||
} | ||
} |
Oops, something went wrong.