diff options
10 files changed, 297 insertions, 9 deletions
diff --git a/hobgoblin/src/output/lang/typescript/ast.hob b/hobgoblin/src/output/lang/typescript/ast.hob index 14ad052..8a254b6 100644 --- a/hobgoblin/src/output/lang/typescript/ast.hob +++ b/hobgoblin/src/output/lang/typescript/ast.hob @@ -7,9 +7,21 @@ struct TypescriptModule { // identifiers, but we have this constraint for simplicity. field name: List[TypescriptIdentifier]; + field imports: List[TypescriptImportDeclaration]; + field body: List[TypescriptStatement]; } +struct TypescriptImportDeclaration { + field namedImports: List[TypescriptNamedImport]; + field fromModule: String; +} + +struct TypescriptNamedImport { + field exportName: TypescriptIdentifier; + field importName: TypescriptIdentifier; +} + // == Statements == sum TypescriptStatement { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java index 89d6d5e..ac8e93a 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java @@ -89,7 +89,7 @@ public class TypescriptTypesGenerator implements Generator { .flatMap(statement -> generateNamespaceStatement(statement, typesInfo).stream()) .toList(); - return new TypescriptModule(typescriptModuleName, statements); + return new TypescriptModule(typescriptModuleName, List.of(), statements); } private List<TypescriptStatement> generateNamespaceStatement( diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java index d177b58..34a6d99 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java @@ -51,6 +51,14 @@ public class TypescriptWriter implements AutoCloseable { writeCustomArea(new TypescriptCustomArea("imports")); this.writer.newLine(); + for (var importDeclaration : module.imports()) { + this.writeImportDeclaration(importDeclaration); + } + + if (!module.imports().isEmpty()) { + this.writer.newLine(); + } + if (!module.body().isEmpty()) { writeWithSeparator( module.body(), @@ -68,6 +76,28 @@ public class TypescriptWriter implements AutoCloseable { writeCustomArea(new TypescriptCustomArea("body")); } + private void writeImportDeclaration(TypescriptImportDeclaration importDeclaration) throws IOException { + this.writer.write("import {"); + + writeWithSeparator( + importDeclaration.namedImports(), + namedImport -> { + this.writeIdentifier(namedImport.exportName()); + this.writer.write(" as "); + this.writeIdentifier(namedImport.importName()); + }, + () -> this.writer.write(", ") + ); + + this.writer.write("} from "); + // TODO: proper string literals + this.writer.write("\""); + this.writer.write(importDeclaration.fromModule()); + this.writer.write("\""); + this.writer.write(";"); + this.writer.newLine(); + } + // == Statements == void writeStatement(TypescriptStatement statement) throws IOException { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclaration.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclaration.java new file mode 100644 index 0000000..3bed5be --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclaration.java @@ -0,0 +1,50 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration imports + +public record TypescriptImportDeclaration( + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport> namedImports, + String fromModule +) { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder(java.util.List.of(), ""); + } + + public record Builder( + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport> namedImports, + String fromModule + ) { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration(namedImports, fromModule); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder withNamedImports(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport> namedImports) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder(namedImports, fromModule); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder addNamedImport(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport namedImport) { + var namedImports = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>(this.namedImports); + namedImports.add(namedImport); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder(namedImports, fromModule); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder addNamedImport(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder namedImport) { + var namedImports = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>(this.namedImports); + namedImports.add(namedImport.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder(namedImports, fromModule); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder withFromModule(String fromModule) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder(namedImports, fromModule); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration body +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModule.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModule.java index 0ddcb6a..466e362 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModule.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModule.java @@ -7,50 +7,68 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; public record TypescriptModule( java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> name, + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration> imports, java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement> body ) { public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder arbitrary() { - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(java.util.List.of(), java.util.List.of()); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(java.util.List.of(), java.util.List.of(), java.util.List.of()); } public record Builder( java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> name, + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration> imports, java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement> body ) { public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule build() { - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule(name, body); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule(name, imports, body); } public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder withName(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> name) { - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, body); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); } public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder addNameElement(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier nameElement) { var name = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier>(this.name); name.add(nameElement); - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, body); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); } public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder addNameElement(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.Builder nameElement) { var name = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier>(this.name); name.add(nameElement.build()); - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, body); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder withImports(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration> imports) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder addImport(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration import_) { + var imports = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>(this.imports); + imports.add(import_); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder addImport(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.Builder import_) { + var imports = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>(this.imports); + imports.add(import_.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); } public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder withBody(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement> body) { - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, body); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); } public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder addBodyElement(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement bodyElement) { var body = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement>(this.body); body.add(bodyElement); - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, body); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); } public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder addBodyElement(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement.Builder bodyElement) { var body = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement>(this.body); body.add(bodyElement.build()); - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, body); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder(name, imports, body); } // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.Builder body diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImport.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImport.java new file mode 100644 index 0000000..0954db2 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImport.java @@ -0,0 +1,46 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport imports + +public record TypescriptNamedImport( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName, + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier importName +) { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.arbitrary().build(), org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.arbitrary().build()); + } + + public record Builder( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName, + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier importName + ) { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport(exportName, importName); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder withExportName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder(exportName, importName); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder withExportName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.Builder exportName) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder(exportName.build(), importName); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder withImportName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier importName) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder(exportName, importName); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder withImportName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.Builder importName) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder(exportName, importName.build()); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java index 56c51f5..7497421 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java @@ -35,6 +35,38 @@ public class TypescriptWriterTests { } @Test + public void moduleWithImports() throws IOException { + var typescript = TypescriptModule.arbitrary() + .addImport(TypescriptImportDeclaration.arbitrary() + .addNamedImport(TypescriptNamedImport.arbitrary() + .withExportName(id("Rectangle")) + .withImportName(id("ShapeRectangle")) + ) + .addNamedImport(TypescriptNamedImport.arbitrary() + .withExportName(id("Triangle")) + .withImportName(id("ShapeTriangle")) + ) + .withFromModule("./shapes") + ) + .build(); + + var string = write(writer -> writer.writeModule(typescript)); + + assertThat(string, equalTo(""" + // Generated by hobgoblin. + + // Custom area start: imports + // Custom area end: imports + + import {Rectangle as ShapeRectangle, Triangle as ShapeTriangle} from "./shapes"; + + // Custom area start: body + // Custom area end: body + """ + )); + } + + @Test public void moduleWithStatements() throws IOException { var typescript = TypescriptModule.arbitrary() .addBodyElement(TypescriptClassDeclaration.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclarationMatcher.java new file mode 100644 index 0000000..f2989ad --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclarationMatcher.java @@ -0,0 +1,47 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher imports + +public final class TypescriptImportDeclarationMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher isTypescriptImportDeclaration() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>> submatchers; + + private TypescriptImportDeclarationMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>> submatchers + ) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher withNamedImports(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>> namedImports) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("namedImports", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration::namedImports, (org.zwobble.precisely.Matcher) namedImports)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher withFromModule(org.zwobble.precisely.Matcher<? super String> fromModule) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("fromModule", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration::fromModule, (org.zwobble.precisely.Matcher) fromModule)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java index fdae828..9996e06 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java @@ -36,6 +36,12 @@ public final class TypescriptModuleMatcher implements org.zwobble.precisely.Matc return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher withImports(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>> imports) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("imports", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule::imports, (org.zwobble.precisely.Matcher) imports)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher withBody(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement>> body) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule::body, (org.zwobble.precisely.Matcher) body)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImportMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImportMatcher.java new file mode 100644 index 0000000..3b85311 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImportMatcher.java @@ -0,0 +1,47 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher imports + +public final class TypescriptNamedImportMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher isTypescriptNamedImport() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>> submatchers; + + private TypescriptNamedImportMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>> submatchers + ) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher withExportName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> exportName) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("exportName", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport::exportName, (org.zwobble.precisely.Matcher) exportName)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher withImportName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> importName) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("importName", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport::importName, (org.zwobble.precisely.Matcher) importName)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher body +} |
