44from JABWrapper .jab_wrapper import JavaWindow
55from robocorp_ls_core .robotframework_log import get_logger
66
7+ from robocorp_code .inspector .java .robocorp_java ._inspector import ColletedTreeTypedDict
8+
79log = get_logger (__name__ )
810
911JavaWindowInfoTypedDict = TypedDict (
1012 "JavaWindowInfoTypedDict" ,
1113 {
12- # Same as JavaWindow
1314 "pid" : int ,
1415 "hwnd" : int ,
1516 "title" : str ,
3233 },
3334)
3435
35- LocatorTreeInfoTypedDict = TypedDict (
36- "LocatorTreeInfoTypedDict" ,
37- {"nodes" : List [LocatorNodeInfoTypedDict ]},
38- )
36+
37+ class MatchesAndHierarchyTypedDict (TypedDict ):
38+ # A list with the nodes matched (these are the ones that the
39+ # locator matched)
40+ matched_paths : List [str ]
41+ # This includes all the entries found along with the full hierarchy
42+ # to reach the matched entries.
43+ hierarchy : List [LocatorNodeInfoTypedDict ]
3944
4045
4146def to_window_info (java_window : JavaWindow ) -> JavaWindowInfoTypedDict :
@@ -52,6 +57,18 @@ def to_locator_info(context_node: ContextNode) -> LocatorNodeInfoTypedDict:
5257 return cast (LocatorNodeInfoTypedDict , ret )
5358
5459
60+ def to_matches_and_hierarchy (
61+ matches_and_hierarchy : ColletedTreeTypedDict ,
62+ ) -> MatchesAndHierarchyTypedDict :
63+ matches = (
64+ [str (matches_and_hierarchy ["matches" ])]
65+ if type (matches_and_hierarchy ["matches" ]) == ContextNode
66+ else [str (match ) for match in matches_and_hierarchy ["matches" ]]
67+ )
68+ hierarchy = [to_locator_info (node ) for node in matches_and_hierarchy ["tree" ]]
69+ return {"matches" : matches , "hierarchy" : hierarchy }
70+
71+
5572class JavaInspector :
5673 def __init__ (self ):
5774 from robocorp_code .inspector .java .robocorp_java ._inspector import (
@@ -66,8 +83,10 @@ def list_windows(self) -> List[JavaWindowInfoTypedDict]:
6683
6784 def collect_tree (
6885 self , window : str , search_depth : int = 8 , locator : Optional [str ] = None
69- ) -> LocatorTreeInfoTypedDict :
86+ ) -> MatchesAndHierarchyTypedDict :
7087 log .info (f"Collect tree from locator: { locator } " )
7188
72- tree = self ._inspector .collect_tree (window , search_depth , locator )
73- return [to_locator_info (node ) for node in tree ]
89+ matches_and_hierarchy = self ._inspector .collect_tree (
90+ window , search_depth , locator
91+ )
92+ return to_matches_and_hierarchy (matches_and_hierarchy )
0 commit comments