diff --git a/ast/src/lang/queries/cpp.rs b/ast/src/lang/queries/cpp.rs index 9409fb928..de80211ee 100644 --- a/ast/src/lang/queries/cpp.rs +++ b/ast/src/lang/queries/cpp.rs @@ -117,14 +117,12 @@ impl Stack for Cpp { fn class_definition_query(&self) -> String { format!( r#" - (translation_unit - (class_specifier - name: (type_identifier)@{CLASS_NAME} - (base_class_clause - (type_identifier)@{CLASS_PARENT} - )? - )@{CLASS_DEFINITION} - ) + (class_specifier + name: (type_identifier)@{CLASS_NAME} + (base_class_clause + (type_identifier)@{CLASS_PARENT} + )? + )@{CLASS_DEFINITION} "# ) } diff --git a/ast/src/lang/queries/kotlin.rs b/ast/src/lang/queries/kotlin.rs index 3fe367da0..530537b19 100644 --- a/ast/src/lang/queries/kotlin.rs +++ b/ast/src/lang/queries/kotlin.rs @@ -91,7 +91,17 @@ impl Stack for Kotlin { (user_type)@{CLASS_PARENT} ) )? - + + )@{CLASS_DEFINITION} + (object_declaration + (modifiers (annotation)*)? @{ATTRIBUTES} + (type_identifier)@{CLASS_NAME} + (delegation_specifier + (constructor_invocation + (user_type)@{CLASS_PARENT} + ) + )? + )@{CLASS_DEFINITION} "# ) @@ -131,6 +141,19 @@ impl Stack for Kotlin { ) ) + ( + (object_declaration + (type_identifier)? @{PARENT_TYPE} + (class_body + (function_declaration + (modifiers (annotation)*)? @{ATTRIBUTES} + (simple_identifier) @{FUNCTION_NAME} + (function_value_parameters) @{ARGUMENTS} + ) @{FUNCTION_DEFINITION} + ) + ) + ) + ( (function_declaration (modifiers (annotation)*)? @{ATTRIBUTES} @@ -261,6 +284,9 @@ impl Stack for Kotlin { Some(format!( "(class_declaration (type_identifier) @{STRUCT_NAME} + ) @{STRUCT} + (object_declaration + (type_identifier) @{STRUCT_NAME} ) @{STRUCT}" )) } diff --git a/ast/src/testing/coverage/cpp.rs b/ast/src/testing/coverage/cpp.rs index edd006181..f08a186c3 100644 --- a/ast/src/testing/coverage/cpp.rs +++ b/ast/src/testing/coverage/cpp.rs @@ -71,7 +71,7 @@ async fn test_btreemap_graph_structure() -> Result<()> { assert_eq!(endpoints.len(), 3); let functions = graph.find_nodes_by_type(NodeType::Function); - assert_eq!(functions.len(), 110); + assert_eq!(functions.len(), 112); let unit_tests = graph.find_nodes_by_type(NodeType::UnitTest); assert_eq!(unit_tests.len(), 8); @@ -83,7 +83,7 @@ async fn test_btreemap_graph_structure() -> Result<()> { assert_eq!(e2e_tests.len(), 0); let classes = graph.find_nodes_by_type(NodeType::Class); - assert_eq!(classes.len(), 1); + assert_eq!(classes.len(), 3); let data_models = graph.find_nodes_by_type(NodeType::DataModel); assert_eq!(data_models.len(), 1); @@ -111,7 +111,7 @@ async fn test_btreemap_test_to_function_edges() -> Result<()> { assert_eq!(calls_edges, 13); let contains_edges = graph.count_edges_of_type(EdgeType::Contains); - assert_eq!(contains_edges, 226); + assert_eq!(contains_edges, 232); let handler_edges = graph.count_edges_of_type(EdgeType::Handler); assert_eq!(handler_edges, 3); diff --git a/ast/src/testing/coverage/kotlin.rs b/ast/src/testing/coverage/kotlin.rs index 2272edcf9..80b13a2ca 100644 --- a/ast/src/testing/coverage/kotlin.rs +++ b/ast/src/testing/coverage/kotlin.rs @@ -83,10 +83,10 @@ async fn test_btreemap_graph_structure() -> Result<()> { assert_eq!(e2e_tests.len(), 0); let classes = graph.find_nodes_by_type(NodeType::Class); - assert_eq!(classes.len(), 16); + assert_eq!(classes.len(), 18); let data_models = graph.find_nodes_by_type(NodeType::DataModel); - assert_eq!(data_models.len(), 9); + assert_eq!(data_models.len(), 10); let traits = graph.find_nodes_by_type(NodeType::Trait); assert_eq!(traits.len(), 0); @@ -111,7 +111,7 @@ async fn test_btreemap_test_to_function_edges() -> Result<()> { assert_eq!(calls_edges, 28); let contains_edges = graph.count_edges_of_type(EdgeType::Contains); - assert_eq!(contains_edges, 219); + assert_eq!(contains_edges, 222); let handler_edges = graph.count_edges_of_type(EdgeType::Handler); assert_eq!(handler_edges, 0); diff --git a/ast/src/testing/cpp/web_api/config.hpp b/ast/src/testing/cpp/web_api/config.hpp new file mode 100644 index 000000000..c01581523 --- /dev/null +++ b/ast/src/testing/cpp/web_api/config.hpp @@ -0,0 +1,23 @@ +// @ast node: Class "Config" +// @ast node: Function "getVersion" +// @ast node: Class "Wrapper" +// @ast node: Function "getValue" +#pragma once +#include + +namespace app { +class Config { +public: + std::string getVersion() { return version; } +private: + std::string version = "1.0"; +}; +} + +template +class Wrapper { +public: + T getValue() { return value; } +private: + T value; +}; diff --git a/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/data/models/UserModels.kt b/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/data/models/UserModels.kt index 94e070bec..1a730e20f 100644 --- a/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/data/models/UserModels.kt +++ b/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/data/models/UserModels.kt @@ -1,11 +1,13 @@ package com.kotlintestapp.data.models // @ast node: Class "ApiResult" // @ast node: Class "Error" +// @ast node: Class "Loading" // @ast node: Class "Success" // @ast node: Class "User" // @ast node: Class "UserRole" // @ast node: DataModel "ApiResult" // @ast node: DataModel "Error" +// @ast node: DataModel "Loading" // @ast node: DataModel "Success" // @ast node: DataModel "User" // @ast node: DataModel "UserRole" diff --git a/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/viewModels/PersonViewModel.kt b/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/viewModels/PersonViewModel.kt index 2c7bb6162..3c9bf32e2 100644 --- a/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/viewModels/PersonViewModel.kt +++ b/ast/src/testing/kotlin/app/src/main/java/com/kotlintestapp/viewModels/PersonViewModel.kt @@ -1,4 +1,6 @@ package com.kotlintestapp.viewModels +// @ast node: Class "ApiClient" +// @ast edge: Operand -> Function "fetchPeople" "PersonViewModel.kt" // @ast node: Class "PersonViewModel" // @ast edge: Operand -> Function "fetchAndStorePersons" "PersonViewModel.kt" // @ast edge: Operand -> Function "fetchPersonsFromApi" "PersonViewModel.kt" diff --git a/cli/tests/cli/cpp.rs b/cli/tests/cli/cpp.rs index 165f239fd..e0449bb16 100644 --- a/cli/tests/cli/cpp.rs +++ b/cli/tests/cli/cpp.rs @@ -38,8 +38,8 @@ fn parse_stats_cpp_dir() { assert_eq!(out.exit_code, 0, "stderr: {}", out.stderr); assert!(out.stdout.contains("Endpoint 3"), "stdout: {}", out.stdout); - assert!(out.stdout.contains("Function 110"), "stdout: {}", out.stdout); - assert!(out.stdout.contains("Class 1"), "stdout: {}", out.stdout); + assert!(out.stdout.contains("Function 112"), "stdout: {}", out.stdout); + assert!(out.stdout.contains("Class 3"), "stdout: {}", out.stdout); } // ── search ──────────────────────────────────────────────────────────────────── diff --git a/cli/tests/cli/kotlin.rs b/cli/tests/cli/kotlin.rs index 59ef20fc0..6dffaf03d 100644 --- a/cli/tests/cli/kotlin.rs +++ b/cli/tests/cli/kotlin.rs @@ -43,7 +43,7 @@ fn parse_stats_kotlin_dir() { let out = run_stakgraph(&["--stats", &dir]); assert_eq!(out.exit_code, 0, "stderr: {}", out.stderr); - assert!(out.stdout.contains("Class 16"), "stdout: {}", out.stdout); + assert!(out.stdout.contains("Class 18"), "stdout: {}", out.stdout); assert!(out.stdout.contains("Function 27"), "stdout: {}", out.stdout); assert!(out.stdout.contains("Request 5"), "stdout: {}", out.stdout); assert!(out.stdout.contains("UnitTest 3"), "stdout: {}", out.stdout);