From 5fd994cf0cb2003d167973bc5c72476faa4103b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Fabianski?= Date: Mon, 29 Jan 2024 10:52:12 +0100 Subject: [PATCH] feat: unanchored class declaration (#1478) feat: unanchor class declaration by default --- .../java/.snapshots/TestPattern-catch_types_is_a_container_type | 2 +- .../.snapshots/TestPattern-method_params_is_a_container_type | 2 +- internal/languages/java/pattern/pattern.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/languages/java/.snapshots/TestPattern-catch_types_is_a_container_type b/internal/languages/java/.snapshots/TestPattern-catch_types_is_a_container_type index b4e75a0c9..87c9810b1 100644 --- a/internal/languages/java/.snapshots/TestPattern-catch_types_is_a_container_type +++ b/internal/languages/java/.snapshots/TestPattern-catch_types_is_a_container_type @@ -1,5 +1,5 @@ (*builder.Result)({ - Query: (string) (len=334) "([(class_declaration . name: (_) . [(class_body [(method_declaration . [ (void_type )] @param1 . [ (identifier )] @param2 . [ (formal_parameters )] . [(block [(try_statement [ (block )] [(catch_clause . [(catch_formal_parameter . [(catch_type (_) @match)] . [ (identifier )] @param3 .)] . [ (block )] .)])] )] .)] )] .)] @root)", + Query: (string) (len=328) "([(class_declaration name: (_) [(class_body [(method_declaration . [ (void_type )] @param1 . [ (identifier )] @param2 . [ (formal_parameters )] . [(block [(try_statement [ (block )] [(catch_clause . [(catch_formal_parameter . [(catch_type (_) @match)] . [ (identifier )] @param3 .)] . [ (block )] .)])] )] .)] )])] @root)", VariableNames: ([]string) (len=1) { (string) (len=1) "_" }, diff --git a/internal/languages/java/.snapshots/TestPattern-method_params_is_a_container_type b/internal/languages/java/.snapshots/TestPattern-method_params_is_a_container_type index b28c5b329..15080fda8 100644 --- a/internal/languages/java/.snapshots/TestPattern-method_params_is_a_container_type +++ b/internal/languages/java/.snapshots/TestPattern-method_params_is_a_container_type @@ -1,5 +1,5 @@ (*builder.Result)({ - Query: (string) (len=196) "([(class_declaration . name: (_) . [(class_body [(method_declaration . [ (void_type )] @param1 . [ (identifier )] @param2 . [(formal_parameters . (_) @match . )] . [ (block )] .)] )] .)] @root)", + Query: (string) (len=190) "([(class_declaration name: (_) [(class_body [(method_declaration . [ (void_type )] @param1 . [ (identifier )] @param2 . [(formal_parameters . (_) @match . )] . [ (block )] .)] )])] @root)", VariableNames: ([]string) (len=1) { (string) (len=1) "_" }, diff --git a/internal/languages/java/pattern/pattern.go b/internal/languages/java/pattern/pattern.go index 9e3f08446..65fca7f21 100644 --- a/internal/languages/java/pattern/pattern.go +++ b/internal/languages/java/pattern/pattern.go @@ -101,7 +101,7 @@ func (*Pattern) IsAnchored(node *tree.Node) (bool, bool) { // function block // lambda () -> {} block // try {} catch () {} - unAnchored := []string{"class_body", "block", "try_statement", "catch_type", "resource_specification"} + unAnchored := []string{"class_declaration", "class_body", "block", "try_statement", "catch_type", "resource_specification"} isAnchored := !slices.Contains(unAnchored, parent.Type()) return isAnchored, isAnchored