Skip to content

Commit 91b4098

Browse files
committed
Fix external methods typing checks
1 parent cb35141 commit 91b4098

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

aibolit/metrics/external_methods_called/external_methods_called.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def _external_method_names_called(self) -> Set[str]:
2929
local_methods = self._local_method_names()
3030
return set(
3131
node.member
32-
for node in self.ast.proxy_nodes(ASTNodeType.METHOD_INVOCATION)
32+
for node in self.ast.proxy_nodes(
33+
ASTNodeType.METHOD_INVOCATION,
34+
ASTNodeType.SUPER_METHOD_INVOCATION,
35+
)
3336
if node.member not in local_methods
3437
)
3538

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2019-2026 Aibolit
2+
// SPDX-License-Identifier: MIT
3+
4+
public class SuperMethodCall {
5+
6+
public String value() {
7+
return super.toString();
8+
}
9+
}

test/metrics/external_methods_called/test_external_methods_called.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def test_external_method_calls(self):
2929

3030
def test_external_method_calls_from_filepath(self):
3131
self.assertEqual(
32-
ExternalMethodsCalled().value(Path(self.dir_path, 'ExternalMethodCalls.java')),
32+
ExternalMethodsCalled().value(
33+
Path(self.dir_path, 'ExternalMethodCalls.java') # ty: ignore[invalid-argument-type]
34+
),
3335
2,
3436
'Could not calculate external methods from a file path'
3537
)
@@ -55,5 +57,12 @@ def test_local_method_call_is_not_external(self):
5557
'Could not ignore local method calls'
5658
)
5759

60+
def test_super_method_call_is_external(self):
61+
self.assertEqual(
62+
ExternalMethodsCalled().value(self._ast('SuperMethodCall.java')),
63+
1,
64+
'Could not count super method calls as external'
65+
)
66+
5867
def _ast(self, filename):
5968
return AST.build_from_javalang(build_ast(Path(self.dir_path, filename)))

test/scripts/test_calculate_metrics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def load_calculate_metrics_module():
1212
raise RuntimeError(f'Failed to load module spec from {script_path}')
1313
if spec.loader is None:
1414
raise RuntimeError(f'Failed to load module loader from {script_path}')
15+
loader = spec.loader
1516
module = importlib.util.module_from_spec(spec)
16-
spec.loader.exec_module(module)
17+
loader.exec_module(module)
1718
return module
1819

1920

0 commit comments

Comments
 (0)