Skip to content

Commit b140267

Browse files
committed
fixs
1 parent 8002d8d commit b140267

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

api/analyzers/java/analyzer.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ def get_entity_docstring(self, node: Node) -> Optional[str]:
3838
if node.prev_sibling.type == "block_comment":
3939
return node.prev_sibling.text.decode('utf-8')
4040
return None
41-
raise ValueError(f"Unknown entity type: {node.type}")
42-
43-
def find_calls(self, method: Entity):
44-
query = self.language.query("(method_invocation) @reference.call")
45-
captures = query.captures(method.node)
46-
if 'reference.call' in captures:
47-
for caller in captures['reference.call']:
48-
method.add_symbol("call", caller)
41+
raise ValueError(f"Unknown entity type: {node.type}")
4942

5043
def get_entity_types(self) -> list[str]:
5144
return ['class_declaration', 'interface_declaration', 'enum_declaration', 'method_declaration', 'constructor_declaration']
@@ -69,7 +62,18 @@ def add_symbols(self, entity: Entity) -> None:
6962
for interface in extends_captures['type']:
7063
entity.add_symbol("extend_interface", interface)
7164
elif entity.node.type in ['method_declaration', 'constructor_declaration']:
72-
self.find_calls(entity)
65+
query = self.language.query("(method_invocation) @reference.call")
66+
captures = query.captures(entity.node)
67+
if 'reference.call' in captures:
68+
for caller in captures['reference.call']:
69+
entity.add_symbol("call", caller)
70+
if entity.node.type == 'method_declaration':
71+
query = self.language.query("(formal_parameters (formal_parameter type: (_) @parameter))")
72+
captures = query.captures(entity.node)
73+
if 'parameter' in captures:
74+
for parameter in captures['parameter']:
75+
entity.add_symbol("parameters", parameter)
76+
entity.add_symbol("return_type", entity.node.child_by_field_name('type'))
7377

7478
def resolve_type(self, files: dict[Path, File], lsp: SyncLanguageServer, path: Path, node: Node) -> list[Entity]:
7579
res = []
@@ -85,8 +89,8 @@ def resolve_method(self, files: dict[Path, File], lsp: SyncLanguageServer, path:
8589
method_dec = self.find_parent(resolved_node, ['method_declaration', 'constructor_declaration', 'class_declaration', 'interface_declaration', 'enum_declaration'])
8690
if method_dec.type in ['class_declaration', 'interface_declaration', 'enum_declaration']:
8791
continue
88-
type_dec = self.find_parent(method_dec, ['class_declaration', 'interface_declaration', 'enum_declaration'])
89-
res.append(file.entities[type_dec].children[method_dec])
92+
if method_dec in file.entities:
93+
res.append(file.entities[method_dec])
9094
return res
9195

9296
def resolve_symbol(self, files: dict[Path, File], lsp: SyncLanguageServer, path: Path, key: str, symbol: Node) -> Entity:

api/analyzers/source_analyzer.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def create_entity_hierarchy(self, entity: Entity, file: File, analyzer: Abstract
4848
child = Entity(node)
4949
child.id = graph.add_entity(analyzer.get_entity_label(node), analyzer.get_entity_name(node), analyzer.get_entity_docstring(node), str(file.path), node.start_point.row, node.end_point.row, {})
5050
analyzer.add_symbols(child)
51-
file.add_entity(entity)
51+
file.add_entity(child)
5252
entity.add_child(child)
5353
graph.connect_entities("DEFINES", entity.id, child.id)
5454
self.create_entity_hierarchy(child, file, analyzer, graph)
@@ -142,16 +142,12 @@ def second_pass(self, graph: Graph, path: Path) -> None:
142142
graph.connect_entities("IMPLEMENTS", entity.id, symbol.id)
143143
elif key == "extend_interface":
144144
graph.connect_entities("EXTENDS", entity.id, symbol.id)
145-
for _, child in entity.children.items():
146-
child.resolved_symbol(lambda key, symbol: analyzers[file_path.suffix].resolve_symbol(self.files, lsps[file_path.suffix], file_path, key, symbol))
147-
for key, symbols in child.resolved_symbols.items():
148-
for symbol in symbols:
149-
if key == "call":
150-
graph.connect_entities("CALLS", child.id, symbol.id)
151-
elif key == "return_type":
152-
graph.connect_entities("RETURNS", child.id, symbol.id)
153-
elif key == "parameters":
154-
graph.connect_entities("PARAMETERS", child.id, symbol.id)
145+
elif key == "call":
146+
graph.connect_entities("CALLS", entity.id, symbol.id)
147+
elif key == "return_type":
148+
graph.connect_entities("RETURNS", entity.id, symbol.id)
149+
elif key == "parameters":
150+
graph.connect_entities("PARAMETERS", entity.id, symbol.id)
155151

156152
def analyze_file(self, file_path: Path, path: Path, graph: Graph) -> None:
157153
ext = file_path.suffix

0 commit comments

Comments
 (0)