├── docs ├── CNAME └── usecases │ ├── dependency-visualization.md │ └── usecases.md ├── chapi-ast-c ├── .gitignore └── src │ ├── test │ └── resources │ │ ├── grammar │ │ ├── BinaryDigit.c │ │ ├── FunctionCall.c │ │ ├── helloworld.c │ │ ├── TypeCast.c │ │ ├── add.c │ │ ├── pr403.c │ │ ├── FunctionReturningPointer.c │ │ ├── FuncForwardDeclaration.c │ │ ├── ParameterOfPointerType.c │ │ ├── FuncCallAsFuncArgument.c │ │ ├── FuncCallwithVarArgs.c │ │ ├── ll.c │ │ ├── dialog.c │ │ ├── FunctionPointer.c │ │ ├── bt.c │ │ └── integrate.c │ │ └── _fixtures │ │ └── examples │ │ ├── 1-helloworld.c │ │ └── 2-struct-function-pointer.c │ └── main │ └── kotlin │ └── chapi │ └── ast │ └── cast │ └── CAstBaseListener.kt ├── chapi-ast-go ├── README.md └── src │ ├── test │ └── resources │ │ ├── examples │ │ ├── function.go │ │ ├── ill_but_correct.go │ │ ├── anonymousMethods.go │ │ ├── gostmts.go │ │ ├── struct_with_func_type.go │ │ ├── arrayEllipsisDecls.go │ │ ├── params.go │ │ ├── method.go │ │ ├── maps.go │ │ ├── shortVarDecl.go │ │ ├── strings.go │ │ ├── promoted.go │ │ ├── switchesType.go │ │ ├── chan.go │ │ ├── arrayDecls.go │ │ ├── hardcodedPassword.go │ │ ├── varDecl.go │ │ ├── defers.go │ │ ├── multiple_type_decl.go │ │ ├── weakHash.go │ │ ├── returnStmt.go │ │ ├── switchesExpr.go │ │ ├── typeAsserts.go │ │ ├── bufChan.go │ │ ├── select.go │ │ ├── interfaces.go │ │ ├── example.go │ │ ├── foreachStmts.go │ │ ├── constDecl.go │ │ ├── sliceDecls.go │ │ ├── interface_inheritance.go │ │ ├── struct_promotion.go │ │ ├── map_with_string.go │ │ └── forStmts.go │ │ ├── gin │ │ └── helloworld.go │ │ └── specific │ │ └── struct_function.go │ └── main │ ├── java │ └── chapi │ │ └── ast │ │ └── antlr │ │ └── GoParserBase.java │ └── kotlin │ └── chapi │ └── ast │ └── goast │ ├── GoAnalyser.kt │ └── GoAstListener.kt ├── chapi-ast-protobuf ├── .gitignore └── src │ └── test │ └── resources │ └── common.proto ├── gradle.properties ├── chapi-parser-cmake ├── README.md └── src │ ├── test │ └── kotlin │ │ └── chapi │ │ └── parser │ │ └── cmake │ │ └── CMakeBasicListenerTest.kt │ └── main │ └── kotlin │ └── chapi │ └── parser │ └── cmake │ ├── CMakeBasicListener.kt │ └── CMakeAnalyser.kt ├── chapi-parser-toml ├── README.md └── src │ └── main │ └── kotlin │ └── chapi │ └── parser │ └── toml │ ├── TomlType.kt │ └── TomlAnalyser.kt ├── .adr.json ├── .idea └── icon.png ├── chapi-ast-rust └── src │ ├── test │ └── resources │ │ └── grammar │ │ ├── hello.rs │ │ ├── v1_48_0_unsafe_mod.rs │ │ ├── v1_53_0_unicode_identifier.rs │ │ ├── v1_46_0_split_float_literal.rs │ │ ├── v1_56_0_open_range.rs │ │ ├── issue_1985_raw_string.rs │ │ ├── inlinepython_example.rs │ │ ├── v1_53_0_or_pattern.rs │ │ └── v1_46_0_split_float_literal.rs.tree │ └── main │ ├── java │ └── chapi │ │ └── ast │ │ └── antlr │ │ └── RustParserBase.java │ └── kotlin │ └── chapi │ └── ast │ └── rustast │ └── RustAnalyser.kt ├── _fixtures └── ast │ └── java │ └── arch │ ├── domain │ ├── Provider.java │ ├── ValueObject.java │ ├── Entity.java │ ├── AggregateRoot.java │ ├── ValueObjectC.java │ ├── ValueObjectD.java │ ├── EntityB.java │ ├── AggregateRootB.java │ ├── Router.java │ └── AggregateRootA.java │ ├── repositories │ ├── Repository.java │ └── AggregateRootARepo.java │ ├── gateways │ └── FakeRouter.java │ └── Main.java ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── chapi-module.gradle ├── chapi-ast-kotlin └── src │ ├── test │ ├── resources │ │ └── grammar │ │ │ └── main.kt │ └── kotlin │ │ └── chapi │ │ └── ast │ │ └── kotlinast │ │ └── KotlinAnalyserTest.kt │ └── main │ └── kotlin │ └── chapi │ └── ast │ └── kotlinast │ └── KotlinAstListener.kt ├── chapi-ast-cpp └── src │ ├── test │ └── resources │ │ ├── grammar │ │ ├── template_args_test.cpp │ │ ├── helloworld.cpp │ │ ├── not_keyword.cpp │ │ ├── and_keyword.cpp │ │ ├── or_keyword.cpp │ │ └── macro.cpp │ │ └── tequila │ │ ├── inheritance-tree-code │ │ ├── main.cpp │ │ └── inheritance-tree.dot │ │ └── LICENSE │ └── main │ └── java │ └── chapi │ └── ast │ └── antlr │ └── CPP14ParserBase.java ├── .gitattributes ├── chapi-ast-scala ├── src │ ├── test │ │ └── resources │ │ │ ├── grammar │ │ │ ├── example1.scala │ │ │ ├── object.scala │ │ │ ├── example2.scala │ │ │ ├── string.scala │ │ │ └── class.scala │ │ │ └── dsl │ │ │ └── Story.scala │ └── main │ │ └── kotlin │ │ └── chapi │ │ └── ast │ │ └── scalaast │ │ ├── ScalaAnalyser.kt │ │ └── ScalaAstBaseListener.kt └── README.md ├── scripts ├── compile-cpp.sh ├── compile-groovy.sh └── compile-typescript.sh ├── chapi-domain ├── src │ ├── main │ │ └── kotlin │ │ │ └── chapi │ │ │ ├── domain │ │ │ ├── core │ │ │ │ ├── CodeProject.kt │ │ │ │ ├── Since.kt │ │ │ │ ├── CodePackageInfo.kt │ │ │ │ ├── CodeModule.kt │ │ │ │ ├── CodeExport.kt │ │ │ │ ├── CodeDependency.kt │ │ │ │ ├── CodePosition.kt │ │ │ │ ├── CodeImport.kt │ │ │ │ ├── CodePackage.kt │ │ │ │ ├── CodeProperty.kt │ │ │ │ ├── CodeField.kt │ │ │ │ └── CodeMember.kt │ │ │ └── DomainConstants.kt │ │ │ └── infra │ │ │ └── Stack.kt │ └── test │ │ └── kotlin │ │ └── chapi │ │ └── domain │ │ └── core │ │ ├── CodeImportTest.kt │ │ ├── CodeFieldTest.kt │ │ ├── CodePackageInfoTest.kt │ │ ├── CodePropertyTest.kt │ │ ├── CodeProjectTest.kt │ │ └── CodeContainerTest.kt └── build.gradle.kts ├── chapi-ast-csharp └── src │ ├── test │ └── resources │ │ ├── Domain-Driven-Design │ │ ├── eCommerce │ │ │ ├── Helpers │ │ │ │ ├── Domain │ │ │ │ │ ├── IAggregateRoot.cs │ │ │ │ │ ├── IDomainService.cs │ │ │ │ │ ├── Handle.cs │ │ │ │ │ ├── DomainEventRecord.cs │ │ │ │ │ ├── DomainEvent.cs │ │ │ │ │ └── DomainEventHandle.cs │ │ │ │ ├── Logging │ │ │ │ │ └── IRequestCorrelationIdentifier.cs │ │ │ │ ├── Repository │ │ │ │ │ ├── IUnitOfWork.cs │ │ │ │ │ ├── IDomainEventRepository.cs │ │ │ │ │ └── IRepository.cs │ │ │ │ └── Specification │ │ │ │ │ ├── ISpecification.cs │ │ │ │ │ ├── SpecificationBase.cs │ │ │ │ │ ├── IExtensions.cs │ │ │ │ │ ├── Negate.cs │ │ │ │ │ ├── Or.cs │ │ │ │ │ └── And.cs │ │ │ ├── DomainModelLayer │ │ │ │ ├── Email │ │ │ │ │ ├── EmailTemplate.cs │ │ │ │ │ ├── IEmailGenerator.cs │ │ │ │ │ └── IEmailDispatcher.cs │ │ │ │ ├── Tax │ │ │ │ │ ├── TaxType.cs │ │ │ │ │ ├── CountryTaxCreated.cs │ │ │ │ │ └── CountryTax.cs │ │ │ │ ├── Products │ │ │ │ │ ├── ReturnReason.cs │ │ │ │ │ ├── ProductCodeCreated.cs │ │ │ │ │ ├── Return.cs │ │ │ │ │ ├── ProductCreated.cs │ │ │ │ │ ├── ProductReturnReasonSpec.cs │ │ │ │ │ ├── ProductCode.cs │ │ │ │ │ └── ProductIsInStockSpec.cs │ │ │ │ ├── Services │ │ │ │ │ ├── ProductState.cs │ │ │ │ │ └── PaymentStatus.cs │ │ │ │ ├── Newsletter │ │ │ │ │ └── INewsletterSubscriber.cs │ │ │ │ ├── Carts │ │ │ │ │ ├── CheckOutIssue.cs │ │ │ │ │ ├── CartCreated.cs │ │ │ │ │ ├── ProductAddedCart.cs │ │ │ │ │ ├── ProductRemovedCart.cs │ │ │ │ │ ├── CustomerCartSpec.cs │ │ │ │ │ └── ProductInCartSpec.cs │ │ │ │ ├── Customers │ │ │ │ │ ├── ICustomerRepository.cs │ │ │ │ │ ├── CustomerChangedEmail.cs │ │ │ │ │ ├── CustomerPurchaseHistoryReadModel.cs │ │ │ │ │ ├── CreditCardAdded.cs │ │ │ │ │ ├── CustomerCreated.cs │ │ │ │ │ ├── CustomerRegisteredSpec.cs │ │ │ │ │ ├── CustomerAlreadyRegisteredSpec.cs │ │ │ │ │ ├── CustomerCheckOut.cs │ │ │ │ │ ├── CustomerBulkIdFindSpec.cs │ │ │ │ │ ├── CreditCardAvailableSpec.cs │ │ │ │ │ └── CustomerCheckedOutHandle.cs │ │ │ │ ├── Countries │ │ │ │ │ ├── CountryCreated.cs │ │ │ │ │ └── Country.cs │ │ │ │ ├── Settings.cs │ │ │ │ └── Purchases │ │ │ │ │ ├── CustomerPurchasesSpec.cs │ │ │ │ │ ├── CustomerPurchasedNProductsSpec.cs │ │ │ │ │ └── PurchasedProduct.cs │ │ │ ├── ApplicationLayer │ │ │ │ ├── History │ │ │ │ │ ├── HistoryDto.cs │ │ │ │ │ ├── IHistoryService.cs │ │ │ │ │ ├── EventDto.cs │ │ │ │ │ └── HistoryService.cs │ │ │ │ ├── Carts │ │ │ │ │ ├── CartProductDto.cs │ │ │ │ │ ├── CartDto.cs │ │ │ │ │ ├── ICartService.cs │ │ │ │ │ └── CheckOutResultDto.cs │ │ │ │ ├── Products │ │ │ │ │ ├── IProductService.cs │ │ │ │ │ └── ProductDto.cs │ │ │ │ └── Customers │ │ │ │ │ ├── CreditCardDto.cs │ │ │ │ │ ├── CustomerDto.cs │ │ │ │ │ ├── CustomerPurchaseHistoryDto.cs │ │ │ │ │ └── ICustomerService.cs │ │ │ └── InfrastructureLayer │ │ │ │ ├── SmtpEmailDispatcher.cs │ │ │ │ ├── WSNewsletterSubscriber.cs │ │ │ │ ├── StubEmailGenerator.cs │ │ │ │ ├── MemoryUnitOfWork.cs │ │ │ │ ├── MemDomainEventRepository.cs │ │ │ │ └── MemoryRepository.cs │ │ ├── eCommerce.WebService │ │ │ ├── Models │ │ │ │ ├── ResponseOfTReturn.cs │ │ │ │ └── Response.cs │ │ │ ├── App_Start │ │ │ │ ├── FilterConfig.cs │ │ │ │ ├── MappingConfig.cs │ │ │ │ ├── WebApiConfig.cs │ │ │ │ ├── RouteConfig.cs │ │ │ │ ├── Installers │ │ │ │ │ ├── ApplicationLayerInstall.cs │ │ │ │ │ └── DistributedInterfaceLayerInstall.cs │ │ │ │ └── BootstrapConfig.cs │ │ │ ├── Controllers │ │ │ │ └── HistoryController.cs │ │ │ └── Global.asax.cs │ │ └── .gitignore │ │ ├── call │ │ └── hello.cs │ │ └── inference │ │ └── HistoryService.cs │ └── main │ └── java │ └── chapi │ └── ast │ └── antlr │ └── CSharpParserBase.java ├── chapi-ast-python └── src │ ├── test │ └── resources │ │ ├── grammar │ │ ├── while_stmt.py │ │ ├── class_or_func_def_stmt.py │ │ ├── classdef.py │ │ ├── testlist_comp.py │ │ ├── yield_expr.py │ │ ├── test.py │ │ ├── simple_stmt.py │ │ ├── def_parameters.py │ │ ├── funcdef.py │ │ ├── for_stmt.py │ │ ├── argument.py │ │ ├── with_stmt.py │ │ ├── if_stmt.py │ │ ├── typedargslist.py │ │ ├── comprehension.py │ │ ├── subscript.py │ │ ├── try_stmt.py │ │ ├── tokens.py │ │ ├── trailer.py │ │ ├── dictorsetmaker.py │ │ ├── logical_test.py │ │ ├── small_stmt.py │ │ ├── atom.py │ │ ├── varargslist.py │ │ ├── expr.py │ │ ├── import_stmt.py │ │ └── expr_stmt.py │ │ └── call │ │ ├── class_call.py │ │ └── builder_pattern_call.py │ └── main │ ├── java │ └── chapi │ │ └── ast │ │ └── antlr │ │ ├── PythonVersion.java │ │ └── PythonParserBase.java │ └── kotlin │ └── chapi │ └── ast │ └── pythonast │ └── PythonAnalyser.kt ├── chapi-ast-java └── src │ └── test │ └── resources │ ├── importstatic │ ├── SqlGenerator.java │ └── SourceBatch.java │ └── bug │ └── annotation │ └── DemoController.java ├── Makefile ├── chapi-ast-typescript └── src │ ├── test │ ├── resources │ │ └── grammar │ │ │ ├── Module.ts │ │ │ ├── Export.ts │ │ │ ├── GenericInterface.ts │ │ │ ├── AbstractClass.ts │ │ │ ├── Variable.ts │ │ │ ├── Class.ts │ │ │ ├── Generic.ts │ │ │ ├── GenericClass.ts │ │ │ ├── Function.ts │ │ │ ├── Type.ts │ │ │ ├── Statement.ts │ │ │ └── Interface.ts │ └── kotlin │ │ └── chapi │ │ └── ast │ │ └── typescriptast │ │ └── TypeScriptCallTest.kt │ └── main │ └── kotlin │ └── chapi │ └── ast │ └── typescriptast │ ├── TSIdentify.kt │ └── TypeScriptAnalyser.kt ├── .codeclimate.yml ├── chapi-helper ├── src │ └── test │ │ └── kotlin │ │ └── chapi │ │ └── ast │ │ └── helper │ │ └── TreeViewerTest.kt └── build.gradle.kts ├── .editorconfig ├── settings.gradle.kts ├── .gitignore ├── .github └── workflows │ ├── ci.yml │ └── cd.yml ├── chapi-ast-thrift └── src │ └── main │ └── kotlin │ └── chapi │ └── ast │ └── thrift │ └── ThriftAnalyser.kt └── .travis.yml /docs/CNAME: -------------------------------------------------------------------------------- 1 | chapi.phodal.com -------------------------------------------------------------------------------- /chapi-ast-c/.gitignore: -------------------------------------------------------------------------------- 1 | result.json 2 | -------------------------------------------------------------------------------- /chapi-ast-go/README.md: -------------------------------------------------------------------------------- 1 | # Chapi Go 2 | -------------------------------------------------------------------------------- /chapi-ast-protobuf/.gitignore: -------------------------------------------------------------------------------- 1 | *-proto.json 2 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | -------------------------------------------------------------------------------- /chapi-parser-cmake/README.md: -------------------------------------------------------------------------------- 1 | # CMakefile 2 | 3 | -------------------------------------------------------------------------------- /chapi-parser-toml/README.md: -------------------------------------------------------------------------------- 1 | # Just for fun 2 | 3 | -------------------------------------------------------------------------------- /.adr.json: -------------------------------------------------------------------------------- 1 | {"language":"zh-cn","path":"docs/adr/","prefix":"","digits":4} -------------------------------------------------------------------------------- /.idea/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/chapi/HEAD/.idea/icon.png -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/BinaryDigit.c: -------------------------------------------------------------------------------- 1 | int i = 0b0011; 2 | int j = 0B1010; 3 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/hello.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | print!("Hello world!"); 3 | } -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/v1_48_0_unsafe_mod.rs: -------------------------------------------------------------------------------- 1 | unsafe mod m 2 | { 3 | 4 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/function.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | // func BodylessFunction() -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/Provider.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class Provider { 5 | 6 | 7 | } -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/v1_53_0_unicode_identifier.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | let 全世界无产者 = "联合起来"; 3 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/chapi/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/ValueObject.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class ValueObject { 5 | 6 | 7 | } -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/Entity.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class Entity { 5 | 6 | public int id; 7 | 8 | } -------------------------------------------------------------------------------- /chapi-ast-kotlin/src/test/resources/grammar/main.kt: -------------------------------------------------------------------------------- 1 | package grammar 2 | 3 | fun main() { 4 | println("Hello world!") 5 | } 6 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/AggregateRoot.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class AggregateRoot extends Entity { 4 | 5 | 6 | } -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/FunctionCall.c: -------------------------------------------------------------------------------- 1 | int f(int arg1, char arg2) 2 | { 3 | a1(arg1); 4 | a2(arg1, arg2); 5 | a3(); 6 | } -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/ValueObjectC.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class ValueObjectC extends ValueObject { 5 | 6 | 7 | } -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/ValueObjectD.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class ValueObjectD extends ValueObject { 5 | 6 | 7 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/ill_but_correct.go: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import "fmt" 4 | 5 | func main() { ; 6 | ch <- 1 } 7 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/v1_46_0_split_float_literal.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | let a = b.1.2.3.4; 3 | let c = 1.2345; 4 | } -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/grammar/template_args_test.cpp: -------------------------------------------------------------------------------- 1 | void TemplateArgsTest(vector args, vector args2) 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/repositories/Repository.java: -------------------------------------------------------------------------------- 1 | package repositories; 2 | 3 | import domain.*; 4 | 5 | 6 | public class Repository { 7 | 8 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | **/src/main/java/chapi/ast/antlr/** linguist-vendored=true 2 | _fixtures/** linguist-vendored=true 3 | grammars/** linguist-vendored=true 4 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/EntityB.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class EntityB extends Entity { 5 | 6 | private ValueObjectD vo_d; 7 | } -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/_fixtures/examples/1-helloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Hello, World!"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/helloworld.c: -------------------------------------------------------------------------------- 1 | 2 | /* Hello World program */ 3 | 4 | main() 5 | { 6 | printf("Hello World"); 7 | 8 | } 9 | 10 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/grammar/helloworld.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | cout << "Hello World!"; 6 | return 0; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /chapi-ast-scala/src/test/resources/grammar/example1.scala: -------------------------------------------------------------------------------- 1 | 2 | object HelloWorld { 3 | def main(args: Array[String]): Unit = { 4 | println("Hello, world!") 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/AggregateRootB.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class AggregateRootB extends AggregateRoot { 5 | 6 | private AggregateRootA a; 7 | 8 | } -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/TypeCast.c: -------------------------------------------------------------------------------- 1 | f() 2 | { 3 | a1 = (int)(b1); 4 | a2 = (CustomType)(b2); 5 | a3 = (CustomType *)(b3); 6 | a4 = (CustomType **)(b4); 7 | a5 = b5(); 8 | } 9 | -------------------------------------------------------------------------------- /chapi-ast-protobuf/src/test/resources/common.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package common; 4 | 5 | enum Category { 6 | ELECTRONICS = 0; 7 | CLOTHING = 1; 8 | FOOD = 2; 9 | } 10 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/Router.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class Router extends Provider { 5 | 6 | public int select() { 7 | return 0; 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/v1_56_0_open_range.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | match x as u32 { 3 | 0 => println!("zero!"), 4 | 1.. => println!("positive number!"), 5 | }; 6 | } -------------------------------------------------------------------------------- /scripts/compile-cpp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd grammars/cpp 4 | 5 | antlr -Dlanguage=Java -listener -visitor CPP.g4 -o ../../chapi-ast-cpp/src/main/java/chapi/ast/antlr -package chapi.ast.antlr 6 | -------------------------------------------------------------------------------- /chapi-ast-scala/src/test/resources/grammar/object.scala: -------------------------------------------------------------------------------- 1 | package uuu.vvv.www.xxx.yyy.zzz 2 | 3 | object Fields { 4 | def test():String = { 5 | val a: String = "Apple" 6 | val b: String = "Ball"+ "NEW" 7 | "aaaa" 8 | } 9 | } -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeProject.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodeProject( 7 | var Modules: List = listOf() 8 | ) 9 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/grammar/not_keyword.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | if (not false) { 8 | cout << "Hello World!"; 9 | } 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/issue_1985_raw_string.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | let s1 = r"aaa"; 3 | let s2 = r#"aaa"#; 4 | let s3 = r##"aaa"##; 5 | let ss1 = br"aaa"; 6 | let ss2 = br#"aaa"#; 7 | let ss3 = br##"aaa"##; 8 | } -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/add.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int i, sum = 0; 4 | 5 | for ( i = 1; i <= LAST; i++ ) { 6 | sum += i; 7 | } /*-for-*/ 8 | printf("sum = %d\n", sum); 9 | 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/grammar/and_keyword.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | if (true and true) { 8 | cout << "Hello World!"; 9 | } 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/grammar/or_keyword.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | if (false or true) { 8 | cout << "Hello World!"; 9 | } 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/Since.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | /** 4 | * This annotation is used to mark the version of the API that a particular class or member was added. 5 | */ 6 | annotation class Since(val value: String) 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/gateways/FakeRouter.java: -------------------------------------------------------------------------------- 1 | package gateways; 2 | 3 | import domain.*; 4 | 5 | 6 | public class FakeRouter extends Router { 7 | public int select(){ 8 | System.out.println("routed \n"); 9 | return 1; 10 | }; 11 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Domain/IAggregateRoot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace eCommerce.Helpers.Domain 4 | { 5 | public interface IAggregateRoot 6 | { 7 | Guid Id { get; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/pr403.c: -------------------------------------------------------------------------------- 1 | 2 | /* Hello World program */ 3 | 4 | main() 5 | { 6 | printf (_("\ 7 | Usage: %s [ignored command line arguments]\n\ 8 | or: %s OPTION\n\ 9 | "), 10 | program_name, program_name); 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /docs/usecases/dependency-visualization.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Dependency Visualization 4 | nav_order: 2 5 | parent: Usecases 6 | permalink: /usecases/dependency-visualization 7 | --- 8 | 9 | Case example: [ArchGuard Frontend](https://archguard.org/) 10 | 11 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Logging/IRequestCorrelationIdentifier.cs: -------------------------------------------------------------------------------- 1 | namespace eCommerce.Helpers.Logging 2 | { 3 | public interface IRequestCorrelationIdentifier 4 | { 5 | string CorrelationID { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/while_stmt.py: -------------------------------------------------------------------------------- 1 | # while_stmt: WHILE test COLON suite else_clause? 2 | 3 | # WHILE test COLON suite 4 | while x == 3: 5 | x += 1 6 | 7 | # WHILE test COLON suite else_clause 8 | while x == 3: 9 | x += 1 10 | else: 11 | pass 12 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/call/hello.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HelloWorldApp { 4 | class Geeks { 5 | static void Main(string[] args) { 6 | Console.WriteLine("Hello World!"); 7 | Console.ReadKey(); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/inlinepython_example.rs: -------------------------------------------------------------------------------- 1 | use inline_python::python; 2 | 3 | fn main() { 4 | let who = "world"; 5 | let n = 5; 6 | python! { 7 | for i in range('n): 8 | print(i, "Hello", 'who) 9 | print("Goodbye") 10 | } 11 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/anonymousMethods.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | import . "time" 5 | 6 | func AnonymousMethods() { 7 | lambd := func(s string) { Sleep(10); fmt.Println(s) } 8 | lambd("From lambda!") 9 | func() { fmt.Println("Create and invoke!")}() 10 | } 11 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodePackageInfo.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodePackageInfo( 7 | var ProjectName: String = "", 8 | var Dependencies: List = listOf() 9 | ) 10 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/call/class_call.py: -------------------------------------------------------------------------------- 1 | # noinspection PyInterpreter 2 | class Employee: 3 | def __init__(self, name): 4 | self.name = name 5 | 6 | def displayEmployee(self): 7 | print "Name : ", self.name 8 | 9 | emp = Employee("Zara") 10 | emp.displayEmployee() 11 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/gin/helloworld.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | "net/http" 6 | ) 7 | 8 | func main() { 9 | r := gin.Default() 10 | 11 | r.GET("/", func(c *gin.Context) { 12 | c.String(http.StatusOK, "hello world") 13 | }) 14 | 15 | r.Run() 16 | } 17 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeModule.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodeModule ( 7 | var Packages : List = listOf(), 8 | var packageInfo : CodePackageInfo = CodePackageInfo() 9 | ) 10 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/repositories/AggregateRootARepo.java: -------------------------------------------------------------------------------- 1 | package repositories; 2 | 3 | import domain.*; 4 | 5 | 6 | public class AggregateRootARepo extends Repository { 7 | private AggregateRootA[] arList; 8 | public void save(AggregateRootA a){ 9 | System.out.println("saved\n"); 10 | }; 11 | } -------------------------------------------------------------------------------- /chapi-ast-java/src/test/resources/importstatic/SqlGenerator.java: -------------------------------------------------------------------------------- 1 | package infrastructure.utils; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class SqlGenerator { 7 | public static String generateBatchInsertSql(String table, List> values) { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Domain/IDomainService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.Helpers.Domain 7 | { 8 | public interface IDomainService 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/gostmts.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | // import "fmt" 4 | import . "time" 5 | 6 | func Server() { 7 | } 8 | 9 | func GoStmts() { 10 | go Server() 11 | go func() { Sleep(10) } () 12 | /*var c chan 13 | go func(ch chan<- bool) { for { sleep(10); ch <- true }} (<-c)*/ 14 | } 15 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/struct_with_func_type.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Person struct { 6 | work func() 7 | name string 8 | age int32 9 | } 10 | 11 | func main() { 12 | person := Person{work: nil, name: "Michał", age: 29} 13 | fmt.Println(person) // { Michał 29} 14 | } -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeExport.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodeExport( 7 | var Name: String = "", 8 | var SourceFile: String = "", 9 | var Type: DataStructType = DataStructType.CLASS 10 | ) 11 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/arrayEllipsisDecls.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type Custom struct { 8 | string 9 | } 10 | 11 | func ArrayEllipsisDecls() { 12 | stooges := [...]Custom{{"Moe"}, {"Larry"}, {"Curly"}} // len(stooges) == 3 13 | fmt.Println("Stooges: ", stooges) 14 | } -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/class_or_func_def_stmt.py: -------------------------------------------------------------------------------- 1 | # class_or_func_def_stmt: decorator+ (classdef | funcdef); 2 | 3 | # decorator classdef 4 | @decorator 5 | class foo: 6 | pass 7 | 8 | # decorator decorator funcdef 9 | @accepts(int,int) 10 | @returns(float) 11 | def bar(low,high): 12 | pass 13 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/tequila/inheritance-tree-code/main.cpp: -------------------------------------------------------------------------------- 1 | #include "code.h" 2 | 3 | using namespace Gateways; 4 | using namespace Repositories; 5 | 6 | int main(int argc, char const *argv[]) 7 | { 8 | router = new FakeRouter(); 9 | AggregateRootB* b = new AggregateRootB(); 10 | b->Init(); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/params.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ("fmt" 4 | "reflect" 5 | ) 6 | 7 | func ParamTest(a, b int32, c int16) { 8 | fmt.Printf("Type of a is %s\n", reflect.TypeOf(a)) 9 | fmt.Printf("Type of a is %s\n", reflect.TypeOf(b)) 10 | fmt.Printf("Type of a is %s\n", reflect.TypeOf(c)) 11 | } -------------------------------------------------------------------------------- /chapi-ast-scala/src/test/resources/grammar/example2.scala: -------------------------------------------------------------------------------- 1 | package foo.bar 2 | 3 | import scala.concurrent.ExecutionContext.Implicits._ 4 | 5 | object HelloWorld { 6 | def main(args: Array[`String`]): Unit = { 7 | println("Hello, world!") 8 | } 9 | } 10 | //not an empty comment 11 | // 12 | /*not an empty comment*/ 13 | /**/ 14 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/method.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | type Vertex struct { 9 | X, Y float64 10 | } 11 | 12 | func (v Vertex) Abs() float64 { 13 | return math.Sqrt(v.X*v.X + v.Y*v.Y) 14 | } 15 | 16 | func Methods() { 17 | v := Vertex{3, 4} 18 | fmt.Println(v.Abs()) 19 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Email/EmailTemplate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.DomainModelLayer.Email 7 | { 8 | public enum EmailTemplate 9 | { 10 | PurchaseMade 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /scripts/compile-groovy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd grammars/groovy 4 | 5 | antlr -Dlanguage=Java -listener -visitor GroovyLexer.g4 -o ../../chapi-ast-groovy/src/main/java/chapi/ast/antlr -package chapi.ast.antlr 6 | antlr -Dlanguage=Java -listener -visitor GroovyParser.g4 -o ../../chapi-ast-groovy/src/main/java/chapi/ast/antlr -package chapi.ast.antlr 7 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/classdef.py: -------------------------------------------------------------------------------- 1 | # classdef: CLASS name (OPEN_PAREN arglist? CLOSE_PAREN)? COLON suite 2 | 3 | # CLASS NAME COLON suite 4 | class foo: pass 5 | 6 | # CLASS NAME OPEN_PAREN CLOSE_PAREN COLON suite 7 | class bar(): pass 8 | 9 | # CLASS NAME OPEN_PAREN arglist CLOSE_PAREN COLON suite 10 | class baz(foo): 11 | pass 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: test 2 | 3 | build: 4 | 5 | 6 | test: 7 | ./gradlew test 8 | 9 | coverage: 10 | ./gradlew check jacocoTestReport jacocoRootReports coveralls 11 | 12 | changelog: 13 | conventional-changelog -p angular -i CHANGELOG.md -s -r 0 14 | 15 | bintrayUpload: 16 | ./gradlew bintrayUpload -Dbintray.user= -Dbintray.key= 17 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/FunctionReturningPointer.c: -------------------------------------------------------------------------------- 1 | //function returns pointer 2 | void * 3 | __cdecl 4 | f1( 5 | UINTN param1 6 | ); 7 | 8 | 9 | int * 10 | __cdecl 11 | f2 ( 12 | int param1 13 | ); 14 | 15 | 16 | int MyStruct * 17 | f3 ( 18 | int param1, 19 | char param2 20 | ); 21 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/testlist_comp.py: -------------------------------------------------------------------------------- 1 | # testlist_comp 2 | # : (test | star_expr) (comp_for | (COMMA (test | star_expr))* COMMA?) 3 | # ; 4 | 5 | # test 6 | [x] 7 | 8 | # star_expr comp_for 9 | [z for z in a] 10 | 11 | # test COMMA star_expr COMMA 12 | [x, *a,] 13 | 14 | # star_expr COMMA test COMMA star_expr 15 | [*u, a, *i] 16 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Tax/TaxType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.DomainModelLayer.Tax 7 | { 8 | public enum TaxType 9 | { 10 | Business, 11 | Customer 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-java/src/test/resources/importstatic/SourceBatch.java: -------------------------------------------------------------------------------- 1 | package infrastructure; 2 | 3 | import static infrastructure.utils.SqlGenerator.generateBatchInsertSql; 4 | 5 | public class SourceBatch extends DefaultBatchImpl { 6 | @Override 7 | public void execute() { 8 | String sql = generateBatchInsertSql(table, values); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /chapi-domain/src/test/kotlin/chapi/domain/core/CodeImportTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.junit.jupiter.api.Assertions.* 5 | 6 | internal class CodeImportTest { 7 | @Test 8 | fun testEquals() { 9 | assertEquals(CodeImport(Source = "source"), CodeImport(Source = "source")) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/yield_expr.py: -------------------------------------------------------------------------------- 1 | # yield_expr 2 | # : YIELD yield_arg? 3 | # ; 4 | # 5 | # yield_arg 6 | # : FROM test 7 | # | testlist 8 | # ; 9 | 10 | def f(): 11 | 12 | # YIELD 13 | yield 14 | 15 | # YIELD FROM test 16 | yield from g 17 | 18 | # YIELD testlist 19 | yield x, a, b if x else a 20 | 21 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/v1_53_0_or_pattern.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | for c in self.bytes() { 3 | match c { 4 | Err(e) => return Err(e), 5 | Ok(0 | 3 | 4) => return Ok(None), 6 | Ok(0x7f) => { buf.pop(); } 7 | Ok(b'\n' | b'\r') => break, 8 | Ok(c) => buf.push(c), 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/FuncForwardDeclaration.c: -------------------------------------------------------------------------------- 1 | /* 2 | Func call with various arg numbers. 3 | And func forward declarations. 4 | */ 5 | 6 | void aX(void); 7 | int a1(int param1); 8 | int a2(int param1, param2); 9 | void a3(); 10 | void a3(void); 11 | 12 | int f(int arg1, char arg2) 13 | { 14 | a1(arg1); 15 | a2(arg1, arg2); 16 | a3(); 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/History/HistoryDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.History 7 | { 8 | public class HistoryDto 9 | { 10 | public List Events { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/History/IHistoryService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.History 7 | { 8 | public interface IHistoryService 9 | { 10 | HistoryDto GetHistory(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Domain/Handle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.Helpers.Domain 7 | { 8 | public interface Handles 9 | where T : DomainEvent 10 | { 11 | void Handle(T args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-domain/src/test/kotlin/chapi/domain/core/CodeFieldTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class CodeFieldTest { 7 | 8 | @Test 9 | fun testEquals() { 10 | assertEquals(CodeField(TypeType = "type"), CodeField(TypeType = "type")) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /scripts/compile-typescript.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd grammars/typescript 4 | 5 | antlr -Dlanguage=Java -listener -visitor TypeScriptLexer.g4 -o ../../chapi-ast-typescript/src/main/java/chapi/ast/antlr -package chapi.ast.antlr 6 | antlr -Dlanguage=Java -listener -visitor TypeScriptParser.g4 -o ../../chapi-ast-typescript/src/main/java/chapi/ast/antlr -package chapi.ast.antlr 7 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/Models/ResponseOfTReturn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace eCommerce.WebService.Models 7 | { 8 | public sealed class Response : Response 9 | { 10 | public TReturn Object { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Products/ReturnReason.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.DomainModelLayer.Products 7 | { 8 | public enum ReturnReason 9 | { 10 | Faulty, 11 | NoReason 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/main/java/chapi/ast/antlr/RustParserBase.java: -------------------------------------------------------------------------------- 1 | package chapi.ast.antlr; 2 | import org.antlr.v4.runtime.*; 3 | 4 | public abstract class RustParserBase extends Parser { 5 | public RustParserBase(TokenStream input){ 6 | super(input); 7 | } 8 | 9 | public boolean next(char expect){ 10 | return _input.LA(1) == expect; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Repository/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.Helpers.Repository 7 | { 8 | public interface IUnitOfWork : IDisposable 9 | { 10 | void Commit(); 11 | void Rollback(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/maps.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | type Vertex2 struct { 6 | Lat, Long float64 7 | } 8 | 9 | var s map[int]string 10 | var m map[string]Vertex2 11 | 12 | func Maps() { 13 | m = make(map[string]Vertex2) 14 | m["Bell Labs"] = Vertex2{ 15 | 40.68433, -74.39967, 16 | } 17 | s[1] ="test" 18 | fmt.Println(m["Bell Labs"]) 19 | } -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/ParameterOfPointerType.c: -------------------------------------------------------------------------------- 1 | //parameter contains pointer 2 | int 3 | __cdecl 4 | f1 ( 5 | const MyType *param1, 6 | int param2 7 | ); 8 | 9 | 10 | MyType1 11 | __cdecl 12 | f1 ( 13 | MyType *param1, 14 | int * param2 15 | ); 16 | 17 | 18 | void 19 | __cdecl 20 | f1 ( 21 | void *param1 22 | ); -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/Models/Response.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace eCommerce.WebService.Models 7 | { 8 | public class Response 9 | { 10 | public bool Errored { get; set; } 11 | public string ErrorMessage { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /chapi-ast-python/src/main/java/chapi/ast/antlr/PythonVersion.java: -------------------------------------------------------------------------------- 1 | package chapi.ast.antlr; 2 | 3 | public enum PythonVersion { 4 | Autodetect(0), 5 | Python2(2), 6 | Python3(3); 7 | 8 | private final int value; 9 | 10 | PythonVersion(int value) { 11 | this.value = value; 12 | } 13 | 14 | public int getValue() { 15 | return value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/test.py: -------------------------------------------------------------------------------- 1 | # test 2 | # : logical_test (IF logical_test ELSE test)? 3 | # | LAMBDA varargslist? COLON test 4 | # ; 5 | 6 | # logical_test 7 | x == y 8 | 9 | # logical_test IF logical_test ELSE test 10 | x == y if z == b else a == u 11 | 12 | # LAMBDA COLON test 13 | lambda: a 14 | 15 | # LAMBDA varargslist COLON test 16 | lambda x, y: a 17 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeDependency.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodeDependency( 7 | var GroupId: String = "", 8 | var ArtifactId: String = "", 9 | var Scope: String = "", 10 | var Type: String = "", 11 | var Version: String = "", 12 | var Optional: Boolean = false 13 | ) 14 | -------------------------------------------------------------------------------- /chapi-domain/src/test/kotlin/chapi/domain/core/CodePackageInfoTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | import org.junit.jupiter.api.Assertions.* 6 | 7 | internal class CodePackageInfoTest { 8 | 9 | @Test 10 | fun getterSetter() { 11 | val pkgInfo = CodePackageInfo("project") 12 | assertEquals(pkgInfo.ProjectName, "project") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/Main.java: -------------------------------------------------------------------------------- 1 | import domain.*; 2 | import gateways.*; 3 | import repositories.*; 4 | 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | System.out.println("main"); 10 | Router router = new FakeRouter(); 11 | AggregateRootARepo repo = new AggregateRootARepo(); 12 | repo.save(new AggregateRootA(router)); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Services/ProductState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.DomainModelLayer.Products 7 | { 8 | public enum ProductState 9 | 10 | { 11 | OK = 200, 12 | NotInStock = 201, 13 | IsFaulty = 202 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace eCommerce.WebService 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Carts/CartProductDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.Carts 7 | { 8 | public class CartProductDto 9 | { 10 | public Guid ProductId { get; set; } 11 | public int Quantity { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/simple_stmt.py: -------------------------------------------------------------------------------- 1 | # simple_stmt: small_stmt (SEMI_COLON small_stmt)* SEMI_COLON? (NEWLINE | EOF) 2 | 3 | # small_stmt NEWLINE 4 | x = 5 5 | 6 | # small_stmt SEMI_COLON small_stmt NEWLINE 7 | x = 5 ; y = 7 8 | 9 | # small_stmt SEMI_COLON NEWLINE 10 | x = 5 ; 11 | 12 | # small_stmt SEMI_COLON small_stmt SEMI_COLON small_stmt SEMI_COLON small_stmt SEMI_COLON EOF 13 | x = 5 ; y = 7 ; z = 9 ; -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Services/PaymentStatus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.DomainModelLayer.Services 7 | { 8 | public enum PaymentStatus 9 | { 10 | OK = 100, 11 | UnpaidBalance = 101, 12 | NoActiveCreditCardAvailable = 102 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /chapi-ast-kotlin/src/main/kotlin/chapi/ast/kotlinast/KotlinAstListener.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.kotlinast 2 | 3 | import chapi.ast.antlr.KotlinParserBaseListener 4 | import chapi.domain.core.CodeContainer 5 | 6 | // the base listener for the Kotlin parser, implement common methods and expose the output interface 7 | abstract class KotlinAstListener : KotlinParserBaseListener() { 8 | abstract fun getNodeInfo(): CodeContainer 9 | } 10 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Email/IEmailGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Mail; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Email 8 | { 9 | public interface IEmailGenerator 10 | { 11 | MailMessage Generate(object objHolder, EmailTemplate emailTemplate); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/def_parameters.py: -------------------------------------------------------------------------------- 1 | # def_parameters: def_parameter (COMMA def_parameter)*; 2 | # def_parameter: named_parameter (ASSIGN test)?; 3 | # named_parameter: NAME (COLON test)?; 4 | 5 | # NAME COLON test 6 | def single_typed(x: int): pass 7 | 8 | # NAME COLON test ASSIGN test 9 | def single_default_typed(x: int = 4): pass 10 | 11 | # NAME COMMA NAME ASSIGN test 12 | def second_default(x, y = 4): pass 13 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/funcdef.py: -------------------------------------------------------------------------------- 1 | # funcdef: ASYNC? DEF name OPEN_PAREN typedargslist? CLOSE_PAREN (ARROW test)? COLON suite 2 | 3 | # DEF NAME OPEN_PAREN CLOSE_PAREN COLON suite 4 | def foo(): pass 5 | 6 | # ASYNC DEF NAME OPEN_PAREN typedargslist? CLOSE_PAREN COLON suite 7 | async def bar(one): pass 8 | 9 | # DEF NAME OPEN_PAREN typedargslist? CLOSE_PAREN ARROW test COLON suite 10 | def baz(one, two) -> int: pass 11 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodePosition.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | // position need to remove in functions, if one function change, others position will also change 6 | @Serializable 7 | data class CodePosition( 8 | var StartLine: Int = 0, 9 | var StartLinePosition: Int = 0, 10 | var StopLine: Int = 0, 11 | var StopLinePosition: Int = 0 12 | ) 13 | -------------------------------------------------------------------------------- /_fixtures/ast/java/arch/domain/AggregateRootA.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | 4 | public class AggregateRootA extends AggregateRoot { 5 | 6 | private EntityB entity_b; 7 | private ValueObjectC vo_c; 8 | private Router router; 9 | private AggregateRootB b; 10 | 11 | public AggregateRootA(Router router) { 12 | this.router = router; 13 | } 14 | public void init() { 15 | router.select(); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Newsletter/INewsletterSubscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Customers; 6 | 7 | namespace eCommerce.DomainModelLayer.Newsletter 8 | { 9 | public interface INewsletterSubscriber 10 | { 11 | void Subscribe(Customer customer); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/shortVarDecl.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | import "os" 5 | 6 | func ShortVarDecls() { 7 | a, b := 0, 10 8 | c := func() int { return 7 } 9 | d := make(chan int) 10 | e, f, _ := os.Pipe() // os.Pipe() returns a connected pair of Files and an error, if any 11 | // _, y, _ := coord(p) // coord() returns three values; only interested in y coordinate 12 | fmt.Println(a, b, c, d, e, f) 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/FuncCallAsFuncArgument.c: -------------------------------------------------------------------------------- 1 | /* 2 | Func call with various arg numbers. 3 | And func forward declarations. 4 | And func call as func call argument. 5 | */ 6 | 7 | void aX(void); 8 | int a1(int param1); 9 | int a2(int param1, param2); 10 | void a3(); 11 | void a3(void); 12 | 13 | int f(int arg1, char arg2) 14 | { 15 | a1(arg1); 16 | a2(arg1, arg2); 17 | a3(); 18 | a1(a1()); 19 | a1(a1(), a2(a1(), x1)); 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Email/IEmailDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Customers; 6 | using System.Net.Mail; 7 | 8 | namespace eCommerce.DomainModelLayer.Email 9 | { 10 | public interface IEmailDispatcher 11 | { 12 | void Dispatch(MailMessage mailMessage); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/strings.go: -------------------------------------------------------------------------------- 1 | // Verifies raw and interpreted string parsing (see issue #1131). 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | type Vertex struct { 9 | X float64 `"X" Description` /* X Comment */ 10 | Y float64 "`Y` Description" // Y Comment 11 | } 12 | 13 | func main() { 14 | fmt.Println("this \"that") 15 | fmt.Println(`Hello`) 16 | } 17 | 18 | type Something struct { 19 | Msg string `World` 20 | } 21 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Module.ts: -------------------------------------------------------------------------------- 1 | export let age : number = 20; 2 | export class Employee { 3 | empCode: number; 4 | empName: string; 5 | constructor(name: string, code: number) { 6 | this.empName = name; 7 | this.empCode = code; 8 | } 9 | displayEmployee() { 10 | console.log ("Employee Code: " + this.empCode + ", Employee Name: " + this.empName ); 11 | } 12 | } 13 | let companyName:string = "XYZ"; -------------------------------------------------------------------------------- /chapi-domain/src/test/kotlin/chapi/domain/core/CodePropertyTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import org.junit.jupiter.api.Assertions.* 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class CodePropertyTest { 7 | @Test 8 | fun testEquals() { 9 | assertEquals( 10 | CodeProperty(TypeType = "type", TypeValue = "value"), 11 | CodeProperty(TypeType = "type", TypeValue = "value") 12 | ) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Specification/ISpecification.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace eCommerce.Helpers.Specification 8 | { 9 | public interface ISpecification 10 | { 11 | Expression> SpecExpression { get; } 12 | bool IsSatisfiedBy(T obj); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeImport.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodeImport( 7 | var Source: String = "", 8 | /// todo: define for new usage 9 | var AsName: String = "", 10 | // import UsageName from 'usage' 11 | // import AsSource as UsageName from 'source' 12 | var UsageName: List = listOf(), 13 | var Scope: String = "" 14 | ) 15 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Products/IProductService.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.DomainModelLayer.Products; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.ApplicationLayer.Products 8 | { 9 | public interface IProductService 10 | { 11 | ProductDto Get(Guid productId); 12 | ProductDto Add(ProductDto product); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/for_stmt.py: -------------------------------------------------------------------------------- 1 | # for_stmt: ASYNC? FOR exprlist IN testlist COLON suite else_clause? 2 | 3 | # FOR exprlist IN testlist COLON suite 4 | for x in range(1): 5 | pass 6 | 7 | # FOR exprlist IN testlist COLON suite (else_clause)? 8 | for x in range(1): 9 | x 10 | else: 11 | pass 12 | 13 | # async_stmt must be inside async function 14 | async def f(): 15 | # ASYNC for_stmt 16 | async for _ in range(5): 17 | pass 18 | -------------------------------------------------------------------------------- /chapi-ast-scala/src/test/resources/grammar/string.scala: -------------------------------------------------------------------------------- 1 | package uuu.vvv.www.xxx.yyy.zzzz 2 | import java.math.BigDecimal 3 | import org.apache.spark.sql.hive.HiveContext 4 | 5 | object CreateTable extends CreateTableInterface { 6 | val a = 7 | """ 8 | Test 9 | Test 10 | """ 11 | val b = 12 | """ 13 | |Test 14 | |Test 15 | |""".stripMargin 16 | def execute (hiveContext: HiveContext) = { 17 | hiveContext.sql("""asd""") 18 | } 19 | } -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/DomainConstants.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain 2 | 3 | public class DomainConstants { 4 | companion object { 5 | val ASSERTION_LIST = arrayOf( 6 | "assert", 7 | "should", 8 | "check", // ArchUnit, 9 | "maynotbe", // ArchUnit, 10 | "is", // RestAssured, 11 | "spec", // RestAssured, 12 | "verify" // Mockito, 13 | ) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/App_Start/MappingConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using AutoMapper; 6 | 7 | namespace eCommerce.WebService.App_Start 8 | { 9 | public class MappingConfig 10 | { 11 | public static void RegisterMapping() 12 | { 13 | Mapper.AddProfile(new eCommerce.ApplicationLayer.Map()); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/promoted.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | type Foo1 func(x int) int 9 | 10 | type Foo2 func(x int) int 11 | 12 | type Request struct{} 13 | 14 | // T is a custom type 15 | type T2 struct { 16 | http.Request // field name is "Request" 17 | age int32 18 | } 19 | 20 | func Types() { 21 | // person := T{name: "Michael", age: 29} 22 | // fmt.Println(person) 23 | fmt.Println("123") 24 | } 25 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Carts/CheckOutIssue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.DomainModelLayer.Carts 7 | { 8 | public enum CheckOutIssue 9 | { 10 | UnpaidBalance = 101, 11 | NoActiveCreditCardAvailable = 102, 12 | ProductNotInStock = 201, 13 | ProductIsFaulty = 202, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/argument.py: -------------------------------------------------------------------------------- 1 | # argument 2 | # : test (comp_for | ASSIGN test)? 3 | # | (POWER | STAR) test 4 | # ; 5 | 6 | # test 7 | b(x) 8 | 9 | # test comp_for 10 | b(x for x in a) 11 | 12 | # test ASSIGN test 13 | b(x=i) 14 | 15 | # test COMMA test ASSIGN test COMMA test ASSIGN test 16 | b(z, x=i, y=u) 17 | 18 | # POWER test 19 | b(**z) 20 | 21 | # STAR test 22 | b(*z) 23 | 24 | # test COMMA STAR test COMMA test ASSIGN test 25 | b(y, *z, x=i) 26 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/with_stmt.py: -------------------------------------------------------------------------------- 1 | # with_stmt: ASYNC? WITH with_item (COMMA with_item)* COLON suite 2 | 3 | # WITH with_item COLON suite 4 | with open("with_stmt.py"): 5 | pass 6 | 7 | # WITH with_item COMMA with_item COLON suite 8 | with open("with_stmt.py") as a, open("with_stmt.py") as b: 9 | pass 10 | 11 | # async_stmt must be inside async function 12 | async def f(): 13 | # ASYNC with_stmt 14 | async with open("with_stmt.py") as f: 15 | pass 16 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/switchesType.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | type O struct { 6 | 7 | } 8 | 9 | func (O) typee() {} 10 | 11 | func TypeSwitch(i interface{}) { 12 | switch v := i.(type) { 13 | case int: 14 | fmt.Printf("Twice %v is %v\n", v, v*2) 15 | case string: 16 | fmt.Printf("%q is %v bytes long\n", v, len(v)) 17 | case byte, uintptr: 18 | fmt.Printf("Type i %T", v) 19 | default: 20 | fmt.Printf("I don't know about type %T!\n", v) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | exclude_patterns: 3 | - "**/src/main/java/chapi/ast/antlr/" 4 | - "**/resources/**" 5 | - "tests/" 6 | # 7 | #checks: 8 | # identical-code: 9 | # config: 10 | # threshold: 25 11 | # similar-code: 12 | # config: 13 | # threshold: 50 14 | 15 | plugins: 16 | duplication: 17 | enabled: true 18 | config: 19 | languages: 20 | kotlin: 21 | exclude_patterns: 22 | - "**/*Analyser.kt" 23 | - "**/*Test.kt" 24 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/FuncCallwithVarArgs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Func call with various arg numbers. 3 | And func forward declarations. 4 | And func call as func call argument. 5 | */ 6 | 7 | void aX(void); 8 | int a1(int param1); 9 | int a2(int param1, param2); 10 | void a3(); 11 | void a3(void); 12 | void a4(int, ...); 13 | void a4(int param1, ...); 14 | 15 | 16 | int f(int arg1, char arg2) 17 | { 18 | a1(arg1); 19 | a2(arg1, arg2); 20 | a3(); 21 | a1(a1()); 22 | a1(a1(), a2(a1(), x1)); 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Customers/CreditCardDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.Customers 7 | { 8 | public class CreditCardDto 9 | { 10 | public Guid Id { get; set; } 11 | public string NameOnCard { get; set; } 12 | public string CardNumber { get; set; } 13 | public DateTime Expiry { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Repository/IDomainEventRepository.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.Helpers.Repository 8 | { 9 | public interface IDomainEventRepository 10 | { 11 | void Add(TDomainEvent domainEvent) where TDomainEvent : DomainEvent; 12 | IEnumerable FindAll(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/if_stmt.py: -------------------------------------------------------------------------------- 1 | # if_stmt: IF cond=test COLON suite elif_clause* else_clause? 2 | 3 | # IF test COLON suite 4 | if x == 5: pass 5 | 6 | # IF test COLON suite elif_clause 7 | if x == 4: 8 | pass 9 | elif x == 3: 10 | pass 11 | 12 | # IF test COLON suite else_clause 13 | if x == 7: 14 | pass 15 | else: 16 | pass 17 | 18 | # IF test COLON suite elif_clause elif_clause else_clause 19 | if x == 4: 20 | pass 21 | elif x == 3: 22 | pass 23 | else: 24 | pass 25 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Carts/CartDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.Carts 7 | { 8 | public class CartDto 9 | { 10 | public Guid CustomerId { get; set; } 11 | public List Products { get; set; } 12 | public DateTime Created { get; set; } 13 | public DateTime Modified { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodePackage.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | import kotlinx.serialization.json.JsonElement 5 | import kotlinx.serialization.json.JsonObject 6 | 7 | @Serializable 8 | data class CodePackage( 9 | var Name: String = "", 10 | var ID: String = "", 11 | var codeContainers: List = listOf(), 12 | var Packages : List = listOf(), 13 | var Extension: JsonElement = JsonObject(HashMap()) 14 | ) 15 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/typedargslist.py: -------------------------------------------------------------------------------- 1 | # typedargslist 2 | # : (def_parameters COMMA)? (args (COMMA def_parameters)? (COMMA kwargs)? | kwargs) 3 | # | def_parameters 4 | # ; 5 | 6 | # def_parameters COMMA 7 | def single(x, *, i): pass 8 | 9 | # def_parameters COMMA kwargs 10 | def f1(x, y, **z): pass 11 | 12 | # def_parameters COMMA args COMMA def_parameters COMMA kwargs COMMA 13 | def f1(x, y, *z: int, a, b, **c: int,): pass 14 | 15 | # def_parameters COMMA args 16 | def f1(x, y, *z): pass 17 | 18 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/History/EventDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.History 7 | { 8 | public class EventDto 9 | { 10 | public string Type { get; set; } 11 | public Dictionary Args { get; set; } 12 | public DateTime Created { get; set; } 13 | 14 | public string CorrelationID { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Domain/DomainEventRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.Helpers.Domain 7 | { 8 | public class DomainEventRecord 9 | { 10 | public string Type { get; set; } 11 | public List> Args { get; set; } 12 | public string CorrelationID { get; set; } 13 | public DateTime Created { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/InfrastructureLayer/SmtpEmailDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Email; 6 | using System.Net.Mail; 7 | 8 | namespace eCommerce.InfrastructureLayer 9 | { 10 | public class SmtpEmailDispatcher : IEmailDispatcher 11 | { 12 | public void Dispatch(MailMessage mailMessage) 13 | { 14 | //send an email here... 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /chapi-helper/src/test/kotlin/chapi/ast/helper/TreeViewerTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.helper 2 | 3 | import chapi.ast.javaast.JavaAnalyser 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class TreeViewerTest { 7 | @Test 8 | fun show() { 9 | val javaAnalyser = JavaAnalyser() 10 | javaAnalyser.parse("public class Test { }").let { 11 | val ruleNamesList: List = it.ruleNames.toList() 12 | println(TreeViewer().toPrettyTree(it.compilationUnit(), ruleNamesList)) 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/ICustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Repository; 2 | using eCommerce.Helpers.Specification; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace eCommerce.DomainModelLayer.Customers 9 | { 10 | public interface ICustomerRepository : IRepository 11 | { 12 | IEnumerable GetCustomersPurchaseHistory(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Customers/CustomerDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.Customers 7 | { 8 | public class CustomerDto 9 | { 10 | public Guid Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Email { get; set; } 14 | public Guid CountryId { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/ll.c: -------------------------------------------------------------------------------- 1 | 2 | struct list_el { 3 | int val; 4 | struct list_el * next; 5 | }; 6 | 7 | typedef struct list_el item; 8 | 9 | void main() { 10 | item * curr, * head; 11 | int i; 12 | 13 | head = NULL; 14 | 15 | for(i=1;i<=10;i++) { 16 | curr = (item *)malloc(sizeof(item)); 17 | curr->val = i; 18 | curr->next = head; 19 | head = curr; 20 | } 21 | 22 | curr = head; 23 | 24 | while(curr) { 25 | printf("%d\n", curr->val); 26 | curr = curr->next ; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/call/builder_pattern_call.py: -------------------------------------------------------------------------------- 1 | ## https://stackoverflow.com/questions/17321167/calling-chains-methods-with-intermediate-results 2 | 3 | class Person: 4 | def setName(self, name): 5 | self.name = name 6 | return self ## this is what makes this work 7 | 8 | def setAge(self, age): 9 | self.age = age; 10 | return self; 11 | 12 | def setSSN(self, ssn): 13 | self.ssn = ssn 14 | return self 15 | 16 | 17 | p = Person() 18 | p.setName("Hunter").setAge(24).setSSN("111-22-3333") 19 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Export.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace StringUtility 5 | { 6 | function ToCapital(str: string): string { 7 | return str.toUpperCase(); 8 | } 9 | 10 | function Nemw(str: string, length: number = 0): string { 11 | return str.toUpperCase(); 12 | } 13 | export function Eported(from: string, length: number = 0): string { 14 | return from.toUpperCase(); 15 | } 16 | 17 | export function Eported2(str: string, length: number = 0): string { 18 | return str.toUpperCase(); 19 | } 20 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Carts/ICartService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Carts; 6 | 7 | namespace eCommerce.ApplicationLayer.Carts 8 | { 9 | public interface ICartService 10 | { 11 | CartDto Add(Guid customerId, CartProductDto cartProductDto); 12 | CartDto Remove(Guid customerId, Guid productId); 13 | CartDto Get(Guid customerId); 14 | CheckOutResultDto CheckOut(Guid customerId); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/InfrastructureLayer/WSNewsletterSubscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Newsletter; 6 | using eCommerce.DomainModelLayer.Customers; 7 | 8 | namespace eCommerce.InfrastructureLayer 9 | { 10 | public class WSNewsletterSubscriber : INewsletterSubscriber 11 | { 12 | public void Subscribe(Customer customer) 13 | { 14 | //call a third party web service here... 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/chan.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func Ch() { 9 | var ball = make(chan string) 10 | kickBall := func(playerName string) { 11 | for { 12 | fmt.Println(<-ball, "kicked the ball.") 13 | time.Sleep(time.Second) 14 | ball <- playerName 15 | } 16 | } 17 | go kickBall("John") 18 | go kickBall("Alice") 19 | go kickBall("Bob") 20 | go kickBall("Emily") 21 | time.Sleep(time.Second * 2) 22 | ball <- "referee" // kick off 23 | 24 | var c chan bool // nil 25 | <-c // blocking here for ever 26 | } 27 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/infra/Stack.kt: -------------------------------------------------------------------------------- 1 | package chapi.infra 2 | 3 | class Stack { 4 | val elements: MutableList = mutableListOf() 5 | fun isEmpty() = elements.isEmpty() 6 | fun count() = elements.size 7 | fun push(item: T) = elements.add(item) 8 | fun pop(): T? { 9 | val item = elements.lastOrNull() 10 | if (!isEmpty()) { 11 | elements.removeAt(elements.size - 1) 12 | } 13 | return item 14 | } 15 | 16 | fun peek(): T? = elements.lastOrNull() 17 | 18 | override fun toString(): String = elements.toString() 19 | } 20 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/dialog.c: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | /* Define default values: */ 4 | 5 | int n = 0; 6 | float x = 0.0; 7 | 8 | /* Define contents of dialog window */ 9 | 10 | create_int_dialog_entry("n", &n); 11 | create_float_dialog_entry("x", &x); 12 | 13 | /* Create window with name "Setup" and top-left corner at (0,0) */ 14 | 15 | set_up_dialog("Setup", 0, 0); 16 | 17 | /* Display the window and read the results */ 18 | 19 | read_dialog_window(); 20 | 21 | /* Print out the new values */ 22 | 23 | printf("n = %d, x = %f\n", n, x); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Carts/CartCreated.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Carts 8 | { 9 | public class CartCreated : DomainEvent 10 | { 11 | public Cart Cart { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("CustomerId", this.Cart.CustomerId); 16 | this.Args.Add("CartId", this.Cart.Id); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/GenericInterface.ts: -------------------------------------------------------------------------------- 1 | interface IProcessor 2 | { 3 | result:T; 4 | process(a: T, b: T) => T; 5 | } 6 | 7 | interface KeyPair { 8 | key: T; 9 | value: U; 10 | } 11 | 12 | let kv1: KeyPair = { key:1, value:"Steve" }; // OK 13 | let kv2: KeyPair = { key:1, value:12345 }; // OK 14 | 15 | interface KeyValueProcessor 16 | { 17 | (key: T, val: U): void; 18 | }; 19 | 20 | function processNumKeyPairs(key:number, value:number):void { 21 | console.log('processNumKeyPairs: key = ' + key + ', value = ' + value) 22 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/InfrastructureLayer/StubEmailGenerator.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.DomainModelLayer.Email; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Net.Mail; 7 | 8 | namespace eCommerce.InfrastructureLayer 9 | { 10 | public class StubEmailGenerator : IEmailGenerator 11 | { 12 | public MailMessage Generate(object objHolder, EmailTemplate emailTemplate) 13 | { 14 | //Generate your email here 15 | return new MailMessage(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/arrayDecls.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func ArrayDecls() { 8 | /*[32]byte 9 | [2*N] struct { x, y int32 } 10 | [1000]*float64 11 | [3][5]int 12 | [2][2][2]float64 // same as [2]([2]([2]float64)) 13 | */ 14 | var a [2]string 15 | a[0] = "Hello" 16 | a[1] = "World" 17 | fmt.Println(a[0], a[1]) 18 | 19 | primes := [6]int{2, 3, 5, 7, 11, 13} 20 | fmt.Println(primes) 21 | 22 | var twoD [2][4]int 23 | for i := 0; i < 2; i++ { 24 | for j := 0; j < 3; j++ { 25 | twoD[i][j] = i + j 26 | } 27 | } 28 | fmt.Println("2d: ", twoD) 29 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Countries/CountryCreated.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Countries 8 | { 9 | public class CountryCreated : DomainEvent 10 | { 11 | public Country Country { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("Id", this.Country.Id); 16 | this.Args.Add("Name", this.Country.Name); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /chapi-ast-scala/src/test/resources/dsl/Story.scala: -------------------------------------------------------------------------------- 1 | // https://gist.github.com/nicerobot/4189552 2 | object Story { 3 | object Once { def upon = (x: a.type) => x } 4 | object a { def time = (x: languages.type) => x } 5 | object languages { def were = (x: inflexible.type) => x } 6 | object inflexible { def along = (x: came.type) => x } 7 | object came { def Scala = (x: inflexible.type) => x } 8 | implicit def string(s : String) : inflexible.type = inflexible 9 | 10 | def main(args: Array[String]): Unit = { 11 | Once upon a time languages were inflexible; "Then " along came Scala ". The End!" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/comprehension.py: -------------------------------------------------------------------------------- 1 | # comp_for 2 | # : FOR exprlist IN logical_test comp_iter? 3 | # ; 4 | # 5 | # comp_iter 6 | # : comp_for 7 | # | IF test comp_iter? 8 | # ; 9 | 10 | # FOR exprlist IN logical_test 11 | [x for x in a] 12 | 13 | # FOR exprlist IN logical_test comp_for 14 | [x for x in a for a in k] 15 | 16 | # FOR exprlist IN logical_test IF test 17 | [x for x in a if x == 1] 18 | 19 | # FOR exprlist IN logical_test IF test IF test 20 | [x for x in a if x == 1 if x != 9] 21 | 22 | # FOR exprlist IN logical_test IF test comp_for 23 | [x for x in a if x == 1 for a in q] 24 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/subscript.py: -------------------------------------------------------------------------------- 1 | # subscript 2 | # : ELLIPSIS 3 | # | test 4 | # | test? COLON test? sliceop? 5 | # ; 6 | # 7 | # sliceop 8 | # : COLON test? 9 | # ; 10 | 11 | # ELLIPSIS 12 | b[...] 13 | 14 | # test 15 | b[a] 16 | 17 | # COLON 18 | b[:] 19 | 20 | # test COLON 21 | b[a:] 22 | 23 | # COLON test 24 | b[:a] 25 | 26 | # test COLON test 27 | b[a:a] 28 | 29 | # COLON COLON 30 | b[::] 31 | 32 | # COLON COLON test 33 | b[::-1] 34 | 35 | # test COLON COLON test 36 | b[a::2] 37 | 38 | # COLON test COLON test 39 | b[:a:2] 40 | 41 | # test COLON test COLON test 42 | b[1:a:2] 43 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/hardcodedPassword.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | type HpType struct { 6 | } 7 | 8 | func (c HpType) HP() { 9 | password := `hardcoded` 10 | // var password = "hardcoded" 11 | fmt.Printf("Hello, world\nYou type the password=%v\n", password) 12 | letters := []string{"a", "b", "c", "d"} 13 | // shadowing previous same decl 14 | // var letters []string 15 | //letters = make([]string, 4, 10) 16 | // letters[3] = "e" 17 | p := make([]string, 10) 18 | p = append(letters, "e", "f") 19 | fmt.Println(letters, len(letters), cap(letters)) 20 | fmt.Println(p, len(p), cap(p)) 21 | } 22 | -------------------------------------------------------------------------------- /chapi-domain/src/test/kotlin/chapi/domain/core/CodeProjectTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | import org.junit.jupiter.api.Assertions.* 6 | 7 | internal class CodeProjectTest { 8 | @Test 9 | internal fun shouldCreateProject() { 10 | val pkg = CodePackage( 11 | ID = "com.phodal", 12 | Name = "domain" 13 | ) 14 | val codeModule = CodeModule() 15 | codeModule.Packages += pkg 16 | val project = CodeProject() 17 | project.Modules += codeModule 18 | 19 | assertEquals(project.Modules.size, 1) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/try_stmt.py: -------------------------------------------------------------------------------- 1 | # try_stmt: TRY COLON suite (except_clause+ else_clause? finaly_clause? | finaly_clause) 2 | 3 | # TRY COLON suite except_clause 4 | try: 5 | pass 6 | except: 7 | pass 8 | 9 | # TRY COLON suite except_clause except_clause else_clause 10 | try: 11 | pass 12 | except Exception as ex: 13 | pass 14 | except: 15 | pass 16 | else: 17 | pass 18 | 19 | # TRY COLON suite except_clause finaly_clause 20 | try: 21 | pass 22 | except Exception: 23 | pass 24 | finally: 25 | pass 26 | 27 | # TRY COLON suite finaly_clause 28 | try: 29 | pass 30 | finally: 31 | pass 32 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Settings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Countries; 6 | 7 | namespace eCommerce.DomainModelLayer 8 | { 9 | public class Settings 10 | { 11 | public virtual Country BusinessCountry { get; protected set; } 12 | 13 | public Settings() 14 | { 15 | 16 | } 17 | 18 | public Settings(Country businessCountry) 19 | { 20 | this.BusinessCountry = businessCountry; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/InfrastructureLayer/MemoryUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Repository; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.InfrastructureLayer 8 | { 9 | public class MemoryUnitOfWork : IUnitOfWork 10 | { 11 | public void Commit() 12 | { 13 | //commit 14 | } 15 | 16 | public void Rollback() 17 | { 18 | //rollback 19 | } 20 | 21 | public void Dispose() 22 | { 23 | //dispose 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/test/resources/grammar/v1_46_0_split_float_literal.rs.tree: -------------------------------------------------------------------------------- 1 | (crate (item (visItem (function_ functionQualifiers fn (identifier main) ( ) (blockExpression { (statements (statement (letStatement let (patternNoTopAlt (patternWithoutRange (identifierPattern (identifier a)))) = (expression (expression (expression (expression (expression (pathExpression (pathInExpression (pathExprSegment (pathIdentSegment (identifier b)))))) . (tupleIndex 1)) . (tupleIndex 2)) . (tupleIndex 3)) . (tupleIndex 4)) ;)) (statement (letStatement let (patternNoTopAlt (patternWithoutRange (identifierPattern (identifier c)))) = (expression (literalExpression 1.2345)) ;))) })))) ) -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Products/ProductCodeCreated.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Products 8 | { 9 | public class ProductCodeCreated : DomainEvent 10 | { 11 | public ProductCode ProductCode { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("ProductCodeId", this.ProductCode.Id); 16 | this.Args.Add("ProductCodeName", this.ProductCode.Name); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerChangedEmail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Domain; 6 | 7 | namespace eCommerce.DomainModelLayer.Customers 8 | { 9 | public class CustomerChangedEmail : DomainEvent 10 | { 11 | public Customer Customer { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("CustomerId", this.Customer.Id); 16 | this.Args.Add("Email", this.Customer.Email); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/varDecl.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | var entries map[string]int 6 | 7 | func multiRet() (int, int) { 8 | return 1, 2 9 | } 10 | 11 | func VarDecls() { 12 | var a int // + 13 | var b, c float64 // + strange extra levels 14 | var d = 1 // + doesn't show zero value 15 | var e, f float32 = -1, -2 // + 16 | var ( 17 | g int 18 | h, i, j = 2.0, 3.0, "bar" 19 | ) // + need to precise general text span 20 | // var _, k = entries["1"] // map lookup; 21 | var l, m = multiRet() // + TODO: Figure out with duplication 22 | fmt.Println(a, b, c, d, e, f, g, h, i, j, /*k,*/ l, m) 23 | } 24 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | insert_final_newline = true 6 | 7 | [*.{kt, groovy}] 8 | indent_style = space 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | indent_style = space 16 | indent_size = 4 17 | 18 | [*.{kt,kts}] 19 | # possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely) 20 | indent_size=4 21 | # true (recommended) / false 22 | insert_final_newline=true 23 | # possible values: number (e.g. 120) (package name, imports & comments are ignored), "off" 24 | # it's automatically set to 100 on `ktlint --android ...` (per Android Kotlin Style Guide) 25 | max_line_length=off 26 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Repository/IRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Domain; 6 | using eCommerce.Helpers.Specification; 7 | 8 | namespace eCommerce.Helpers.Repository 9 | { 10 | public interface IRepository 11 | where TEntity : IAggregateRoot 12 | { 13 | TEntity FindById(Guid id); 14 | TEntity FindOne(ISpecification spec); 15 | IEnumerable Find(ISpecification spec); 16 | void Add(TEntity entity); 17 | void Remove(TEntity entity); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/tokens.py: -------------------------------------------------------------------------------- 1 | DECIMAL = 0000000000 2 | DECIMAL = 1234567890 3 | OCT_1 = 0o01234567 4 | OCT_2 = 0O01234567 5 | HEX_1 = 0x0123456789abcdef 6 | HEX_2 = 0X0123456789ABCDEF 7 | BIN_1 = 0b01 8 | BIN_1 = 0B01 9 | IMAG_1 = 0123456789.0123456789j 10 | IMAG_2 = 0123456789J 11 | FLOAT_1 = 0123456789.e1234567890 12 | FLOAT_2 = .0123456789E1234567890 13 | 14 | LINE_JOIN_EXPR = 2 + \ 15 | 2 16 | 17 | SHORT_STRING_1 = 'a \'\\ b' 18 | SHORT_STRING_2 = "a \"\\ b" 19 | LONG_STRING_1 = b""" asdf " qwer 20 | zxcv 21 | """ 22 | LONG_STRING_1 = r''' aasdf ' qwer 23 | zxcv 24 | ''' 25 | STRING_WITH_LINE_JOIND = "a \ 26 | b" 27 | 28 | # COMMENT 29 | 30 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "chapi" 2 | 3 | include( 4 | ":chapi-domain", 5 | ":chapi-helper", 6 | // tier 1 languages 7 | ":chapi-ast-java", 8 | ":chapi-ast-typescript", 9 | 10 | // tier 1 model language 11 | ":chapi-ast-protobuf", 12 | ":chapi-ast-thrift", 13 | 14 | // tier 2 languages 15 | ":chapi-ast-kotlin", 16 | ":chapi-ast-go", 17 | ":chapi-ast-python", 18 | ":chapi-ast-scala", 19 | 20 | // tier 3 languages 21 | ":chapi-ast-rust", 22 | ":chapi-ast-csharp", 23 | ":chapi-ast-c", 24 | ":chapi-ast-cpp", 25 | 26 | // others 27 | ":chapi-parser-toml", 28 | ":chapi-parser-cmake", 29 | ) 30 | 31 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/FunctionPointer.c: -------------------------------------------------------------------------------- 1 | //function pointer 2 | typedef 3 | void * 4 | (*f1)( 5 | const MyType *param1, 6 | long param2, 7 | void *param3, 8 | short param4 9 | ); 10 | 11 | 12 | typedef 13 | int 14 | (*f2)( 15 | const MyType *param1, 16 | long param2, 17 | char *param3, 18 | int param4 19 | ); 20 | 21 | 22 | typedef 23 | MyStruct 24 | ( *f3 ) ( 25 | const MyType *param1, 26 | double param2, 27 | float *param3, 28 | long param4 29 | ); -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/tequila/inheritance-tree-code/inheritance-tree.dot: -------------------------------------------------------------------------------- 1 | digraph g { 2 | node[style = filled, color = orange]; 3 | 4 | AggregateRootA[label="AggregateRootA\l", comment=AR, shape=box] 5 | AggregateRootB[label="AggregateRootB\l", comment=AR, shape=box] 6 | EntityB[label="EntityB\l", comment=E, shape=box] 7 | EntityC[label="EntityB\l", comment=E, shape=box] 8 | ValueObjectC[label="ValueObjectC\l", comment=VO, shape=box, color=lightblue] 9 | ValueObjectD[label="ValueObjectD\l", comment=VO, shape=box, color=lightblue] 10 | AggregateRootA -> EntityB 11 | AggregateRootA -> EntityC 12 | AggregateRootA -> ValueObjectC 13 | EntityB -> ValueObjectD 14 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/defers.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | "crypto/rsa" 6 | "crypto/rand" 7 | ) 8 | 9 | func DeferCallee() { 10 | fmt.Println("Called from the first defer!") 11 | } 12 | 13 | func DeferCallee2() { 14 | fmt.Println("Called from the second defer!") 15 | } 16 | 17 | func Defers() { 18 | pvk, err := rsa.GenerateKey(rand.Reader, 2048) 19 | defer DeferCallee() 20 | // switch the equal sign for the different number of executed defer invocations 21 | if extra := -1; err != nil { 22 | fmt.Println("Something went wrong", extra) 23 | } else { 24 | return 25 | } 26 | 27 | defer DeferCallee2() 28 | fmt.Printf("End\n", pvk.Size()) 29 | } 30 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/multiple_type_decl.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type ( 9 | Abser interface { 10 | Abs() float64 11 | } 12 | 13 | MyError struct { 14 | When time.Time 15 | What string 16 | } 17 | 18 | MyCustomError struct { 19 | Message string 20 | Abser 21 | MyError 22 | } 23 | ) 24 | 25 | // The following takes precedence over instance call to Abs() 26 | func (myErr *MyCustomError) Abs() float64 { 27 | return 0.0 28 | } 29 | 30 | func main() { 31 | a:= MyCustomError{"New One", nil, MyError{time.Now(), "Hello"}} 32 | a.Abs() 33 | a.Message = "New" 34 | fmt.Println("MyCustomError method = %v", a.Abs()) 35 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Carts/CheckOutResultDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Customers; 6 | using eCommerce.DomainModelLayer.Products; 7 | using eCommerce.DomainModelLayer.Carts; 8 | 9 | namespace eCommerce.ApplicationLayer.Carts 10 | { 11 | public class CheckOutResultDto 12 | { 13 | public Nullable PurchaseId { get; set; } 14 | public decimal TotalCost { get; set; } 15 | public decimal TotalTax { get; set; } 16 | public Nullable CheckOutIssue { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | .idea 25 | !.idea/icon.png 26 | !.idea/.name 27 | build 28 | .gradle 29 | *.iml 30 | !gradle-wrapper.jar 31 | **/gen 32 | **/out 33 | venv/ 34 | keystore.gradle 35 | local.properties 36 | chapi.json 37 | *.ipr 38 | *.iws 39 | output.json 40 | .DS_Store 41 | api.json 42 | nodes.json 43 | nohup.out 44 | *.tokens 45 | recording.jsonl 46 | 47 | -------------------------------------------------------------------------------- /chapi-ast-c/src/main/kotlin/chapi/ast/cast/CAstBaseListener.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.cast 2 | 3 | import chapi.ast.antlr.CParserBaseListener 4 | import chapi.domain.core.* 5 | import org.antlr.v4.runtime.ParserRuleContext 6 | 7 | open class CAstBaseListener : CParserBaseListener() { 8 | fun buildPosition(ctx: ParserRuleContext?): CodePosition { 9 | if (ctx == null) { 10 | return CodePosition() 11 | } 12 | 13 | return CodePosition( 14 | StartLine = ctx.start.line, 15 | StartLinePosition = ctx.start.charPositionInLine, 16 | StopLine = ctx.stop.line, 17 | StopLinePosition = ctx.stop.charPositionInLine 18 | ) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Products/Return.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.DomainModelLayer.Customers; 6 | 7 | namespace eCommerce.DomainModelLayer.Products 8 | { 9 | public class Return 10 | { 11 | public virtual Product Product { get; protected set; } 12 | public virtual Customer Customer { get; protected set; } 13 | public virtual ReturnReason Reason { get; protected set; } 14 | public virtual DateTime Created { get; protected set; } 15 | public virtual string Note { get; protected set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace eCommerce.WebService 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | config.Routes.MapHttpRoute( 13 | name: "DefaultApi", 14 | routeTemplate: "api/{controller}/{action}/{id}", 15 | defaults: new { action = "get", id = RouteParameter.Optional } 16 | ); 17 | 18 | config.EnableSystemDiagnosticsTracing(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Customers/CustomerPurchaseHistoryDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.Customers 7 | { 8 | public class CustomerPurchaseHistoryDto 9 | { 10 | public Guid CustomerId { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Email { get; set; } 14 | public int TotalPurchases { get; set; } 15 | public int TotalProductsPurchased { get; set; } 16 | public decimal TotalCost { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /chapi-parser-cmake/src/test/kotlin/chapi/parser/cmake/CMakeBasicListenerTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.parser.cmake; 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Test 5 | 6 | class CMakeBasicListenerTest { 7 | 8 | @Test 9 | fun shouldReturnCodeContainerWithFilePathAsFullName() { 10 | // given 11 | val cmakeCode = """ 12 | cmake_minimum_required(VERSION 3.0) 13 | project(HelloWorld) 14 | add_executable(HelloWorld HelloWorld.cpp) 15 | """.trimIndent() 16 | val container = CMakeAnalyser().analysis(cmakeCode, "CMakeLists.txt") 17 | 18 | // when 19 | assertEquals(3, container.Fields.size) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/_fixtures/examples/2-struct-function-pointer.c: -------------------------------------------------------------------------------- 1 | // https://stackoverflow.com/questions/12642830/can-i-define-a-function-inside-a-c-structure 2 | #include 3 | #include 4 | #include 5 | 6 | struct point 7 | { 8 | int x; 9 | int y; 10 | void (*print)(const struct point*); 11 | }; 12 | 13 | void print_x(const struct point* p) 14 | { 15 | printf("x=%d\n", p->x); 16 | } 17 | 18 | void print_y(const struct point* p) 19 | { 20 | printf("y=%d\n", p->y); 21 | } 22 | 23 | int main(void) 24 | { 25 | struct point p1 = { 2, 4, print_x }; 26 | struct point p2 = { 7, 1, print_y }; 27 | 28 | p1.print(&p1); 29 | p2.print(&p2); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeProperty.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodeProperty( 7 | var Modifiers: List = listOf(), 8 | var DefaultValue: String = "", 9 | var TypeValue: String, 10 | var TypeType: String, 11 | var Annotations: List = listOf(), 12 | /// for TypeScript and Parameter 13 | var ObjectValue: List = listOf(), 14 | var ReturnTypes: List = listOf(), 15 | /** 16 | * in Golang, we also use it to save fmt.Print series values, like `fmt.Println("hello", "world")` 17 | */ 18 | var Parameters: List = listOf(), 19 | ) 20 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerPurchaseHistoryReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.DomainModelLayer.Customers 7 | { 8 | public class CustomerPurchaseHistoryReadModel 9 | { 10 | public Guid CustomerId { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public int TotalPurchases { get; set; } 14 | public int TotalProductsPurchased { get; set; } 15 | public decimal TotalCost { get; set; } 16 | public decimal TotalTax { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /gradle/chapi-module.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | //apply plugin: "maven-publish" 3 | //apply plugin: "com.jfrog.bintray" 4 | //apply from: "$rootDir/gradle/publications.gradle" 5 | 6 | //buildscript { 7 | // repositories { 8 | // jcenter() 9 | // } 10 | //} 11 | 12 | task sourcesJar(type: Jar, dependsOn: classes) { 13 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE 14 | archiveClassifier.set("sources") 15 | from sourceSets.main.allSource 16 | // Don't include or exclude anything explicitly by default. See SPR-12085. 17 | } 18 | 19 | task javadocJar(type: Jar) { 20 | archiveClassifier.set("javadoc") 21 | from javadoc 22 | } 23 | 24 | artifacts { 25 | archives sourcesJar 26 | archives javadocJar 27 | } 28 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Products/ProductDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.Products 7 | { 8 | public class ProductDto 9 | { 10 | public Guid Id { get; set; } 11 | public string Name { get; set; } 12 | public DateTime Created { get; set; } 13 | public DateTime Modified { get; set; } 14 | public bool Active { get; set; } 15 | public int Quantity { get; set; } 16 | public decimal Cost { get; set; } 17 | public Guid ProductCodeId { get; set; } 18 | public string ProductCodeName { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/usecases/usecases.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Usecases 4 | nav_order: 2 5 | has_children: true 6 | permalink: /usecases 7 | --- 8 | 9 | - [ArchGuard](https://github.com/archguard/archguard) - ArchGuard is an architecture workbench, also for architecture 10 | governance, which can analysis architecture in container, component, code level, create architecture fitness 11 | functions, 12 | and analysis system dependencies. 13 | - [UnitGen](https://github.com/unit-mesh/unit-gen) is a code fine-tuning data framework that generates data from your 14 | existing codebase. 15 | - [ChocolateFactory](https://github.com/unit-mesh/chocolate-factory) is a cutting-edge LLM toolkit designed to empower 16 | you in creating your very own AI assistant. 17 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/trailer.py: -------------------------------------------------------------------------------- 1 | # trailer 2 | # : OPEN_PAREN (argument (COMMA argument)* COMMA?)? CLOSE_PAREN 3 | # | OPEN_BRACKET subscript (COMMA subscript)* COMMA? CLOSE_BRACKET 4 | # | DOT name 5 | # ; 6 | 7 | # DOT name 8 | a.b 9 | 10 | # OPEN_PAREN CLOSE_PAREN 11 | x() 12 | 13 | # OPEN_PAREN argument CLOSE_PAREN 14 | x(a) 15 | 16 | # OPEN_PAREN argument COMMA argument COMMA CLOSE_PAREN 17 | x(a, b,) 18 | 19 | # OPEN_PAREN argument COMMA argument COMMA argument CLOSE_PAREN 20 | x(a, b, c) 21 | 22 | # OPEN_BRACKET subscript CLOSE_BRACKET 23 | x[a] 24 | 25 | # OPEN_BRACKET subscript COMMA subscript COMMA CLOSE_BRACKET 26 | x[a, b,] 27 | 28 | # OPEN_BRACKET subscript COMMA subscript COMMA subscript CLOSE_BRACKET 29 | x[a, b, c] -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace eCommerce.WebService 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/dictorsetmaker.py: -------------------------------------------------------------------------------- 1 | # dictorsetmaker 2 | # : (test COLON test | POWER expr) (COMMA (test COLON test | POWER expr))* COMMA? // key_datum_list 3 | # | test COLON test comp_for // dict_comprehension 4 | # | testlist_comp 5 | # ; 6 | 7 | # test COLON test 8 | {d : y} 9 | 10 | # POWER expr 11 | {**x} 12 | 13 | # test COLON test COMMA test COLON test 14 | {d : y, x : z} 15 | 16 | # test COLON test COMMA test COLON test COMMA 17 | {d : y, x : z,} 18 | 19 | # POWER expr COMMA test COLON test 20 | {**x, d : y} 21 | 22 | # test COLON test COMMA POWER expr 23 | {d : y, **x} 24 | 25 | # test COLON test comp_for 26 | {d : y for d, y in x} 27 | 28 | # testlist_comp 29 | {x, q, y} 30 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/AbstractClass.ts: -------------------------------------------------------------------------------- 1 | abstract class Person { 2 | name: string; 3 | 4 | constructor(name: string) { 5 | this.name = name; 6 | } 7 | 8 | abstract find(string): Person; 9 | abstract nameAbs: string; 10 | } 11 | 12 | class Employee extends Person { 13 | empCode: number; 14 | 15 | constructor(name: string, code: number) { 16 | super(name); // must call super() 17 | this.empCode = code; 18 | } 19 | 20 | find(name:string): Person { 21 | // execute AJAX request to find an employee from a db 22 | return new Employee(name, 1); 23 | } 24 | } 25 | 26 | let emp: Person = new Employee("James", 100); 27 | emp.display(); //James 28 | 29 | let emp2: Person = emp.find('Steve'); -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/weakHash.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | import "io" 5 | import "crypto/md5" 6 | import "crypto/sha256" 7 | 8 | import "golang.org/x/crypto/blake2s" 9 | 10 | // Trivial routine 11 | func WeakHash(a int32) { 12 | hMd5 := md5.New() 13 | hSha := sha256.New() 14 | hBlake2s, err := blake2s.New256(nil) 15 | if err == nil { 16 | io.WriteString(hMd5, "Welcome to Go Language Secure Coding Practices") 17 | io.WriteString(hSha, "Welcome to Go Language Secure Coding Practices") 18 | io.WriteString(hBlake2s, "Welcome to Go Language Secure Coding Practices") 19 | fmt.Printf("MD5 : %x\n", hMd5.Sum(nil)) 20 | fmt.Printf("SHA256 : %x\n", hSha.Sum(nil)) 21 | fmt.Printf("Blake2s-256: %x\n", hBlake2s.Sum(nil)) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CreditCardAdded.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Customers 8 | { 9 | public class CreditCardAdded : DomainEvent 10 | { 11 | public CreditCard CreditCard { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("CustomerId", this.CreditCard.Customer.Id); 16 | this.Args.Add("NameOnCard", this.CreditCard.NameOnCard); 17 | this.Args.Add("Last3Digits", this.CreditCard.CardNumber.Substring(this.CreditCard.CardNumber.Length - 3, 3)); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Carts/ProductAddedCart.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Carts 8 | { 9 | public class ProductAddedCart : DomainEvent 10 | { 11 | public CartProduct CartProduct { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("CartId", this.CartProduct.CartId); 16 | this.Args.Add("CustomerId", this.CartProduct.CustomerId); 17 | this.Args.Add("ProductId", this.CartProduct.ProductId); 18 | this.Args.Add("Quantity", this.CartProduct.Quantity); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerCreated.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Domain; 6 | 7 | namespace eCommerce.DomainModelLayer.Customers 8 | { 9 | public class CustomerCreated : DomainEvent 10 | { 11 | public Customer Customer { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("FirstName", this.Customer.FirstName); 16 | this.Args.Add("LastName", this.Customer.LastName); 17 | this.Args.Add("Email", this.Customer.Email); 18 | this.Args.Add("Country", this.Customer.CountryId); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Purchases/CustomerPurchasesSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using eCommerce.Helpers.Specification; 4 | 5 | namespace eCommerce.DomainModelLayer.Purchases 6 | { 7 | public class CustomerPurchasesSpec : SpecificationBase 8 | { 9 | readonly Guid customerId; 10 | 11 | public CustomerPurchasesSpec(Guid customerId) 12 | { 13 | this.customerId = customerId; 14 | } 15 | 16 | public override Expression> SpecExpression 17 | { 18 | get 19 | { 20 | return purchase => purchase.CustomerId == this.customerId; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Chapi CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | strategy: 9 | matrix: 10 | os: [macos-latest, ubuntu-latest, windows-latest] 11 | runs-on: ${{ matrix.os }} 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: Set up JDK 11 16 | uses: actions/setup-java@v1 17 | with: 18 | java-version: 11 19 | 20 | - name: Setup Gradle 21 | uses: gradle/gradle-build-action@v2 22 | 23 | - name: Execute Gradle build 24 | run: ./gradlew build 25 | 26 | - name: Execute Gradle Coverage 27 | run: ./gradlew check 28 | 29 | - name: Upload coverage reports to Codecov 30 | uses: codecov/codecov-action@v3 31 | env: 32 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 33 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Carts/ProductRemovedCart.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Carts 8 | { 9 | public class ProductRemovedCart : DomainEvent 10 | { 11 | public CartProduct CartProduct { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("CartId", this.CartProduct.CartId); 16 | this.Args.Add("CustomerId", this.CartProduct.CustomerId); 17 | this.Args.Add("ProductId", this.CartProduct.ProductId); 18 | this.Args.Add("Quantity", this.CartProduct.Quantity); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Purchases/CustomerPurchasedNProductsSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using eCommerce.Helpers.Specification; 4 | 5 | namespace eCommerce.DomainModelLayer.Purchases 6 | { 7 | public class PurchasedNProductsSpec : SpecificationBase 8 | { 9 | readonly int nProducts; 10 | 11 | public PurchasedNProductsSpec(int nProducts) 12 | { 13 | this.nProducts = nProducts; 14 | } 15 | 16 | public override Expression> SpecExpression 17 | { 18 | get 19 | { 20 | return purchase => purchase.Products.Count >= this.nProducts; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Tax/CountryTaxCreated.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Tax 8 | { 9 | public class CountryTaxCreated : DomainEvent 10 | { 11 | public CountryTax CountryTax { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("CountryTaxId", CountryTax.Id); 16 | this.Args.Add("CountryTaxCountryId", CountryTax.Country.Id); 17 | this.Args.Add("CountryTaxPercentage", this.CountryTax.Percentage); 18 | this.Args.Add("CountryTaxType", this.CountryTax.Type); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Variable.ts: -------------------------------------------------------------------------------- 1 | let employeeName = "John"; 2 | // or 3 | let employeeName:string = "John"; 4 | 5 | var num1:number = 1; 6 | 7 | const playerCodes = { 8 | player1 : 9, 9 | player2 : 10, 10 | player3 : 13, 11 | player4 : 20 12 | }; 13 | playerCodes.player2 = 11; // OK 14 | 15 | playerCodes = { //Compiler Error: Cannot assign to playerCodes because it is a constant or read-only 16 | player1 : 50, // Modified value 17 | player2 : 10, 18 | player3 : 13, 19 | player4 : 20 20 | }; 21 | 22 | playerCodesArray = { //Compiler Error: Cannot assign to playerCodes because it is a constant or read-only 23 | player1 : 50, // Modified value 24 | player2 : playerCodes[Test], 25 | player3 : 13, 26 | player4 : 20 27 | }; -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ################# 3 | ## Visual Studio 4 | ################# 5 | 6 | ## Ignore Visual Studio temporary files, build results, and 7 | ## files generated by popular Visual Studio add-ons. 8 | 9 | # User-specific files 10 | *.suo 11 | *.user 12 | *.sln.docstates 13 | 14 | # Build results 15 | 16 | [Dd]ebug/ 17 | [Rr]elease/ 18 | x64/ 19 | build/ 20 | [Bb]in/ 21 | [Oo]bj/ 22 | 23 | .vs/ 24 | 25 | 26 | # MSTest test Results 27 | [Tt]est[Rr]esult*/ 28 | [Bb]uild[Ll]og.* 29 | 30 | *_i.c 31 | *_p.c 32 | *.ilk 33 | *.meta 34 | *.obj 35 | *.pch 36 | *.pdb 37 | *.pgc 38 | *.pgd 39 | *.rsp 40 | *.sbr 41 | *.tlb 42 | *.tli 43 | *.tlh 44 | *.tmp 45 | *.tmp_proj 46 | *.log 47 | *.vspscc 48 | *.vssscc 49 | .builds 50 | *.pidb 51 | *.log 52 | *.scc 53 | -------------------------------------------------------------------------------- /chapi-domain/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | java 3 | kotlin("jvm") 4 | kotlin("plugin.serialization") version "1.6.10" 5 | 6 | `jacoco-conventions` 7 | } 8 | 9 | dependencies { 10 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") 11 | implementation(kotlin("stdlib-jdk8")) 12 | implementation(kotlin("reflect")) 13 | 14 | testImplementation(kotlin("test")) 15 | 16 | // JUnit 5 17 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") 18 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0") 19 | testRuntimeOnly("org.junit.platform:junit-platform-console:1.6.0") 20 | } 21 | 22 | tasks.withType { 23 | useJUnitPlatform() 24 | testLogging { 25 | events("passed", "skipped", "failed") 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TSIdentify.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.typescriptast 2 | 3 | import java.io.File 4 | 5 | open class TSIdentify(var filePath: String = "") { 6 | fun isJsxFile(): Boolean { 7 | return filePath.endsWith(".tsx") || filePath.endsWith(".jsx") 8 | } 9 | 10 | fun resolvePackage(): String { 11 | val split = filePath.split("/").toMutableList() 12 | if(split.size == 1) { 13 | return File(split[0]).nameWithoutExtension 14 | } 15 | 16 | if(split[0] == "src" || split[0] == "") { 17 | split[0] = "@" 18 | } else { 19 | split.add(0, "@") 20 | } 21 | 22 | split[split.size - 1] = File(split.last()).nameWithoutExtension 23 | return split.joinToString(".") 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/returnStmt.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | type Devnull struct {} 4 | 5 | func noResult() { 6 | return 7 | } 8 | 9 | func simpleF() int { 10 | return 2 11 | } 12 | 13 | func complexF1() (re float64, im float64) { 14 | return -7.0, -4.0 15 | } 16 | 17 | func complexF2() (re float64, im float64) { 18 | return complexF1() 19 | } 20 | 21 | func complexF3() (re float64, im float64) { 22 | re = 7.0 23 | im = 4.0 24 | return 25 | } 26 | 27 | func (Devnull) writeLength(p []byte) (n int, _ error) { 28 | n = len(p) 29 | return 30 | } 31 | 32 | func ReturnImported() { 33 | var p []byte 34 | var devnull Devnull 35 | noResult() // + 36 | simpleF() // + 37 | complexF1() // + 38 | complexF2() // + but sort out with propogating multiRet 39 | complexF3() // - 40 | devnull.writeLength(p) // - 41 | } -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Class.ts: -------------------------------------------------------------------------------- 1 | 2 | interface IPerson { 3 | name: string; 4 | } 5 | 6 | class Person implements IPerson { 7 | public publicString: string; 8 | private privateString: string; 9 | protected protectedString: string; 10 | readonly readonlyString: string; 11 | name: string; 12 | 13 | constructor(name: string) { 14 | this.name = name; 15 | } 16 | } 17 | 18 | class Employee extends Person { 19 | empCode: number; 20 | static pi: number = 3.14; 21 | 22 | constructor(empcode: number, name:string) { 23 | super(name); 24 | this.empCode = empcode; 25 | } 26 | 27 | displayName():void { 28 | console.log("Name = " + this.name + ", Employee Code = " + this.empCode); 29 | } 30 | } 31 | 32 | let emp = new Employee(100,"Steve"); -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/Customers/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace eCommerce.ApplicationLayer.Customers 7 | { 8 | public interface ICustomerService 9 | { 10 | bool IsEmailAvailable(string email); 11 | CustomerDto Add(CustomerDto customerDto); 12 | void Update(CustomerDto customerDto); 13 | void Remove(Guid customerId); 14 | CustomerDto Get(Guid customerId); 15 | CreditCardDto Add(Guid customerId, CreditCardDto creditCard); 16 | List GetAllCustomerPurchaseHistoryV1(); 17 | 18 | List GetAllCustomerPurchaseHistoryV2(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Products/ProductCreated.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.DomainModelLayer.Products 8 | { 9 | public class ProductCreated : DomainEvent 10 | { 11 | public Product Product { get; set; } 12 | 13 | public override void Flatten() 14 | { 15 | this.Args.Add("ProductId", this.Product.Id); 16 | this.Args.Add("ProductName", this.Product.Name); 17 | this.Args.Add("ProductQuantity", this.Product.Quantity); 18 | this.Args.Add("ProductCode", this.Product.Code.Id); 19 | this.Args.Add("ProductCost", this.Product.Cost); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /chapi-parser-cmake/src/main/kotlin/chapi/parser/cmake/CMakeBasicListener.kt: -------------------------------------------------------------------------------- 1 | package chapi.parser.cmake 2 | 3 | import chapi.domain.core.CodeContainer 4 | 5 | class CMakeBasicListener(val filePath: String) : CMakeBaseListener() { 6 | private val container: CodeContainer = CodeContainer(FullName = filePath) 7 | 8 | override fun enterCommand_invocation(ctx: CMakeParser.Command_invocationContext?) { 9 | val id = ctx?.Identifier()?.text ?: "" 10 | val arg = ctx?.single_argument()?.map { it.text } ?: emptyList() 11 | 12 | container.Fields += chapi.domain.core.CodeField( 13 | TypeKey = id, 14 | TypeValue = arg.joinToString(" "), 15 | TypeType = "String" 16 | ) 17 | } 18 | 19 | fun getNodeInfo(): CodeContainer { 20 | return container 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Specification/SpecificationBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Linq.Expressions; 6 | 7 | namespace eCommerce.Helpers.Specification 8 | { 9 | public abstract class SpecificationBase : ISpecification 10 | { 11 | private Func _compiledExpression; 12 | 13 | private Func CompiledExpression 14 | { 15 | get { return _compiledExpression ?? (_compiledExpression = SpecExpression.Compile()); } 16 | } 17 | 18 | public abstract Expression> SpecExpression { get; } 19 | 20 | public bool IsSatisfiedBy(T obj) 21 | { 22 | return CompiledExpression(obj); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/switchesExpr.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | ) 7 | 8 | func f() int { 9 | return 1 10 | } 11 | 12 | func g() {} 13 | 14 | func SwitchesExpr() int { 15 | switch os := runtime.GOOS; os { 16 | case "darwin": 17 | fmt.Println("OS X.") 18 | case "linux": 19 | fmt.Println("Linux.") 20 | default: 21 | // freebsd, openbsd, 22 | // plan9, windows... 23 | fmt.Printf("%s.\n", os) 24 | } 25 | 26 | tag := 1 27 | switch tag { 28 | default: g() 29 | case 0, 1, 2, 3: f() 30 | case 4, 5, 6, 7: f() 31 | } 32 | 33 | switch x := f(); { // missing switch expression means "true" 34 | case x < 0: return -x 35 | default: return x 36 | } 37 | 38 | switch { 39 | case 1 < 2: f() 40 | case 2 < 3: f() 41 | case tag == 4: f() 42 | } 43 | 44 | return 1 45 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/typeAsserts.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | /* 6 | type I interface { m() } 7 | 8 | type J interface { n() } 9 | 10 | 11 | 12 | func (TwoS) m() {} 13 | func (TwoS) n() {} 14 | 15 | func call(y I) { 16 | s := y.(string) // illegal: string does not implement I (missing method m) 17 | r := y.(J) // r has type io.Reader and the dynamic type of y must implement both I and io.Reader 18 | } 19 | */ 20 | 21 | type TwoS struct { 22 | } 23 | 24 | func TypeAssertions() { 25 | var i interface{} = "hello" 26 | 27 | s := i.(string) 28 | fmt.Println(s) 29 | 30 | s, ok := i.(string) 31 | fmt.Println(s, ok) 32 | 33 | f, ok := i.(float64) 34 | fmt.Println(f, ok) 35 | 36 | t, ok := i.(TwoS) 37 | fmt.Println(t, ok) 38 | 39 | //f = i.(float64) // panic 40 | // fmt.Println(f) 41 | } 42 | -------------------------------------------------------------------------------- /chapi-ast-python/src/main/java/chapi/ast/antlr/PythonParserBase.java: -------------------------------------------------------------------------------- 1 | package chapi.ast.antlr; 2 | 3 | import org.antlr.v4.runtime.Parser; 4 | import org.antlr.v4.runtime.TokenStream; 5 | 6 | public abstract class PythonParserBase extends Parser 7 | { 8 | public PythonVersion Version = PythonVersion.Autodetect; 9 | 10 | protected PythonParserBase(TokenStream input) { 11 | super(input); 12 | } 13 | 14 | protected boolean CheckVersion(int version) { 15 | return Version == PythonVersion.Autodetect || version == Version.getValue(); 16 | } 17 | 18 | protected void SetVersion(int requiredVersion) { 19 | if (requiredVersion == 2) { 20 | Version = PythonVersion.Python2; 21 | } else if (requiredVersion == 3) { 22 | Version = PythonVersion.Python3; 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /chapi-ast-go/src/main/java/chapi/ast/antlr/GoParserBase.java: -------------------------------------------------------------------------------- 1 | package chapi.ast.antlr; 2 | 3 | import java.util.List; 4 | import org.antlr.v4.runtime.*; 5 | 6 | /** 7 | * All parser methods that used in grammar (p, prev, notLineTerminator, etc.) 8 | * should start with lower case char similar to parser rules. 9 | */ 10 | public abstract class GoParserBase extends Parser 11 | { 12 | protected GoParserBase(TokenStream input) { 13 | super(input); 14 | } 15 | 16 | 17 | /** 18 | * Returns true if the current Token is a closing bracket (")" or "}") 19 | */ 20 | protected boolean closingBracket() 21 | { 22 | BufferedTokenStream stream = (BufferedTokenStream)_input; 23 | int prevTokenType = stream.LA(1); 24 | 25 | return prevTokenType == GoParser.R_CURLY || prevTokenType == GoParser.R_PAREN; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Domain/DomainEvent.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Logging; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.Helpers.Domain 8 | { 9 | public abstract class DomainEvent 10 | { 11 | public string Type { get { return this.GetType().Name; } } 12 | 13 | public DateTime Created { get; private set; } 14 | 15 | public Dictionary Args { get; private set; } 16 | 17 | public string CorrelationID { get; set; } 18 | 19 | public DomainEvent() 20 | { 21 | this.Created = DateTime.Now; 22 | this.Args = new Dictionary(); 23 | } 24 | 25 | public abstract void Flatten(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/main/java/chapi/ast/antlr/CPP14ParserBase.java: -------------------------------------------------------------------------------- 1 | package chapi.ast.antlr; 2 | 3 | import org.antlr.v4.runtime.*; 4 | import org.antlr.v4.runtime.tree.ParseTree; 5 | 6 | public abstract class CPP14ParserBase extends Parser { 7 | protected CPP14ParserBase(TokenStream input) { 8 | super(input); 9 | } 10 | 11 | protected boolean IsPureSpecifierAllowed() { 12 | try { 13 | ParserRuleContext x = this._ctx;// memberDeclarator 14 | ParseTree c = x.getChild(0).getChild(0); 15 | ParseTree c2 = c.getChild(0); 16 | ParseTree p = c2.getChild(1); 17 | if (p == null) return false; 18 | return (p instanceof CPP14Parser.ParametersAndQualifiersContext); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerRegisteredSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using System.Linq.Expressions; 7 | using eCommerce.Helpers.Specification; 8 | 9 | namespace eCommerce.DomainModelLayer.Customers 10 | { 11 | public class CustomerRegisteredSpec : SpecificationBase 12 | { 13 | Guid id; 14 | 15 | public CustomerRegisteredSpec(Guid id) 16 | { 17 | this.id = id; 18 | } 19 | 20 | public override Expression> SpecExpression 21 | { 22 | get 23 | { 24 | return customer => customer.Id == this.id; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/bufChan.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | func goRoutineA(a <-chan int) { 6 | val := <-a 7 | fmt.Println("goRoutineA received the data", val) 8 | } 9 | 10 | func BufChan() { 11 | c := make(chan int, 2) // a buffered channel 12 | c <- 3 13 | c <- 5 14 | close(c) 15 | fmt.Println(len(c), cap(c)) // 2 2 16 | x, ok := <-c 17 | fmt.Println(x, ok) // 3 true 18 | fmt.Println(len(c), cap(c)) // 1 2 19 | x, ok = <-c 20 | fmt.Println(x, ok) // 5 true 21 | fmt.Println(len(c), cap(c)) // 0 2 22 | x, ok = <-c 23 | fmt.Println(x, ok) // 0 false 24 | x, ok = <-c 25 | fmt.Println(x, ok) // 0 false 26 | fmt.Println(len(c), cap(c)) // 0 2 27 | // close(c) // panic! 28 | // The send will also panic if the above 29 | // close call is removed. 30 | // c <- 7 31 | 32 | ch := make(chan int) 33 | go goRoutineA(ch) 34 | } 35 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Generic.ts: -------------------------------------------------------------------------------- 1 | function getArray(items : T[] ) : T[] { 2 | return new Array().concat(); 3 | } 4 | 5 | let myNumArr = getArray([100, 200, 300]); 6 | let myStrArr = getArray(["Hello", "World"]); 7 | 8 | myNumArr.push(400); // OK 9 | myStrArr.push("Hello TypeScript"); // OK 10 | 11 | myNumArr.push("Hi"); // Compiler Error 12 | myStrArr.push(500); // Compiler Error 13 | 14 | 15 | function displayType(id:T, name:U): void { 16 | console.log(typeof(id) + ", " + typeof(name)); 17 | } 18 | 19 | function displayTypeNon(id:T, name:string): void { 20 | console.log(typeof(id) + ", " + typeof(name)); 21 | } 22 | 23 | function displayNames(names:T[]): void { 24 | console.log(names.join(", ")); 25 | } 26 | 27 | 28 | function display(per: T): void { 29 | console.log(`${ per.firstName} ${per.lastName}` ); 30 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/select.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | func Selects() { 4 | var a []int 5 | var c, c1, c2, c3, c4, c5 chan int 6 | var i1, i2 int 7 | select { 8 | case i1 = <-c1: 9 | print("received ", i1, " from c1\n") 10 | case c2 <- i2: 11 | print("sent ", i2, " to c2\n") 12 | case i3, ok := (<-c3): // same as: i3, ok := <-c3 13 | if ok { 14 | print("received ", i3, " from c3\n") 15 | } else { 16 | print("c3 is closed\n") 17 | } 18 | case <-c5: 19 | print("received without an assignment") 20 | case a[f()] = <-c4: 21 | // same as: 22 | // case t := <-c4 23 | // a[f()] = t 24 | default: 25 | print("no communication\n") 26 | } 27 | 28 | for i := 0; i < 10; i++ { // send random sequence of bits to c 29 | select { 30 | case c <- 0: // note: no statement, no fallthrough, no folding of cases 31 | case c <- 1: 32 | default: 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /chapi-domain/src/test/kotlin/chapi/domain/core/CodeContainerTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import org.junit.jupiter.api.Assertions.* 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class CodeContainerTest { 7 | @Test 8 | internal fun usageForContainersField() { 9 | val csharpFile = CodeContainer( 10 | PackageName = "hello.cs" 11 | ) 12 | val firstNameSpace = CodeContainer( 13 | PackageName = "worldSpace" 14 | ) 15 | csharpFile.Containers += firstNameSpace 16 | 17 | assertEquals(csharpFile.Containers.size, 1) 18 | } 19 | 20 | @Test 21 | internal fun testEquals() { 22 | assertEquals( 23 | CodeContainer( 24 | PackageName = "hello.cs" 25 | ), 26 | CodeContainer( 27 | PackageName = "hello.cs" 28 | ) 29 | ) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Carts/CustomerCartSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using eCommerce.DomainModelLayer.Products; 7 | using System.Linq.Expressions; 8 | using eCommerce.Helpers.Specification; 9 | 10 | namespace eCommerce.DomainModelLayer.Carts 11 | { 12 | public class CustomerCartSpec : SpecificationBase 13 | { 14 | readonly Guid customerId; 15 | 16 | public CustomerCartSpec(Guid customerId) 17 | { 18 | this.customerId = customerId; 19 | } 20 | 21 | public override Expression> SpecExpression 22 | { 23 | get 24 | { 25 | return cart => cart.CustomerId == this.customerId; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerAlreadyRegisteredSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using System.Linq.Expressions; 7 | using eCommerce.Helpers.Specification; 8 | 9 | namespace eCommerce.DomainModelLayer.Customers 10 | { 11 | public class CustomerAlreadyRegisteredSpec : SpecificationBase 12 | { 13 | string email; 14 | 15 | public CustomerAlreadyRegisteredSpec(string email) 16 | { 17 | this.email = email; 18 | } 19 | 20 | public override Expression> SpecExpression 21 | { 22 | get 23 | { 24 | return customer => customer.Email == this.email; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerCheckOut.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Domain; 6 | using eCommerce.DomainModelLayer.Purchases; 7 | 8 | namespace eCommerce.DomainModelLayer.Customers 9 | { 10 | public class CustomerCheckedOut : DomainEvent 11 | { 12 | public Purchase Purchase { get; set; } 13 | 14 | public override void Flatten() 15 | { 16 | this.Args.Add("CustomerId", this.Purchase.CustomerId); 17 | this.Args.Add("PurchaseId", this.Purchase.Id); 18 | this.Args.Add("TotalCost", this.Purchase.TotalCost); 19 | this.Args.Add("TotalTax", this.Purchase.TotalTax); 20 | this.Args.Add("NumberOfProducts", this.Purchase.Products.Count); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/GenericClass.ts: -------------------------------------------------------------------------------- 1 | class KeyValuePair 2 | { 3 | private key: T; 4 | private val: U; 5 | 6 | setKeyValue(key: T, val: U): void { 7 | this.key = key; 8 | this.val = val; 9 | } 10 | 11 | display():void { 12 | console.log(`Key = ${this.key}, val = ${this.val}`); 13 | } 14 | } 15 | let kvp1 = new KeyValuePair(); 16 | kvp1.setKeyValue(1, "Steve"); 17 | kvp1.display(); //Output: Key = 1, Val = Steve 18 | 19 | let kvp2 = new KayValuePair(); 20 | kvp2.SetKeyValue("CEO", "Bill"); 21 | kvp2.display(); //Output: Key = CEO, Val = Bill 22 | 23 | 24 | interface IKeyValueProcessor 25 | { 26 | process(key: T, val: U): void; 27 | }; 28 | 29 | class kvProcessor implements IKeyValueProcessor 30 | { 31 | process(key:T, val:U):void { 32 | console.log(`Key = ${key}, val = ${val}`); 33 | } 34 | } -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeField.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | /** 6 | * Represents a field in a Java class. 7 | * 8 | * In Java, a field is defined as follows: 9 | * 10 | * ```java 11 | * private String helloText = "hello, world"; 12 | * // || || || 13 | * // 14 | * ``` 15 | */ 16 | @Serializable 17 | data class CodeField( 18 | var TypeType: String = "", 19 | var TypeValue: String = "", 20 | var TypeKey: String = "", 21 | var Annotations: List = listOf(), 22 | var Modifiers: List = listOf(), 23 | /// for TypeScript and JavaScript only, examples: `export default sample = createHello() ` 24 | var Calls: List = listOf(), 25 | /// import 2.2.3 for Toml 26 | @Since("2.2.3") 27 | var ArrayValue: List = listOf(), 28 | ) 29 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/bt.c: -------------------------------------------------------------------------------- 1 | struct tree_el { 2 | int val; 3 | struct tree_el * right, * left; 4 | }; 5 | 6 | typedef struct tree_el node; 7 | 8 | void insert(node ** tree, node * item) { 9 | if(!(*tree)) { 10 | *tree = item; 11 | return; 12 | } 13 | if(item->val<(*tree)->val) 14 | insert(&(*tree)->left, item); 15 | else if(item->val>(*tree)->val) 16 | insert(&(*tree)->right, item); 17 | } 18 | 19 | void printout(node * tree) { 20 | if(tree->left) printout(tree->left); 21 | printf("%d\n",tree->val); 22 | if(tree->right) printout(tree->right); 23 | } 24 | 25 | void main() { 26 | node * curr, * root; 27 | int i; 28 | 29 | root = NULL; 30 | 31 | for(i=1;i<=10;i++) { 32 | curr = (node *)malloc(sizeof(node)); 33 | curr->left = curr->right = NULL; 34 | curr->val = rand(); 35 | insert(&root, curr); 36 | } 37 | 38 | printout(root); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerBulkIdFindSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using System.Linq.Expressions; 7 | using eCommerce.Helpers.Specification; 8 | 9 | namespace eCommerce.DomainModelLayer.Customers 10 | { 11 | public class CustomerBulkIdFindSpec : SpecificationBase 12 | { 13 | readonly IEnumerable customerIds; 14 | 15 | public CustomerBulkIdFindSpec(IEnumerable customerIds) 16 | { 17 | this.customerIds = customerIds; 18 | } 19 | 20 | public override Expression> SpecExpression 21 | { 22 | get 23 | { 24 | return customer => this.customerIds.Contains(customer.Id); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/logical_test.py: -------------------------------------------------------------------------------- 1 | # logical_test 2 | # : comparison 3 | # | NOT logical_test 4 | # | logical_test op=AND logical_test 5 | # | logical_test op=OR logical_test 6 | # ; 7 | # 8 | # comparison 9 | # : comparison (LESS_THAN | GREATER_THAN | EQUALS | GT_EQ | LT_EQ | NOT_EQ_1 | NOT_EQ_2 | optional=NOT? IN | IS optional=NOT?) comparison 10 | # | expr 11 | # ; 12 | 13 | # expr EQUALS expr 14 | a == b 15 | 16 | # not expr 17 | not a 18 | 19 | # expr AND expr 20 | a and b 21 | 22 | # expr OR expr 23 | a or b 24 | 25 | # expr LESS_THAN expr 26 | a < b 27 | 28 | # expr GREATER_THAN expr 29 | a > b 30 | 31 | # expr GT_EQ expr 32 | a >= b 33 | 34 | # expr LT_EQ expr 35 | a <= b 36 | 37 | # expr NOT_EQ_2 expr 38 | a != b 39 | 40 | # expr IN expr 41 | a in b 42 | 43 | # expr NOT IN expr 44 | a not in b 45 | 46 | # expr IS expr 47 | a is b 48 | 49 | # expr IS NOT expr 50 | a is not b 51 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/interfaces.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | type Shape interface { 6 | Area(a float64) float64 7 | } 8 | 9 | type Object interface { 10 | Volume() float64 11 | } 12 | 13 | type Material interface { 14 | Shape 15 | Object 16 | } 17 | 18 | type Cube struct { 19 | side float64 20 | } 21 | 22 | func (c Cube) Area(a float64) float64 { 23 | return 6 * (c.side * c.side) * a 24 | } 25 | 26 | func (c Cube) Volume() float64 { 27 | return c.side * c.side * c.side 28 | } 29 | 30 | func Interfaces() { 31 | c := Cube{3} 32 | var m Material = c 33 | var s Shape = c 34 | var o Object = c 35 | fmt.Printf("dynamic type and value of interface m of static type Material is'%T' and '%v'\n", m, m) 36 | fmt.Printf("dynamic type and value of interface s of static type Shape is'%T' and '%v'\n", s, s) 37 | fmt.Printf("dynamic type and value of interface o of static type Object is'%T' and '%v'\n", o, o) 38 | } 39 | -------------------------------------------------------------------------------- /chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.rustast 2 | 3 | import chapi.ast.antlr.RustLexer 4 | import chapi.ast.antlr.RustParser 5 | import chapi.domain.core.CodeContainer 6 | import chapi.parser.Analyser 7 | import org.antlr.v4.runtime.CharStreams 8 | import org.antlr.v4.runtime.CommonTokenStream 9 | import org.antlr.v4.runtime.tree.ParseTreeWalker 10 | 11 | open class RustAnalyser : Analyser { 12 | override fun analysis(code: String, filePath: String): CodeContainer { 13 | val context = this.parse(code).crate() 14 | val listener = RustFullIdentListener(filePath) 15 | ParseTreeWalker().walk(listener, context) 16 | return listener.getNodeInfo() 17 | } 18 | 19 | private fun parse(str: String): RustParser = 20 | CharStreams.fromString(str) 21 | .let(::RustLexer) 22 | .let(::CommonTokenStream) 23 | .let(::RustParser) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Specification/IExtensions.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Repository; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace eCommerce.Helpers.Specification 8 | { 9 | public static class IExtensions 10 | { 11 | public static ISpecification And( 12 | this ISpecification left, 13 | ISpecification right) 14 | { 15 | return new And(left, right); 16 | } 17 | 18 | public static ISpecification Or( 19 | this ISpecification left, 20 | ISpecification right) 21 | { 22 | return new Or(left, right); 23 | } 24 | 25 | public static ISpecification Negate(this ISpecification inner) 26 | { 27 | return new Negated(inner); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/grammar/macro.cpp: -------------------------------------------------------------------------------- 1 | #define Verify(cond, msg) \ 2 | do \ 3 | { \ 4 | if (!(cond)) \ 5 | { \ 6 | verRaiseVerifyExceptionIfNeeded(INDEBUG(msg) DEBUGARG(__FILE__) DEBUGARG(__LINE__)); \ 7 | } \ 8 | } while (0) 9 | 10 | void f() { 11 | int b = 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Carts/ProductInCartSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using eCommerce.DomainModelLayer.Products; 7 | using System.Linq.Expressions; 8 | using eCommerce.Helpers.Specification; 9 | 10 | namespace eCommerce.DomainModelLayer.Carts 11 | { 12 | public class ProductInCartSpec : SpecificationBase 13 | { 14 | readonly Product product; 15 | 16 | public ProductInCartSpec(Product product) 17 | { 18 | this.product = product; 19 | } 20 | 21 | public override Expression> SpecExpression 22 | { 23 | get 24 | { 25 | return cartProduct => cartProduct.ProductId == this.product.Id; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CreditCardAvailableSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using System.Linq.Expressions; 7 | using eCommerce.Helpers.Specification; 8 | 9 | namespace eCommerce.DomainModelLayer.Customers.Spec 10 | { 11 | public class CreditCardAvailableSpec : SpecificationBase 12 | { 13 | readonly DateTime dateTime; 14 | 15 | public CreditCardAvailableSpec(DateTime dateTime) 16 | { 17 | this.dateTime = dateTime; 18 | } 19 | 20 | public override Expression> SpecExpression 21 | { 22 | get 23 | { 24 | return creditCard => creditCard.Active && creditCard.Expiry >= this.dateTime; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapi-ast-scala/src/main/kotlin/chapi/ast/scalaast/ScalaAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.scalaast 2 | 3 | import chapi.ast.antlr.ScalaLexer 4 | import chapi.ast.antlr.ScalaParser 5 | import chapi.domain.core.CodeContainer 6 | import chapi.parser.Analyser 7 | import org.antlr.v4.runtime.CharStreams 8 | import org.antlr.v4.runtime.CommonTokenStream 9 | import org.antlr.v4.runtime.tree.ParseTreeWalker 10 | 11 | open class ScalaAnalyser: Analyser { 12 | override fun analysis(code: String, filePath: String): CodeContainer { 13 | val context = this.parse(code).compilationUnit() 14 | val listener = ScalaFullIdentListener(fileName = filePath) 15 | 16 | ParseTreeWalker().walk(listener, context) 17 | return listener.getNodeInfo() 18 | } 19 | 20 | private fun parse(str: String): ScalaParser = 21 | CharStreams.fromString(str) 22 | .let(::ScalaLexer) 23 | .let(::CommonTokenStream) 24 | .let(::ScalaParser) 25 | } 26 | -------------------------------------------------------------------------------- /chapi-ast-c/src/test/resources/grammar/integrate.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | float f(float x) 5 | { 6 | return(1/(1+pow(x,2))); 7 | } 8 | void main() 9 | { 10 | int i,n; 11 | float x0,xn,h,y[20],so,se,ans,x[20]; 12 | printf("\n Enter values of x0,xn,h:\n"); 13 | scanf("%f%f%f",&x0,&xn,&h); 14 | n=(xn-x0)/h; 15 | if(n%2==1) 16 | { 17 | n=n+1; 18 | } 19 | h=(xn-x0)/n; 20 | printf("\nrefined value of n and h are:%d %f\n",n,h); 21 | printf("\n Y values \n"); 22 | for(i=0; i<=n; i++) 23 | { 24 | x[i]=x0+i*h; 25 | y[i]=f(x[i]); 26 | printf("\n%f\n",y[i]); 27 | } 28 | so=0; 29 | se=0; 30 | for(i=1; i !x.IsInterface && !x.IsAbstract && !x.Name.EndsWith("Dto") && x.Namespace.Contains("ApplicationLayer")) 15 | .WithService.DefaultInterfaces() 16 | .Configure(c => c.LifestyleTransient())); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/foreachStmts.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | func ForeachStmts() { 6 | // Here we use `range` to sum the numbers in a slice. 7 | // Arrays work like this too. 8 | nums := []int{2, 3, 4} 9 | sum := 0 10 | for _, num := range nums { 11 | sum += num 12 | } 13 | fmt.Println("sum:", sum) 14 | 15 | // `range` on arrays and slices provides both the 16 | // index and value for each entry. Above we didn't 17 | // need the index, so we ignored it with the 18 | // blank identifier `_`. Sometimes we actually want 19 | // the indexes though. 20 | for i, num := range nums { 21 | if num == 3 { 22 | fmt.Println("index:", i) 23 | } 24 | } 25 | 26 | // `range` on map iterates over key/value pairs. 27 | kvs := map[string]string{"a": "apple", "b": "banana"} 28 | 29 | for k, v := range kvs { 30 | fmt.Printf("%s -> %s\n", k, v) 31 | } 32 | 33 | // Valid statement 34 | for range kvs { 35 | fmt.Printf("empty range\n") 36 | } 37 | } -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptCallTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.typescriptast; 2 | 3 | import kotlinx.serialization.encodeToString 4 | import kotlinx.serialization.json.Json 5 | import org.junit.jupiter.api.Test 6 | import kotlin.test.assertEquals 7 | 8 | internal class TypeScriptCallTest { 9 | 10 | @Test 11 | fun shouldIdentifyNewObjectCall() { 12 | val code = """ 13 | function testNew() { 14 | let emp = new Employee(100,"Steve"); 15 | emp.display(); 16 | } 17 | """ 18 | val codeFile = TypeScriptAnalyser().analysis(code, "") 19 | 20 | assertEquals(codeFile.DataStructures.size, 1) 21 | val functionCalls = codeFile.DataStructures[0].Functions[0].FunctionCalls 22 | assertEquals(functionCalls.size, 1) 23 | assertEquals(functionCalls[0].FunctionName, "display") 24 | assertEquals(functionCalls[0].NodeName, "Employee") 25 | assertEquals(functionCalls[0].Parameters.size, 0) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/inference/HistoryService.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using eCommerce.Helpers.Repository; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace eCommerce.ApplicationLayer.History 9 | { 10 | public class HistoryService : IHistoryService 11 | { 12 | IDomainEventRepository domainEventRepository; 13 | 14 | public HistoryService(IDomainEventRepository domainEventRepository) 15 | { 16 | this.domainEventRepository = domainEventRepository; 17 | } 18 | 19 | public HistoryDto GetHistory() 20 | { 21 | IEnumerable events = this.domainEventRepository.FindAll(); 22 | 23 | HistoryDto history = new HistoryDto(); 24 | history.Events = AutoMapper.Mapper.Map, List>(events); 25 | 26 | return history; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Products/ProductReturnReasonSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using System.Linq.Expressions; 7 | using eCommerce.Helpers.Specification; 8 | 9 | namespace eCommerce.DomainModelLayer.Products 10 | { 11 | public class ProductReturnReasonSpec : SpecificationBase 12 | { 13 | readonly ReturnReason returnReason; 14 | 15 | public ProductReturnReasonSpec(ReturnReason returnReason) 16 | { 17 | this.returnReason = returnReason; 18 | } 19 | 20 | public override Expression> SpecExpression 21 | { 22 | get 23 | { 24 | return product => product.Returns.ToList().Exists(returns => returns.Reason == this.returnReason); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapi-ast-thrift/src/main/kotlin/chapi/ast/thrift/ThriftAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.thrift 2 | 3 | import chapi.ast.antlr.ThriftLexer 4 | import chapi.ast.antlr.ThriftParser 5 | import chapi.domain.core.CodeContainer 6 | import chapi.parser.Analyser 7 | import org.antlr.v4.runtime.* 8 | import org.antlr.v4.runtime.tree.ParseTreeWalker 9 | 10 | class ThriftAnalyser : Analyser { 11 | override fun analysis(code: String, filePath: String): CodeContainer { 12 | val context = this.parse(code).document() 13 | val listener = ThriftFullIdentListener(fileName = filePath) 14 | ParseTreeWalker().walk(listener, context) 15 | 16 | return listener.getNodeInfo() 17 | } 18 | 19 | private fun parse(str: String): ThriftParser { 20 | val fromString = CharStreams.fromString(str) 21 | val lexer = ThriftLexer(fromString) 22 | val tokenStream = CommonTokenStream(lexer) 23 | val parser = ThriftParser(tokenStream) 24 | return parser 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /chapi-ast-scala/src/main/kotlin/chapi/ast/scalaast/ScalaAstBaseListener.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.scalaast 2 | 3 | import chapi.ast.antlr.ScalaBaseListener 4 | import chapi.ast.antlr.ScalaParser 5 | import chapi.domain.core.CodeProperty 6 | 7 | open class ScalaAstBaseListener : ScalaBaseListener() { 8 | fun buildParameters(classParamClauses: ScalaParser.ClassParamClausesContext?): List { 9 | return classParamClauses?.classParamClause()?.flatMap { paramClauseContext -> 10 | paramClauseContext.classParams().classParam().map { classParamContext -> 11 | buildParameter(classParamContext) 12 | } 13 | } ?: emptyList() 14 | } 15 | 16 | private fun buildParameter(classParamContext: ScalaParser.ClassParamContext): CodeProperty { 17 | val parameter = CodeProperty( 18 | TypeType = classParamContext.paramType().text, 19 | TypeValue = classParamContext.Id().text 20 | ) 21 | 22 | return parameter 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Countries/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Domain; 6 | 7 | namespace eCommerce.DomainModelLayer.Countries 8 | { 9 | public class Country : IAggregateRoot 10 | { 11 | public Guid Id { get; protected set; } 12 | public string Name { get; protected set; } 13 | 14 | public static Country Create(string name) 15 | { 16 | return Create(Guid.NewGuid(), name); 17 | } 18 | 19 | public static Country Create(Guid id, string name) 20 | { 21 | Country country = new Country() 22 | { 23 | Id = id, 24 | Name = name 25 | }; 26 | 27 | DomainEvents.Raise(new CountryCreated() { Country = country }); 28 | 29 | return country; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/specific/struct_function.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // Finalsalary of function type 6 | type Finalsalary func(int, int) int 7 | 8 | // Creating structure 9 | type Author struct { 10 | name string 11 | language string 12 | Marticles int 13 | Pay int 14 | 15 | // Function as a field 16 | salary Finalsalary 17 | } 18 | 19 | // Main method 20 | func main() { 21 | 22 | // Initializing the fields 23 | // of the structure 24 | result := Author{ 25 | name: "Sonia", 26 | language: "Java", 27 | Marticles: 120, 28 | Pay: 500, 29 | salary: func(Ma int, pay int) int { 30 | return Ma * pay 31 | }, 32 | } 33 | 34 | // Display values 35 | fmt.Println("Author's Name: ", result.name) 36 | fmt.Println("Language: ", result.language) 37 | fmt.Println("Total number of articles published in May: ", result.Marticles) 38 | fmt.Println("Per article pay: ", result.Pay) 39 | fmt.Println("Total salary: ", result.salary(result.Marticles, result.Pay)) 40 | } 41 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.typescriptast 2 | 3 | import chapi.ast.antlr.TypeScriptLexer 4 | import chapi.ast.antlr.TypeScriptParser 5 | import chapi.domain.core.CodeContainer 6 | import chapi.parser.Analyser 7 | import org.antlr.v4.runtime.CharStreams 8 | import org.antlr.v4.runtime.CommonTokenStream 9 | import org.antlr.v4.runtime.tree.ParseTreeWalker 10 | 11 | open class TypeScriptAnalyser: Analyser { 12 | override fun analysis(code: String, filePath: String): CodeContainer { 13 | val context = this.parse(code).program() 14 | val listener = TypeScriptFullIdentListener(TSIdentify(filePath = filePath)) 15 | ParseTreeWalker().walk(listener, context) 16 | return listener.getNodeInfo() 17 | } 18 | 19 | private fun parse(str: String): TypeScriptParser = 20 | CharStreams.fromString(str) 21 | .let(::TypeScriptLexer) 22 | .let(::CommonTokenStream) 23 | .let(::TypeScriptParser) 24 | } 25 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/App_Start/BootstrapConfig.cs: -------------------------------------------------------------------------------- 1 | using Castle.Windsor; 2 | using eCommerce.WebService.App_Start.Installers; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Web; 7 | using System.Web.Http; 8 | using System.Web.Http.Dispatcher; 9 | using System.Web.Mvc; 10 | 11 | namespace eCommerce.WebService.App_Start 12 | { 13 | public class BootstrapConfig 14 | { 15 | public static void Register(IWindsorContainer container) 16 | { 17 | GlobalConfiguration.Configuration.Services.Replace( 18 | typeof(IHttpControllerActivator), 19 | new WindsorCompositionRoot(container)); 20 | 21 | container.Install( 22 | new InfrastructureLayerInstall(), 23 | new ApplicationLayerInstall(), 24 | new DomainModelLayerInstall(), 25 | new DistributedInterfaceLayerInstall() 26 | ); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/ApplicationLayer/History/HistoryService.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using eCommerce.Helpers.Repository; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace eCommerce.ApplicationLayer.History 9 | { 10 | public class HistoryService : IHistoryService 11 | { 12 | IDomainEventRepository domainEventRepository; 13 | 14 | public HistoryService(IDomainEventRepository domainEventRepository) 15 | { 16 | this.domainEventRepository = domainEventRepository; 17 | } 18 | 19 | public HistoryDto GetHistory() 20 | { 21 | IEnumerable events = this.domainEventRepository.FindAll(); 22 | 23 | HistoryDto history = new HistoryDto(); 24 | history.Events = AutoMapper.Mapper.Map, List>(events); 25 | 26 | return history; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Function.ts: -------------------------------------------------------------------------------- 1 | function Sum(x: number, y: number) : void { 2 | console.log('processNumKeyPairs: key = ' + key + ', value = ' + value) 3 | return x + y; 4 | } 5 | 6 | 7 | let greeting = function() { 8 | console.log("Hello TypeScript!"); 9 | }; 10 | 11 | let SumAnon = function(x: number, y: number) : number 12 | { 13 | return x + y; 14 | } 15 | 16 | function Greet(greeting: string, name?: string ) : string { 17 | return greeting + ' ' + name + '!'; 18 | } 19 | 20 | function Greet2(name: string, greeting: string = "Hello") : string { 21 | return greeting + ' ' + name + '!'; 22 | } 23 | 24 | Greet(undefined, 'Steve'); 25 | 26 | let sumArrow = (x: number, y: number): number => { 27 | return x + y 28 | } 29 | 30 | let Print = () => console.log("Hello TypeScript"); 31 | 32 | let sumShortArrow = (x: number, y: number) => x + y; 33 | 34 | function Test(value: TestClass | TestClass2): value is TestClass { 35 | return (value).someFunction !== undefined; 36 | } 37 | -------------------------------------------------------------------------------- /chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.goast 2 | 3 | import chapi.ast.antlr.GoLexer 4 | import chapi.ast.antlr.GoParser 5 | import chapi.domain.core.CodeContainer 6 | import chapi.parser.Analyser 7 | import org.antlr.v4.runtime.CharStreams 8 | import org.antlr.v4.runtime.CommonTokenStream 9 | import org.antlr.v4.runtime.tree.ParseTreeWalker 10 | 11 | open class GoAnalyser: Analyser { 12 | override fun analysis(code: String, filePath: String): CodeContainer { 13 | val context = this.parse(code).sourceFile() 14 | val listener = GoFullIdentListener(fileName = filePath) 15 | 16 | ParseTreeWalker().walk(listener, context) 17 | 18 | val nodeInfo = listener.getNodeInfo() 19 | return nodeInfo 20 | } 21 | 22 | open fun parse(str: String): GoParser { 23 | val fromString = CharStreams.fromString(str) 24 | val lexer = GoLexer (fromString) 25 | val tokenStream = CommonTokenStream(lexer) 26 | return GoParser(tokenStream) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Type.ts: -------------------------------------------------------------------------------- 1 | // TypeAnotation 2 | var age: number = 32; // number variable 3 | var name: string = "John";// string variable 4 | var isUpdated: boolean = true;// Boolean variable 5 | 6 | var employee : { 7 | id: number; 8 | name: string; 9 | }; 10 | 11 | employee = { 12 | id: 100, 13 | name : "John" 14 | } 15 | 16 | function display(id:number, name:string) 17 | { 18 | console.log("Id = " + id + ", Name = " + name); 19 | } 20 | 21 | 22 | // TypeInterface 23 | 24 | var arr = [0, 1, "test"]; 25 | arr.push("str") // OK 26 | arr.push(true); // Compiler Error: Argument of type 'true' is not assignable to parameter of type 'string | number' 27 | 28 | function sum(a: number, b: number ) 29 | { 30 | return a + b; 31 | } 32 | var total: number = sum(10,20); // OK 33 | var str: string = sum(10,20); // Compiler Error 34 | 35 | 36 | // TypeAssertion 37 | 38 | let code: any = 123; 39 | let employeeCode = code; 40 | console.log(typeof(employeeCode)); //Output: number 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/constDecl.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | // var entries map[string]int 6 | 7 | func constMultiRet() (int, int) { 8 | return 1, 2 9 | } 10 | 11 | func ConstDecls() { 12 | const ( 13 | c0 = iota // c0 == 0 14 | c1 = iota // c1 == 1 15 | c2 = iota // c2 == 2 16 | ) 17 | const ( 18 | Sunday = iota 19 | Monday 20 | Tuesday 21 | Wednesday 22 | Thursday 23 | Friday 24 | Partyday 25 | numberOfDays // this constant is not exported 26 | ) // TODO: Added support for iota token 27 | const Pi float64 = 3.14159265358979323846 28 | const zero = 0.0 // untyped floating-point constant 29 | const ( 30 | size int64 = 1024 31 | eof = -1 // untyped integer constant 32 | ) 33 | const a, b, c = 3, 4, "foo" // a = 3, b = 4, c = "foo", untyped integer and string constants 34 | const u, v float32 = 0, 3 // u = 0.0, v = 3.0 35 | fmt.Println(c0, c1, c2, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Partyday, numberOfDays, Pi, zero, size, eof, a, b, c, u, v) 36 | } 37 | -------------------------------------------------------------------------------- /chapi-helper/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | java 3 | kotlin("jvm") 4 | kotlin("plugin.serialization") version "1.6.10" 5 | 6 | `jacoco-conventions` 7 | } 8 | 9 | dependencies { 10 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") 11 | implementation(kotlin("stdlib-jdk8")) 12 | implementation(kotlin("reflect")) 13 | 14 | implementation("org.antlr:antlr4:4.13.2") 15 | implementation("org.antlr:antlr4-runtime:4.13.2") 16 | // Kotlin reflection. 17 | testImplementation(kotlin("test")) 18 | 19 | testImplementation(project(":chapi-ast-java")) 20 | testImplementation(project(":chapi-domain")) 21 | 22 | // JUnit 5 23 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") 24 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0") 25 | testRuntimeOnly("org.junit.platform:junit-platform-console:1.6.0") 26 | } 27 | 28 | tasks.withType { 29 | useJUnitPlatform() 30 | testLogging { 31 | events("passed", "skipped", "failed") 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Products/ProductCode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Domain; 6 | 7 | namespace eCommerce.DomainModelLayer.Products 8 | { 9 | public class ProductCode : IAggregateRoot 10 | { 11 | public Guid Id { get; protected set; } 12 | public string Name { get; protected set; } 13 | 14 | public static ProductCode Create(string name) 15 | { 16 | return Create(Guid.NewGuid(), name); 17 | } 18 | 19 | public static ProductCode Create(Guid id, string name) 20 | { 21 | ProductCode productCode = new ProductCode() 22 | { 23 | Id = id, 24 | Name = name 25 | }; 26 | 27 | DomainEvents.Raise(new ProductCodeCreated() { ProductCode = productCode }); 28 | 29 | return productCode; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/sliceDecls.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func SliceDecls() { 8 | primes := [6]int{2, 3, 5, 7, 11, 13} 9 | var sl []int = primes[1:4] 10 | fmt.Println(sl) 11 | 12 | s := make([]string, 3) 13 | fmt.Println("emp:", s) 14 | 15 | s[0] = "a" 16 | s[1] = "b" 17 | s[2] = "c" 18 | fmt.Println("set:", s) 19 | fmt.Println("get:", s[2]) 20 | fmt.Println("len:", len(s)) 21 | 22 | s = append(s, "d") 23 | s = append(s, "e", "f") 24 | fmt.Println("apd:", s) 25 | 26 | c := make([]string, len(s)) 27 | copy(c, s) 28 | fmt.Println("cpy:", c) 29 | 30 | l := s[2:5] 31 | fmt.Println("sl1:", l) 32 | 33 | l = s[:5] 34 | fmt.Println("sl2:", l) 35 | 36 | l = s[2:] 37 | fmt.Println("sl3:", l) 38 | 39 | t := []string{"g", "h", "i"} 40 | fmt.Println("dcl:", t) 41 | 42 | twoD := make([][]int, 3) 43 | for i := 0; i < 3; i++ { 44 | innerLen := i + 1 45 | twoD[i] = make([]int, innerLen) 46 | for j := 0; j < innerLen; j++ { 47 | twoD[i][j] = i + j 48 | } 49 | } 50 | fmt.Println("2d: ", twoD) 51 | } -------------------------------------------------------------------------------- /chapi-ast-python/src/main/kotlin/chapi/ast/pythonast/PythonAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.pythonast 2 | 3 | import chapi.ast.antlr.PythonLexer 4 | import chapi.ast.antlr.PythonParser 5 | import chapi.domain.core.CodeContainer 6 | import chapi.parser.Analyser 7 | import org.antlr.v4.runtime.CharStreams 8 | import org.antlr.v4.runtime.CommonTokenStream 9 | import org.antlr.v4.runtime.tree.ParseTreeWalker 10 | 11 | open class PythonAnalyser: Analyser { 12 | override fun analysis(code: String, filePath: String): CodeContainer { 13 | val context = this.parse(code).root() 14 | val listener = PythonFullIdentListener(fileName = filePath) 15 | ParseTreeWalker().walk(listener, context) 16 | 17 | return listener.getNodeInfo() 18 | } 19 | 20 | private fun parse(str: String): PythonParser { 21 | val fromString = CharStreams.fromString(str) 22 | val lexer = PythonLexer(fromString) 23 | val tokenStream = CommonTokenStream(lexer) 24 | val parser = PythonParser(tokenStream) 25 | return parser 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/small_stmt.py: -------------------------------------------------------------------------------- 1 | # del_stmt: DEL exprlist 2 | 3 | del x, d[1], await f 4 | 5 | # pass_stmt: PASS 6 | for i in u: pass 7 | 8 | # break_stmt: BREAK 9 | for i in u: break 10 | 11 | # continue_stmt: CONTINUE 12 | for i in u: continue 13 | 14 | # return_stmt: RETURN testlist? 15 | def f(): 16 | # RETURN 17 | return 18 | def g(): 19 | # RETURN testlist 20 | return 1, 3 21 | 22 | # [Python 3] raise_stmt: RAISE (test (FROM test)?)? 23 | 24 | # RAISE test FROM test 25 | raise a from b 26 | 27 | # RAISE test 28 | raise a 29 | 30 | try: 31 | a 32 | except: 33 | # RAISE 34 | raise 35 | 36 | # global_stmt: GLOBAL name (COMMA name)* 37 | 38 | # GLOBAL name 39 | global a 40 | 41 | # GLOBAL name COMMA name 42 | global a, b 43 | 44 | # assert_stmt: ASSERT test (COMMA test)? 45 | 46 | # ASSERT test 47 | assert a 48 | 49 | # ASSERT test COMMA test 50 | assert a, b 51 | 52 | # nonlocal_stmt: NONLOCAL name (COMMA name)* 53 | 54 | # NONLOCAL name 55 | nonlocal a 56 | 57 | # NONLOCAL name (COMMA name) 58 | nonlocal a, v 59 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/interface_inheritance.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type T1 struct { 6 | name string 7 | } 8 | 9 | func (t T1) M() {} 10 | func (t T1) N() {} 11 | func (t T1) String() string { return "" } 12 | func (t T1) Error() string { return "" } 13 | 14 | type T2 struct { 15 | name string 16 | } 17 | 18 | func (t T2) M() {} 19 | func (t T2) N() {} 20 | func (t T2) String() string { return "" } 21 | func (t T2) Error() string { return "" } 22 | 23 | type I interface { 24 | M() 25 | } 26 | 27 | // In the following interface declaration, error is an 28 | // inherited interface, not the "result" type of N() 29 | type V interface { 30 | I 31 | fmt.Stringer 32 | N() 33 | error 34 | } 35 | 36 | func main() { 37 | m := make(map[I]int) 38 | var i1 I = T1{"foo"} 39 | var i2 I = T2{"bar"} 40 | m[i1] = 1 41 | m[i2] = 2 42 | fmt.Println(m) 43 | 44 | n := make(map[V]int) 45 | var v1 V = T1{"foo"} 46 | var v2 V = T2{"bar"} 47 | v1.N() 48 | v2.M() 49 | v1.String() 50 | v2.Error() 51 | n[v1] = 3 52 | n[v2] = 4 53 | fmt.Println(n) 54 | } -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/struct_promotion.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Person struct { 6 | name string 7 | age int32 8 | } 9 | 10 | func (p Person) IsAdult() bool { 11 | return p.age >= 18 12 | } 13 | 14 | type Employee struct { 15 | position string 16 | } 17 | 18 | func (e Employee) IsManager() bool { 19 | return e.position == "manager" 20 | } 21 | 22 | // In the following structure declaration, Employee is a 23 | // promoted structure, not the "result" type of Person 24 | type Record struct { 25 | Person 26 | Employee 27 | } 28 | 29 | func main() { 30 | person := Person{name: "Michal", age: 29} 31 | fmt.Println(person) // {Michal 29} 32 | record := Record{} 33 | record.name = "Michal" 34 | record.age = 29 35 | record.position = "software engineer" 36 | 37 | fmt.Println(record) // {{Michal 29} {software engineer}} 38 | fmt.Println(record.name) // Michal 39 | fmt.Println(record.age) // 29 40 | fmt.Println(record.position) // software engineer 41 | fmt.Println(record.IsAdult()) // true 42 | fmt.Println(record.IsManager()) // false 43 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/App_Start/Installers/DistributedInterfaceLayerInstall.cs: -------------------------------------------------------------------------------- 1 | using Castle.MicroKernel.Registration; 2 | using eCommerce.Helpers.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Web; 7 | using System.Web.Http.Controllers; 8 | using System.Web.Mvc; 9 | 10 | namespace eCommerce.WebService.App_Start.Installers 11 | { 12 | public class DistributedInterfaceLayerInstall : Castle.MicroKernel.Registration.IWindsorInstaller 13 | { 14 | public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store) 15 | { 16 | container.Register(Classes.FromThisAssembly() 17 | .BasedOn() 18 | .Configure(c => c.LifestyleTransient())); 19 | 20 | container.Register(Component.For().ImplementedBy().LifeStyle.PerWebRequest); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Products/ProductIsInStockSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Repository; 6 | using System.Linq.Expressions; 7 | using eCommerce.DomainModelLayer.Carts; 8 | using eCommerce.Helpers.Specification; 9 | 10 | namespace eCommerce.DomainModelLayer.Products 11 | { 12 | public class ProductIsInStockSpec : SpecificationBase 13 | { 14 | readonly CartProduct productCart; 15 | 16 | public ProductIsInStockSpec(CartProduct productCart) 17 | { 18 | this.productCart = productCart; 19 | } 20 | 21 | public override Expression> SpecExpression 22 | { 23 | 24 | get 25 | { 26 | return product => product.Id == this.productCart.ProductId && product.Active 27 | && product.Quantity >= this.productCart.Quantity; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /chapi-parser-toml/src/main/kotlin/chapi/parser/toml/TomlType.kt: -------------------------------------------------------------------------------- 1 | package chapi.parser.toml 2 | 3 | enum class TomlType { 4 | String_, 5 | Int, 6 | Float, 7 | Bool, 8 | Date, 9 | Array, 10 | InlineTable, 11 | None; 12 | 13 | override fun toString(): String { 14 | return when (this) { 15 | String_ -> "String" 16 | Int -> "Int" 17 | Float -> "Float" 18 | Bool -> "Bool" 19 | Date -> "Date" 20 | Array -> "Array" 21 | InlineTable -> "InlineTable" 22 | None -> "None" 23 | } 24 | } 25 | 26 | companion object { 27 | fun fromString(type: String): TomlType? { 28 | return when (type) { 29 | "String" -> String_ 30 | "Int" -> Int 31 | "Float" -> Float 32 | "Bool" -> Bool 33 | "Date" -> Date 34 | "Array" -> Array 35 | "InlineTable" -> InlineTable 36 | else -> null 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/Controllers/HistoryController.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.ApplicationLayer.History; 2 | using eCommerce.WebService.Models; 3 | using System; 4 | using System.Web.Http; 5 | 6 | namespace eCommerce.WebService.Controllers 7 | { 8 | public class HistoryController : ApiController 9 | { 10 | readonly IHistoryService historyService; 11 | 12 | public HistoryController(IHistoryService historyService) 13 | { 14 | this.historyService = historyService; 15 | } 16 | 17 | [HttpGet] 18 | public Response All() 19 | { 20 | Response response = new Response(); 21 | try 22 | { 23 | response.Object = this.historyService.GetHistory(); 24 | } 25 | catch (Exception ex) 26 | { 27 | //log error 28 | response.Errored = true; 29 | response.ErrorMessage = ex.Message; 30 | } 31 | return response; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Specification/Negate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace eCommerce.Helpers.Specification 8 | { 9 | public class Negated : SpecificationBase 10 | { 11 | private readonly ISpecification _inner; 12 | 13 | public Negated(ISpecification inner) 14 | { 15 | _inner = inner; 16 | } 17 | 18 | // NegatedSpecification 19 | public override Expression> SpecExpression 20 | { 21 | get 22 | { 23 | var objParam = Expression.Parameter(typeof(T), "obj"); 24 | 25 | var newExpr = Expression.Lambda>( 26 | Expression.Not( 27 | Expression.Invoke(this._inner.SpecExpression, objParam) 28 | ), 29 | objParam 30 | ); 31 | 32 | return newExpr; 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/map_with_string.go: -------------------------------------------------------------------------------- 1 | package test_controller 2 | 3 | import ( 4 | "aa.bb.com/facility/assert" 5 | "aa.bb.com/xxx/post/internal/controller" 6 | "aa.bb.com/xxx/post/pkg/cerror" 7 | ctx2 "aa.bb.com/xxx/post/test/tools/ctx" 8 | "aa.bb.com/xxx/post/thrift_gen/base" 9 | "aa.bb.com/xxx/post/thrift_gen/something/xxx/post" 10 | "aa.bb.com/gopkg/logs" 11 | ) 12 | 13 | func newUpdateCommentRequest() *post.UpdateCommentRequest { 14 | req := post.NewUpdateCommentRequest() 15 | req.CommentId = 18 16 | fields := map[string]interface{}{ 17 | "extra": `{"test_update_fields":"update_fields_by_test"}`, 18 | } 19 | req.UpdateFields, _ = json.MarshalToString(fields) 20 | req.Base = &base.Base{ 21 | Caller: "some.interface.withip", 22 | } 23 | return req 24 | } 25 | 26 | func TestUpdateComment() { 27 | ctx := ctx2.MockKiteContext("contextname", "") 28 | req := newUpdateCommentRequest() 29 | resp, err := controller.UpdateComment(ctx, req) 30 | logs.Info("%+v %+v %+v", req, resp, err) 31 | assert.IsNil(err) 32 | assert.EqualInt32(resp.BaseResp.StatusCode, cerror.ErrNo_Success.Int32()) 33 | } 34 | 35 | -------------------------------------------------------------------------------- /chapi-ast-go/src/test/resources/examples/forStmts.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | import "fmt" 4 | 5 | func S() (int, int) { 6 | return 1, 2 7 | } 8 | 9 | func ForStmts() { 10 | a, b := 1, 2 11 | for a < b { 12 | fmt.Println("From condition-only ForStmt") 13 | break 14 | } 15 | 16 | for ;; { 17 | fmt.Println("From empty ForClause ForStmt") 18 | break 19 | } 20 | 21 | // non-compaliable 22 | /*for j: = 0 ; ; { 23 | a += b 24 | fmt.Println("From ForClause with only init ForStmt") 25 | break 26 | }*/ 27 | 28 | for ; a < b; { 29 | fmt.Println("From condition-only ForClause ForClause ForStmt") 30 | break 31 | } 32 | 33 | for j:=0 ; a < b; { 34 | j++ 35 | fmt.Println("From init and condition ForClause ForClause ForStmt") 36 | break 37 | } 38 | 39 | for j:=0 ; ; j++ { 40 | fmt.Println("From init and post ForClause ForClause ForStmt") 41 | break 42 | } 43 | 44 | for ; a < b ; a++ { 45 | fmt.Println("From condition and post ForClause ForClause ForStmt") 46 | break 47 | } 48 | 49 | for z:=0 ; a < b ; z++ { 50 | fmt.Println("From full ForClause ForClause ForStmt") 51 | return 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/atom.py: -------------------------------------------------------------------------------- 1 | # atom 2 | # : OPEN_PAREN (yield_expr | testlist_comp)? CLOSE_PAREN 3 | # | OPEN_BRACKET testlist_comp? CLOSE_BRACKET 4 | # | OPEN_BRACE dictorsetmaker? CLOSE_BRACE 5 | # | REVERSE_QUOTE testlist COMMA? REVERSE_QUOTE 6 | # | dotted_name 7 | # | ELLIPSIS 8 | # | name 9 | # | PRINT 10 | # | EXEC 11 | # | MINUS? number 12 | # | NONE 13 | # | STRING+ 14 | # ; 15 | 16 | # OPEN_PAREN CLOSE_PAREN 17 | () 18 | 19 | # OPEN_PAREN yield_expr CLOSE_PAREN 20 | def f(): 21 | (yield) 22 | 23 | # OPEN_PAREN testlist_comp CLOSE_PAREN 24 | (x, a, q == 1) 25 | 26 | # OPEN_BRACKET CLOSE_BRACKET 27 | [] 28 | 29 | # OPEN_BRACKET testlist_comp CLOSE_BRACKET 30 | [1, 3, b, p == 1] 31 | 32 | # OPEN_BRACE CLOSE_BRACE 33 | {} 34 | 35 | # OPEN_BRACE dictorsetmaker CLOSE_BRACE 36 | {x : y for x, y in a} 37 | 38 | # dotted_name 39 | b.a 40 | 41 | # ELLIPSIS 42 | ... 43 | 44 | # name 45 | f 46 | 47 | # number 48 | 90 49 | 50 | # MINUS number 51 | -1 52 | 53 | # NONE 54 | None 55 | 56 | # STRING 57 | "12312313" 58 | 59 | # STRING STRING 60 | "1231231" "123151" 61 | -------------------------------------------------------------------------------- /.github/workflows/cd.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Set up Java 14 | uses: actions/setup-java@v3 15 | with: 16 | java-version: '11' 17 | distribution: 'adopt' 18 | 19 | - name: Setup Gradle 20 | uses: gradle/gradle-build-action@v2 21 | 22 | - name: Execute Gradle build 23 | run: ./gradlew build 24 | 25 | #After decoding the secret key, place the file in ~ /. Gradle/ secring.gpg 26 | - name: Decode 27 | run: | 28 | echo "${{secrets.GPG_PRIVATE_KEY}}" > ~/.gradle/secring.gpg.b64 29 | base64 -d ~/.gradle/secring.gpg.b64 > ~/.gradle/secring.gpg 30 | 31 | - name: Publish 32 | run: ./gradlew publish -Psigning.keyId=${{secrets.GPG_KEY_ID}} -Psigning.password=${{secrets.GPG_PASSPHRASE}} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg) 33 | env: 34 | OSSRH_USERNAME: ${{secrets.OSSRH_USERNAME}} 35 | OSSRH_PASSWORD: ${{secrets.OSSRH_PASSWORD}} 36 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/main/java/chapi/ast/antlr/CSharpParserBase.java: -------------------------------------------------------------------------------- 1 | package chapi.ast.antlr; 2 | 3 | import chapi.ast.antlr.CSharpParser; 4 | import org.antlr.v4.runtime.Parser; 5 | import org.antlr.v4.runtime.TokenStream; 6 | 7 | public abstract class CSharpParserBase extends Parser { 8 | protected CSharpParserBase(TokenStream input) { 9 | super(input); 10 | } 11 | 12 | protected boolean IsLocalVariableDeclaration() { 13 | try { 14 | CSharpParser.Local_variable_declarationContext local_var_decl = (CSharpParser.Local_variable_declarationContext) this._ctx; 15 | if (local_var_decl == null) { 16 | return true; 17 | } 18 | CSharpParser.Local_variable_typeContext local_variable_type = local_var_decl.local_variable_type(); 19 | if (local_variable_type == null) { 20 | return true; 21 | } 22 | if (local_variable_type.getText().equals("var")) { 23 | return false; 24 | } 25 | return true; 26 | } catch (Exception e){ 27 | return false; 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /chapi-ast-java/src/test/resources/bug/annotation/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.macro.mall.demo.controller; 2 | 3 | import com.macro.mall.common.api.CommonPage; 4 | import com.macro.mall.common.api.CommonResult; 5 | import com.macro.mall.demo.dto.PmsBrandDto; 6 | import com.macro.mall.demo.service.DemoService; 7 | import com.macro.mall.model.PmsBrand; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.validation.annotation.Validated; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | /** 16 | * 品牌管理示例controller 17 | * Created by macro on 2019/4/8. 18 | */ 19 | @Api(tags = "DemoController", description = "品牌管理示例接口") 20 | @Controller 21 | public class DemoController { 22 | @ApiOperation(value = "获取全部品牌列表") 23 | @RequestMapping(value = "/brand/listAll", method = RequestMethod.GET) 24 | @ResponseBody 25 | public CommonResult> getBrandList() { 26 | return CommonResult.success(demoService.listAllBrand()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapi-ast-cpp/src/test/resources/tequila/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Li Xin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file to set up TestFX correctly. 2 | # Adapted from https://github.com/TestFX/TestFX/wiki/Travis-CI 3 | 4 | # NOTE When updating, update https://stackoverflow.com/a/49116679/4126843 too 5 | # and the one from java-template-project 6 | 7 | language: java 8 | 9 | jdk: 10 | - openjdk8 11 | - oraclejdk11 12 | 13 | services: 14 | - xvfb 15 | 16 | before_install: 17 | - sudo apt update 18 | - sudo apt install openjfx 19 | - chmod +x ./gradlew 20 | - export DISPLAY=:99.0 21 | 22 | install: true 23 | 24 | before_script: 25 | - touch local.properties 26 | 27 | script: 28 | - ./gradlew check 29 | 30 | after_success: 31 | # Generate coverage report and upload to coveralls 32 | - ./gradlew check jacocoTestReport jacocoRootReports coveralls 33 | # Also upload to codecov 34 | - bash <(curl -s https://codecov.io/bash) 35 | 36 | before_cache: 37 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 38 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 39 | - rm -f $HOME/.gradle/caches/*/fileHashes/fileHashes.bin 40 | - rm -f $HOME/.gradle/caches/*/fileHashes/fileHashes.lock 41 | 42 | cache: 43 | directories: 44 | - $HOME/.gradle/caches/ 45 | - $HOME/.gradle/wrapper/ 46 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/InfrastructureLayer/MemDomainEventRepository.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using eCommerce.Helpers.Repository; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace eCommerce.InfrastructureLayer 9 | { 10 | public class MemDomainEventRepository : IDomainEventRepository 11 | { 12 | private List domainEvents = new List(); 13 | 14 | public void Add(TDomainEvent domainEvent) where TDomainEvent : DomainEvent 15 | { 16 | this.domainEvents.Add( 17 | new DomainEventRecord() 18 | { 19 | Created = domainEvent.Created, 20 | Type = domainEvent.Type, 21 | Args = domainEvent.Args.Select(kv => new KeyValuePair(kv.Key, kv.Value.ToString())).ToList(), 22 | CorrelationID = domainEvent.CorrelationID 23 | }); 24 | } 25 | 26 | public IEnumerable FindAll() 27 | { 28 | return this.domainEvents; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/varargslist.py: -------------------------------------------------------------------------------- 1 | # varargslist 2 | # : (vardef_parameters COMMA)? (varargs (COMMA vardef_parameters)? (COMMA varkwargs)? | varkwargs) COMMA? 3 | # | vardef_parameters COMMA? 4 | # ; 5 | # 6 | # vardef_parameters 7 | # : vardef_parameter (COMMA vardef_parameter)* 8 | # ; 9 | # 10 | # vardef_parameter 11 | # : name (ASSIGN test)? 12 | # ; 13 | # 14 | # varargs 15 | # : STAR name 16 | # ; 17 | # 18 | # varkwargs 19 | # : POWER name 20 | # ; 21 | 22 | # vardef_parameters COMMA 23 | # NAME COMMA 24 | lambda x,: 5 25 | 26 | # vardef_parameters COMMA 27 | # NAME COMMA STAR COMMA NAME COMMA 28 | lambda x, *, y,: 5 29 | 30 | # vardef_parameters 31 | # NAME COMMA STAR COMMA NAME ASSIGN test 32 | lambda x, *, y=7: 5 33 | 34 | # varargs 35 | lambda *y: 8 36 | 37 | # varargs COMMA vardef_parameters COMMA 38 | lambda *y, z: 8 39 | 40 | # vardef_parameters COMMA varargs COMMA vardef_parameters COMMA 41 | lambda a, b, *y, z: 8 42 | 43 | # vardef_parameters COMMA varargs COMMA vardef_parameters COMMA varkwargs 44 | lambda a, b, *y, z, **k: 8 45 | 46 | # varkwargs 47 | lambda **z: 8 48 | 49 | # vardef_parameters COMMA varkwargs 50 | lambda a, b, c, **k: 8 51 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Domain/DomainEventHandle.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Logging; 2 | using eCommerce.Helpers.Repository; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace eCommerce.Helpers.Domain 9 | { 10 | public class DomainEventHandle : Handles 11 | where TDomainEvent : DomainEvent 12 | { 13 | IDomainEventRepository domainEventRepository; 14 | IRequestCorrelationIdentifier requestCorrelationIdentifier; 15 | 16 | public DomainEventHandle(IDomainEventRepository domainEventRepository, 17 | IRequestCorrelationIdentifier requestCorrelationIdentifier) 18 | { 19 | this.domainEventRepository = domainEventRepository; 20 | this.requestCorrelationIdentifier = requestCorrelationIdentifier; 21 | } 22 | 23 | public void Handle(TDomainEvent @event) 24 | { 25 | @event.Flatten(); 26 | @event.CorrelationID = this.requestCorrelationIdentifier.CorrelationID; 27 | this.domainEventRepository.Add(@event); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Statement.ts: -------------------------------------------------------------------------------- 1 | let x: number = 10, y = 20; 2 | 3 | // If-else 4 | 5 | if (x > y) 6 | { 7 | console.log('x is greater than y.'); 8 | } 9 | else 10 | { 11 | console.log('x is less than or equal to y.'); //This will be executed 12 | } 13 | 14 | // Switch 15 | switch (x-y) { 16 | case 0: 17 | console.log("Result: 0"); 18 | break; 19 | case 5: 20 | console.log("Result: 5"); 21 | break; 22 | case 10: 23 | console.log("Result: 10"); 24 | break; 25 | } 26 | 27 | // For 28 | for (let i = 0; i < 3; i++) { 29 | console.log ("Block statement execution no." + i); 30 | } 31 | 32 | let str = "Hello World"; 33 | 34 | for (var char of str) { 35 | console.log(char); // prints chars: H e l l o W o r l d 36 | } 37 | 38 | let arr = [10, 20, 30, 40]; 39 | 40 | for (var index in arr) { 41 | console.log(index); // prints indexes: 0, 1, 2, 3 42 | 43 | console.log(arr[index]); // prints elements: 10, 20, 30, 40 44 | } 45 | 46 | // While 47 | let i: number = 2; 48 | do { 49 | console.log("Block statement execution no." + i ) 50 | i++; 51 | } while ( i < 4) 52 | 53 | while (i < 4) { 54 | console.log( "Block statement execution no." + i ) 55 | i++; 56 | } -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/expr.py: -------------------------------------------------------------------------------- 1 | # expr 2 | # : AWAIT? atom trailer* 3 | # | expr op=POWER expr 4 | # | op=(ADD | MINUS | NOT_OP) expr 5 | # | expr op=(STAR | DIV | MOD | IDIV | AT) expr 6 | # | expr op=(ADD | MINUS) expr 7 | # | expr op=(LEFT_SHIFT | RIGHT_SHIFT) expr 8 | # | expr op=AND_OP expr 9 | # | expr op=XOR expr 10 | # | expr op=OR_OP expr 11 | # ; 12 | 13 | # atom 14 | "123" 15 | 16 | # AWAIT atom 17 | await 5 18 | 19 | # atom trailer 20 | "1231".lower() 21 | 22 | # atom trailer trailer 23 | "1231".lower().upper() 24 | 25 | # AWAIT atom trailer trailer 26 | await "1231".lower().upper() 27 | 28 | # expr op=POWER expr op=POWER expr 29 | 2 ** 2 ** 3 30 | 31 | # ADD expr 32 | +6 33 | 34 | # MINUS expr 35 | -6 36 | 37 | # NOT_OP expr 38 | ~6 39 | 40 | # expr STAR expr 41 | 6 * 7 42 | 43 | # expr DIV expr 44 | 6 / 7 45 | 46 | # expr MOD expr 47 | 6 % 8 48 | 49 | # expr IDIV expr 50 | 6 // 7 51 | 52 | # expr AT expr 53 | 6 @ 2 54 | 55 | # expr ADD expr 56 | 6 + 1 57 | 58 | # expr MINUS expr 59 | 7 - 9 60 | 61 | # expr LEFT_SHIFT expr 62 | 8 << 9 63 | 64 | # expr RIGHT_SHIFT expr 65 | 4 >> 1 66 | 67 | # expr op=AND_OP expr 68 | 4 & 6 69 | 70 | # expr op=XOR expr 71 | 4 ^ 7 72 | 73 | # expr op=OR_OP expr 74 | 7 | 1 75 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Specification/Or.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace eCommerce.Helpers.Specification 8 | { 9 | public class Or : SpecificationBase 10 | { 11 | ISpecification left; 12 | ISpecification right; 13 | 14 | public Or( 15 | ISpecification left, 16 | ISpecification right) 17 | { 18 | this.left = left; 19 | this.right = right; 20 | } 21 | 22 | // OrSpecification 23 | public override Expression> SpecExpression 24 | { 25 | get 26 | { 27 | var objParam = Expression.Parameter(typeof(T), "obj"); 28 | 29 | var newExpr = Expression.Lambda>( 30 | Expression.OrElse( 31 | Expression.Invoke(left.SpecExpression, objParam), 32 | Expression.Invoke(right.SpecExpression, objParam) 33 | ), 34 | objParam 35 | ); 36 | 37 | return newExpr; 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce.WebService/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using Castle.Windsor; 2 | using eCommerce.WebService; 3 | using eCommerce.WebService.App_Start; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Web; 8 | using System.Web.Http; 9 | using System.Web.Mvc; 10 | using System.Web.Optimization; 11 | using System.Web.Routing; 12 | 13 | namespace eCommerce.WebService 14 | { 15 | public class WebApiApplication : System.Web.HttpApplication 16 | { 17 | private IWindsorContainer container; 18 | 19 | protected void Application_Start() 20 | { 21 | AreaRegistration.RegisterAllAreas(); 22 | WebApiConfig.Register(GlobalConfiguration.Configuration); 23 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 24 | RouteConfig.RegisterRoutes(RouteTable.Routes); 25 | MappingConfig.RegisterMapping(); 26 | 27 | container = new WindsorContainer(); 28 | BootstrapConfig.Register(this.container); 29 | } 30 | 31 | protected void Application_Stop() 32 | { 33 | if(this.container != null) 34 | { 35 | this.container.Dispose(); 36 | } 37 | } 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/Helpers/Specification/And.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace eCommerce.Helpers.Specification 8 | { 9 | public class And : SpecificationBase 10 | { 11 | ISpecification left; 12 | ISpecification right; 13 | 14 | public And( 15 | ISpecification left, 16 | ISpecification right) 17 | { 18 | this.left = left; 19 | this.right = right; 20 | } 21 | 22 | // AndSpecification 23 | public override Expression> SpecExpression 24 | { 25 | get 26 | { 27 | var objParam = Expression.Parameter(typeof(T), "obj"); 28 | 29 | var newExpr = Expression.Lambda>( 30 | Expression.AndAlso( 31 | Expression.Invoke(left.SpecExpression, objParam), 32 | Expression.Invoke(right.SpecExpression, objParam) 33 | ), 34 | objParam 35 | ); 36 | 37 | return newExpr; 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoAstListener.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.goast 2 | 3 | import chapi.ast.antlr.GoParser 4 | import chapi.ast.antlr.GoParserBaseListener 5 | import chapi.domain.core.CodeProperty 6 | 7 | open class GoAstListener : GoParserBaseListener() { 8 | fun getStructNameFromReceiver(parameters: GoParser.ParametersContext?): String { 9 | parameters?.parameterDecl()?.forEach { 10 | var typeType = it.type_().text 11 | if (typeType.startsWith("*")) { 12 | typeType = typeType.removePrefix("*") 13 | } 14 | 15 | return typeType 16 | } 17 | 18 | return "" 19 | } 20 | 21 | protected fun buildReturnTypeFromSignature(signatureContext: GoParser.SignatureContext?): List { 22 | var returns: List = listOf() 23 | 24 | signatureContext?.result()?.let { result -> 25 | result.parameters()?.parameterDecl()?.forEach { 26 | returns += CodeProperty(TypeType = it.text, TypeValue = "") 27 | } 28 | 29 | if (result.type_() != null) { 30 | returns += CodeProperty(TypeType = result.type_().text, TypeValue = "") 31 | } 32 | } 33 | 34 | return returns; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/InfrastructureLayer/MemoryRepository.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.Helpers.Domain; 2 | using eCommerce.Helpers.Repository; 3 | using eCommerce.Helpers.Specification; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace eCommerce.InfrastructureLayer 10 | { 11 | public class MemoryRepository : IRepository 12 | where TEntity : IAggregateRoot 13 | { 14 | protected static List entities = new List(); 15 | 16 | public TEntity FindById(Guid id) 17 | { 18 | return entities.Where(x => x.Id == id).FirstOrDefault(); 19 | } 20 | 21 | public TEntity FindOne(ISpecification spec) 22 | { 23 | return entities.Where(spec.IsSatisfiedBy).FirstOrDefault(); 24 | } 25 | 26 | public IEnumerable Find(ISpecification spec) 27 | { 28 | return entities.Where(spec.IsSatisfiedBy); 29 | } 30 | 31 | public void Add(TEntity entity) 32 | { 33 | entities.Add(entity); 34 | } 35 | 36 | public void Remove(TEntity entity) 37 | { 38 | entities.Remove(entity); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/import_stmt.py: -------------------------------------------------------------------------------- 1 | 2 | # First, check this one 3 | # import_stmt: IMPORT dotted_as_names 4 | # dotted_as_names: dotted_as_name (COMMA dotted_as_name)*; 5 | # dotted_as_name: dotted_name (AS NAME)?; 6 | 7 | # IMPORT dotted_name 8 | import collections.abc 9 | 10 | # IMPORT dotted_name AS NAME 11 | import collections.abc as ss 12 | 13 | # IMPORT dotted_name AS NAME COMMA dotted_name 14 | import collections.abc as ss, itertools 15 | 16 | # Then check this 17 | # import_from: FROM ((DOT | ELLIPSIS)* dotted_name | (DOT | ELLIPSIS)+) 18 | # IMPORT (STAR | OPEN_PAREN import_as_names CLOSE_PAREN | import_as_names); 19 | # import_as_names: import_as_name (COMMA import_as_name)*; 20 | # import_as_name: NAME (AS NAME)?; 21 | 22 | # FROM dotted_name IMPORT import_as_name 23 | from classdef import bar as b 24 | 25 | # FROM DOT IMPORT import_as_name 26 | from . import bar 27 | 28 | # FROM DOT DOT DOT IMPORT import_as_name 29 | from . . . import bar 30 | 31 | # FROM DOT dotted_name IMPORT import_as_name 32 | from .classdef import bar 33 | 34 | # FROM dotted_name IMPORT STAR 35 | from sys import * 36 | 37 | # FROM dotted_name IMPORT import_as_name COMMA import_as_name 38 | from collections import bar, baz 39 | 40 | # FROM dotted_name IMPORT OPEN_PAREN import_as_name CLOSE_PAREN 41 | from collections import (bar) 42 | -------------------------------------------------------------------------------- /chapi-ast-python/src/test/resources/grammar/expr_stmt.py: -------------------------------------------------------------------------------- 1 | # expr_stmt: testlist_star_expr assign_part? 2 | # 3 | # testlist_star_expr : (test | star_expr) (COMMA (test | star_expr))* COMMA? 4 | # 5 | # assign_part 6 | # : (ASSIGN testlist_star_expr)* (ASSIGN yield_expr)? 7 | # | COLON test (ASSIGN testlist)? 8 | # | op=( ADD_ASSIGN 9 | # | SUB_ASSIGN 10 | # | MULT_ASSIGN 11 | # | AT_ASSIGN 12 | # | DIV_ASSIGN 13 | # | MOD_ASSIGN 14 | # | AND_ASSIGN 15 | # | OR_ASSIGN 16 | # | XOR_ASSIGN 17 | # | LEFT_SHIFT_ASSIGN 18 | # | RIGHT_SHIFT_ASSIGN 19 | # | POWER_ASSIGN 20 | # | IDIV_ASSIGN 21 | # ) 22 | # (yield_expr | testlist) 23 | # ; 24 | 25 | # Yield tests (should not be used outside the function) 26 | def f(): 27 | # test ASSIGN yield_expr 28 | x = yield 29 | 30 | # test COMMA test COMMA ASSIGN test COMMA star_expr ASSIGN yield_expr 31 | x, [*t], = y, *z = yield 32 | 33 | # test '+=' yield_expr 34 | x += yield 35 | 36 | # test ASSIGN testlist_star_expr 37 | z = 1, *y 38 | 39 | # test ASSIGN test COMMA test ASSIGN test COMMA star_expr COMMA 40 | x = y, a = z, *q, 41 | 42 | # test COLON test 43 | x: int 44 | 45 | # COLON test ASSIGN testlist 46 | x: int = 8 47 | 48 | # test '-=' testlist 49 | x -= 9 50 | -------------------------------------------------------------------------------- /chapi-ast-scala/README.md: -------------------------------------------------------------------------------- 1 | # Scala 2 | 3 | 4 | ## Play API Routes 5 | 6 | [RoutesFileParser.scala](https://github.com/playframework/playframework/blob/main/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/RoutesFileParser.scala) 7 | 8 | 9 | 10 | ```scala 11 | private[routes] class RoutesFileParser extends JavaTokenParsers { 12 | override def skipWhitespace = false 13 | override val whiteSpace = """[ \t]+""".r 14 | 15 | def EOF: util.matching.Regex = "\\z".r 16 | 17 | def namedError[A](p: Parser[A], msg: String): Parser[A] = Parser[A] { i => 18 | p(i) match { 19 | case Failure(_, in) => Failure(msg, in) 20 | case o => o 21 | } 22 | } 23 | 24 | def several[T](p: => Parser[T]): Parser[List[T]] = Parser { in => 25 | import scala.collection.mutable.ListBuffer 26 | val elems = new ListBuffer[T] 27 | def continue(in: Input): ParseResult[List[T]] = { 28 | val p0 = p // avoid repeatedly re-evaluating by-name parser 29 | @scala.annotation.tailrec 30 | def applyp(in0: Input): ParseResult[List[T]] = p0(in0) match { 31 | case Success(x, rest) => 32 | elems += x; applyp(rest) 33 | case Failure(_, _) => Success(elems.toList, in0) 34 | case err: Error => err 35 | } 36 | applyp(in) 37 | } 38 | continue(in) 39 | } 40 | 41 | ``` 42 | -------------------------------------------------------------------------------- /chapi-ast-kotlin/src/test/kotlin/chapi/ast/kotlinast/KotlinAnalyserTest.kt: -------------------------------------------------------------------------------- 1 | package chapi.ast.kotlinast 2 | 3 | import kotlinx.coroutines.async 4 | import kotlinx.coroutines.awaitAll 5 | import kotlinx.coroutines.runBlocking 6 | import org.junit.jupiter.api.Test 7 | import java.io.BufferedReader 8 | import java.io.File 9 | import java.nio.file.Paths 10 | import kotlin.test.assertTrue 11 | 12 | internal class KotlinAnalyserTest { 13 | // add compatibility tests for Kotlin with psi?? https://github.com/JetBrains/kotlin/tree/master/compiler/testData/psi 14 | 15 | private val analyser = KotlinAnalyser() 16 | private val modulePath: File by lazy { Paths.get("").toFile().absoluteFile } 17 | private val kotlinFiles: Sequence by lazy { modulePath.walk().filter { it.isFile && it.extension == "kt" } } 18 | 19 | @Test 20 | fun `should not crash for grammar file in basic identifier mode`() = runBlocking { 21 | val codeContainers = kotlinFiles 22 | .map { 23 | async { analyser.analysis(it.bufferedReader().use(BufferedReader::readText), it.name) } 24 | } 25 | .toList().awaitAll() 26 | .onEach { 27 | println("${it.FullName}, contains ${it.DataStructures.size} data structures") 28 | } 29 | 30 | assertTrue { codeContainers.isNotEmpty() } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapi-ast-typescript/src/test/resources/grammar/Interface.ts: -------------------------------------------------------------------------------- 1 | export interface IPerson { 2 | name: string; 3 | gender: string; 4 | } 5 | 6 | interface IEmployee extends IPerson{ 7 | empCode: number; 8 | readonly empName: string; 9 | empDept?:string; 10 | getSalary: (number) => number; // arrow function 11 | getManagerName(number): string; 12 | } 13 | 14 | 15 | class Employee implements IEmployee { 16 | empCode: number; 17 | name: string; 18 | 19 | constructor(code: number, name: string) { 20 | this.empCode = code; 21 | this.name = name; 22 | } 23 | 24 | getSalary(empCode:number):number { 25 | return 20000; 26 | } 27 | } 28 | // Interface As type 29 | interface KeyPair { 30 | key: number; 31 | value: string; 32 | } 33 | 34 | let kv1: KeyPair = { key:1, value:"Steve" }; // OK 35 | 36 | let kv2: KeyPair = { key:1, val:"Steve" }; // Compiler Error: 'val' doesn't exist in type 'KeyPair' 37 | 38 | let kv3: KeyPair = { key:1, value:100 }; // Compiler Error 39 | 40 | //Interface for Array Type 41 | 42 | interface NumList { 43 | [index:string]:string 44 | } 45 | 46 | let numArr: NumList = [1, 2, 3]; 47 | numArr[0]; 48 | numArr[1]; 49 | 50 | interface IStringList { 51 | [index:string]:string 52 | } 53 | 54 | let strArr : IStringList; 55 | strArr["TS"] = "TypeScript"; 56 | strArr["JS"] = "JavaScript"; 57 | -------------------------------------------------------------------------------- /chapi-ast-scala/src/test/resources/grammar/class.scala: -------------------------------------------------------------------------------- 1 | package xxx.yy.zz.aa.bb.commons.transformation 2 | import xxx.yy.zz.aa.bb.commons.constants.Forms 3 | import xxx.yy.zz.aa.core.configuration.KingTransformation 4 | import xxx.yy.zz.aa.core.engine.ProcessStatus 5 | import xxx.yy.zz.aa.core.transformation.TransformationTrait 6 | import org.apache.spark.sql.{DataFrame, Row, functions} 7 | import org.apache.spark.sql.functions._ 8 | 9 | class AddingHoldingFlag1(val transformation: KingTransformation) extends TransformationTrait{ 10 | def runTransformation: DataFrame = { 11 | val previousDF = ProcessStatus.components(transformation.previous.get(0)) 12 | val outPutDataframe = addingHoldingFlag1(previousDF) 13 | outPutDataframe 14 | } 15 | def addingHoldingFlag1(previousDF: DataFrame): DataFrame = { 16 | // adding holding flag field when a customer has at least one account valid and is in scope for CS 17 | val addingFlag = previousDF 18 | .withColumn(Forms.HOLD_1, when(col(Forms.capamer).contains("WER") && col(Forms.FLCOUNT) === 1, lit("YES")) 19 | .otherwise(lit("NO"))) 20 | addingFlag 21 | } 22 | 23 | def concatTest() = { 24 | val a = "test" + "test" + "test" 25 | val schema = StructType(Seq( StructField(Fields.Alpha + "_trc", StringType), StructField(Fields.Beta + "_trc", DecimalType(10,0)), StructField(Fields.Gamma, StringType) )) 26 | } 27 | } -------------------------------------------------------------------------------- /chapi-parser-toml/src/main/kotlin/chapi/parser/toml/TomlAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.parser.toml 2 | 3 | import chapi.domain.core.CodeContainer 4 | import chapi.parser.Analyser 5 | import org.antlr.v4.runtime.CharStreams 6 | import org.antlr.v4.runtime.CommonTokenStream 7 | import org.antlr.v4.runtime.tree.ParseTreeWalker 8 | 9 | /** 10 | * The [TomlAnalyser] class is responsible for parsing TOML (Tom's Obvious, Minimal Language) code and converting it into a 11 | * [CodeContainer] object. 12 | * 13 | * Example usage: 14 | * ```kotlin 15 | * val container = TomlAnalyser().analysis("title = "TOML Example"") 16 | * assert(container.Fields.size == 1) 17 | * assert(container.Fields[0].TypeKey == "title") 18 | * assert(container.Fields[0].TypeValue == "TOML Example") 19 | * assert(container.Fields[0].TypeValue == "String") 20 | * ``` 21 | * 22 | */ 23 | class TomlAnalyser : Analyser { 24 | override fun analysis(code: String, filePath: String): CodeContainer { 25 | val context = this.parse(code).document() 26 | val listener = TomlListener(filePath = filePath) 27 | ParseTreeWalker().walk(listener, context) 28 | return listener.getNodeInfo() 29 | } 30 | 31 | private fun parse(str: String): TomlParser = 32 | CharStreams.fromString(str) 33 | .let(::TomlLexer) 34 | .let(::CommonTokenStream) 35 | .let(::TomlParser) 36 | 37 | } 38 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Tax/CountryTax.cs: -------------------------------------------------------------------------------- 1 | using eCommerce.DomainModelLayer.Countries; 2 | using eCommerce.Helpers.Domain; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace eCommerce.DomainModelLayer.Tax 9 | { 10 | public class CountryTax : IAggregateRoot 11 | { 12 | public virtual Guid Id { get; protected set; } 13 | public virtual Country Country { get; protected set; } 14 | public virtual decimal Percentage { get; protected set; } 15 | public virtual TaxType Type { get; protected set; } 16 | 17 | public static CountryTax Create(TaxType type, Country country, decimal percentage) 18 | { 19 | return Create(Guid.NewGuid(), type, country, percentage); 20 | } 21 | 22 | public static CountryTax Create(Guid id, TaxType type, Country country, decimal percentage) 23 | { 24 | CountryTax countryTax = new CountryTax() 25 | { 26 | Id = id, 27 | Country = country, 28 | Percentage = percentage, 29 | Type = type 30 | }; 31 | 32 | DomainEvents.Raise(new CountryTaxCreated() { CountryTax = countryTax }); 33 | 34 | return countryTax; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /chapi-domain/src/main/kotlin/chapi/domain/core/CodeMember.kt: -------------------------------------------------------------------------------- 1 | package chapi.domain.core 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CodeMember( 7 | var ID: String = "", 8 | var FileID: String = "", 9 | var DataStructID: String = "", 10 | var AliasPackage: String = "", 11 | var Name: String = "", 12 | var Type: String = "", 13 | var StructureNodes: List = listOf(), 14 | var FunctionNodes: List = listOf(), 15 | var Namespace: List = listOf(), 16 | var Position: CodePosition = CodePosition() 17 | ) { 18 | fun buildMemberId() { 19 | val isDefaultFunction = this.DataStructID == "default" 20 | when { 21 | isDefaultFunction -> { 22 | for (node in this.FunctionNodes) { 23 | this.ID = this.AliasPackage + ":" + node.Name 24 | } 25 | } 26 | else -> { 27 | var packageName = this.FileID 28 | if (this.FileID != this.AliasPackage) { 29 | packageName = this.FileID + "|" + this.AliasPackage 30 | } 31 | if (this.FileID == "" && this.AliasPackage != "") { 32 | packageName = this.AliasPackage 33 | } 34 | 35 | this.ID = packageName + "::" + this.DataStructID 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /chapi-parser-cmake/src/main/kotlin/chapi/parser/cmake/CMakeAnalyser.kt: -------------------------------------------------------------------------------- 1 | package chapi.parser.cmake 2 | 3 | import chapi.domain.core.CodeContainer 4 | import chapi.parser.Analyser 5 | import org.antlr.v4.runtime.CharStreams 6 | import org.antlr.v4.runtime.CommonTokenStream 7 | import org.antlr.v4.runtime.tree.ParseTreeWalker 8 | 9 | /** 10 | * The `CMakeAnalyser` class is a CMakelists.txt parser that implements the `Analyser` interface. 11 | * It provides a method to analyze the given code and extract relevant information from it. 12 | * 13 | * ```kotlin 14 | * val cmakeCode = """ 15 | * cmake_minimum_required(VERSION 3.0) 16 | * project(HelloWorld) 17 | * add_executable(HelloWorld HelloWorld.cpp) 18 | * """.trimIndent() 19 | * val container = CMakeAnalyser().analysis(cmakeCode, "CMakeLists.txt") 20 | * println(container.Fields.size) // 3 21 | * ``` 22 | */ 23 | class CMakeAnalyser : Analyser { 24 | override fun analysis(code: String, filePath: String): CodeContainer { 25 | val context = this.parse(code).file_() 26 | val listener = CMakeBasicListener(filePath = filePath) 27 | ParseTreeWalker().walk(listener, context) 28 | return listener.getNodeInfo() 29 | } 30 | 31 | private fun parse(str: String): CMakeParser = 32 | CharStreams.fromString(str) 33 | .let(::CMakeLexer) 34 | .let(::CommonTokenStream) 35 | .let(::CMakeParser) 36 | 37 | } 38 | -------------------------------------------------------------------------------- /chapi-ast-csharp/src/test/resources/Domain-Driven-Design/eCommerce/DomainModelLayer/Customers/CustomerCheckedOutHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using eCommerce.Helpers.Domain; 6 | using eCommerce.DomainModelLayer.Email; 7 | 8 | namespace eCommerce.DomainModelLayer.Customers 9 | { 10 | public class CustomerCheckedOutHandle : Handles 11 | { 12 | readonly IEmailDispatcher emailDispatcher; 13 | readonly IEmailGenerator emailGenerator; 14 | readonly ICustomerRepository customerRepository; 15 | 16 | public CustomerCheckedOutHandle(IEmailGenerator emailGenerator, 17 | IEmailDispatcher emailSender, ICustomerRepository customerRepository) 18 | { 19 | this.emailDispatcher = emailSender; 20 | this.emailGenerator = emailGenerator; 21 | this.customerRepository = customerRepository; 22 | } 23 | 24 | public void Handle(CustomerCheckedOut args) 25 | { 26 | Customer customer = this.customerRepository.FindById(args.Purchase.CustomerId); 27 | 28 | this.emailDispatcher.Dispatch( 29 | this.emailGenerator.Generate(customer, EmailTemplate.PurchaseMade) 30 | ); 31 | 32 | //send notifications, update third party systems, etc 33 | } 34 | } 35 | } 36 | --------------------------------------------------------------------------------