-
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
9 changed files
with
309 additions
and
11 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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/caoccao/javet/buddy/ts2java/ast/BaseTs2JavaAstWithBuilderStore.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,38 @@ | ||
/* | ||
* 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; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaBuilderStore; | ||
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAst; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class BaseTs2JavaAstWithBuilderStore<AST extends ISwc4jAst> | ||
extends BaseTs2JavaAst<AST> | ||
implements ITs2JavaBuilderStore { | ||
protected final Ts2JavaDynamicTypeBuilderStore builderStore; | ||
|
||
public BaseTs2JavaAstWithBuilderStore(Ts2JavaDynamicTypeBuilderStore builderStore, AST ast) { | ||
super(ast); | ||
this.builderStore = Objects.requireNonNull(builderStore); | ||
} | ||
|
||
@Override | ||
public Ts2JavaDynamicTypeBuilderStore getBuilderStore() { | ||
return builderStore; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/caoccao/javet/buddy/ts2java/ast/clazz/Ts2JavaAstClass.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,68 @@ | ||
/* | ||
* 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.clazz; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.BaseTs2JavaAstWithBuilderStore; | ||
import com.caoccao.javet.buddy.ts2java.ast.Ts2JavaDynamicTypeBuilderStore; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstClassMember; | ||
import com.caoccao.javet.buddy.ts2java.exceptions.Ts2JavaAstException; | ||
import com.caoccao.javet.swc4j.ast.clazz.Swc4jAstClass; | ||
import com.caoccao.javet.swc4j.ast.clazz.Swc4jAstClassMethod; | ||
import com.caoccao.javet.swc4j.ast.interfaces.ISwc4jAstClassMember; | ||
import com.caoccao.javet.utils.SimpleFreeMarkerFormat; | ||
import com.caoccao.javet.utils.SimpleMap; | ||
import net.bytebuddy.implementation.Implementation; | ||
import net.bytebuddy.jar.asm.MethodVisitor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Ts2JavaAstClass | ||
extends BaseTs2JavaAstWithBuilderStore<Swc4jAstClass> { | ||
protected final List<ITs2JavaAstClassMember<?>> body; | ||
|
||
public Ts2JavaAstClass(Ts2JavaDynamicTypeBuilderStore builderStore, Swc4jAstClass ast) { | ||
super(builderStore, ast); | ||
body = new ArrayList<>(); | ||
for (ISwc4jAstClassMember classMember : ast.getBody()) { | ||
switch (classMember.getType()) { | ||
case ClassMethod: | ||
body.add(new Ts2JavaAstClassMethod(builderStore, classMember.as(Swc4jAstClassMethod.class))); | ||
break; | ||
default: | ||
throw new Ts2JavaAstException( | ||
classMember, | ||
SimpleFreeMarkerFormat.format("Class body type ${type} is not supported.", | ||
SimpleMap.of("type", classMember.getType().name()))); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Size apply(MethodVisitor methodVisitor, Implementation.Context context) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void compile() { | ||
body.forEach(ITs2JavaAstClassMember::compile); | ||
} | ||
|
||
public List<ITs2JavaAstClassMember<?>> getBody() { | ||
return body; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/com/caoccao/javet/buddy/ts2java/ast/clazz/Ts2JavaAstClassMethod.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,76 @@ | ||
/* | ||
* 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.clazz; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.BaseTs2JavaAstWithBuilderStore; | ||
import com.caoccao.javet.buddy.ts2java.ast.Ts2JavaDynamicTypeBuilderStore; | ||
import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAstClassMember; | ||
import com.caoccao.javet.buddy.ts2java.exceptions.Ts2JavaAstException; | ||
import com.caoccao.javet.swc4j.ast.clazz.Swc4jAstClassMethod; | ||
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstAccessibility; | ||
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstMethodKind; | ||
import com.caoccao.javet.swc4j.ast.expr.Swc4jAstIdentName; | ||
import com.caoccao.javet.utils.SimpleFreeMarkerFormat; | ||
import com.caoccao.javet.utils.SimpleMap; | ||
import net.bytebuddy.implementation.Implementation; | ||
import net.bytebuddy.jar.asm.MethodVisitor; | ||
|
||
public class Ts2JavaAstClassMethod | ||
extends BaseTs2JavaAstWithBuilderStore<Swc4jAstClassMethod> | ||
implements ITs2JavaAstClassMember<Swc4jAstClassMethod> { | ||
protected final Ts2JavaAstFunction function; | ||
|
||
public Ts2JavaAstClassMethod(Ts2JavaDynamicTypeBuilderStore builderStore, Swc4jAstClassMethod ast) { | ||
super(builderStore, ast); | ||
if (ast.isStatic()) { | ||
throw new Ts2JavaAstException( | ||
ast, | ||
"Static method is not implemented"); | ||
} | ||
if (ast.getKind() != Swc4jAstMethodKind.Method) { | ||
throw new Ts2JavaAstException( | ||
ast, | ||
SimpleFreeMarkerFormat.format("ClassMethod kind ${kind} is not supported.", | ||
SimpleMap.of("kind", ast.getKind().name()))); | ||
} | ||
if (!(ast.getKey() instanceof Swc4jAstIdentName)) { | ||
throw new Ts2JavaAstException( | ||
ast, | ||
SimpleFreeMarkerFormat.format("ClassMethod key type ${keyType} is not supported.", | ||
SimpleMap.of("keyType", ast.getKey().getClass().getSimpleName()))); | ||
|
||
} | ||
String name = ast.getKey().as(Swc4jAstIdentName.class).getSym(); | ||
boolean _static = ast.isStatic(); | ||
Swc4jAstAccessibility accessibility = ast.getAccessibility().orElse(Swc4jAstAccessibility.Public); | ||
function = new Ts2JavaAstFunction(builderStore, ast.getFunction(), name, _static, accessibility); | ||
} | ||
|
||
@Override | ||
public Size apply(MethodVisitor methodVisitor, Implementation.Context context) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void compile() { | ||
function.compile(); | ||
} | ||
|
||
public Ts2JavaAstFunction getFunction() { | ||
return function; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/caoccao/javet/buddy/ts2java/ast/clazz/Ts2JavaAstFunction.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,65 @@ | ||
/* | ||
* 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.clazz; | ||
|
||
import com.caoccao.javet.buddy.ts2java.ast.BaseTs2JavaAstWithBuilderStore; | ||
import com.caoccao.javet.buddy.ts2java.ast.Ts2JavaDynamicTypeBuilderStore; | ||
import com.caoccao.javet.swc4j.ast.clazz.Swc4jAstFunction; | ||
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstAccessibility; | ||
import net.bytebuddy.implementation.Implementation; | ||
import net.bytebuddy.jar.asm.MethodVisitor; | ||
|
||
public class Ts2JavaAstFunction | ||
extends BaseTs2JavaAstWithBuilderStore<Swc4jAstFunction> { | ||
protected final boolean _static; | ||
protected final Swc4jAstAccessibility accessibility; | ||
protected final String name; | ||
|
||
public Ts2JavaAstFunction( | ||
Ts2JavaDynamicTypeBuilderStore builderStore, | ||
Swc4jAstFunction ast, | ||
String name, | ||
boolean _static, | ||
Swc4jAstAccessibility accessibility) { | ||
super(builderStore, ast); | ||
this._static = _static; | ||
this.accessibility = accessibility; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public Size apply(MethodVisitor methodVisitor, Implementation.Context context) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void compile() { | ||
|
||
} | ||
|
||
public Swc4jAstAccessibility getAccessibility() { | ||
return accessibility; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public boolean isStatic() { | ||
return _static; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/caoccao/javet/buddy/ts2java/ast/interfaces/ITs2JavaAstClassMember.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.swc4j.ast.interfaces.ISwc4jAstClassMember; | ||
|
||
public interface ITs2JavaAstClassMember<AST extends ISwc4jAstClassMember> | ||
extends ITs2JavaAst<AST> { | ||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/caoccao/javet/buddy/ts2java/ast/interfaces/ITs2JavaBuilderStore.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,23 @@ | ||
/* | ||
* 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.Ts2JavaDynamicTypeBuilderStore; | ||
|
||
public interface ITs2JavaBuilderStore { | ||
Ts2JavaDynamicTypeBuilderStore getBuilderStore(); | ||
} |
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