Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukyanoffpashok committed Jul 9, 2020
1 parent be5b7bf commit 0742432
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
6 changes: 3 additions & 3 deletions aibolit/patterns/multiple_while/multiple_while.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class MultipleWhile:
def __init__(self):
pass

def get_number_of_sequential_while_statement_in_function(self, tree: AST, node: int) -> int:
def get_top_level_while_qty(self, tree: AST, node: int) -> int:
list_while_nodes: List[int] = []
set_child_while_nodes: Set[int] = set()
for child in tree.all_children_with_type(node, ASTNodeType.WHILE_STATEMENT):
list_while_nodes.append(child)
set_internal_while = set(tree.list_all_children_with_type(child, ASTNodeType.WHILE_STATEMENT))
set_child_while_nodes = set.union(set_child_while_nodes, set_internal_while)
set_child_while_nodes |= set_internal_while
return len(list_while_nodes) - len(set_child_while_nodes)

def value(self, filename: str) -> List[int]:
Expand All @@ -28,7 +28,7 @@ def value(self, filename: str) -> List[int]:
tree = AST.build_from_javalang(build_ast(filename))
lines: List[int] = []
for node in tree.nodes_by_type(ASTNodeType.METHOD_DECLARATION):
if self.get_number_of_sequential_while_statement_in_function(tree, node) > 1:
if self.get_top_level_while_qty(tree, node) > 1:
lines.append(tree.get_attr(node, 'source_code_line'))

return lines
4 changes: 2 additions & 2 deletions test/patterns/multiple_while/MultipleWhile.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class MultipleWhile {
void bar() {
while (true) {
x = 1;
// some code
while (false) {
x = 1;
// some code
}
}
// more code
Expand Down
33 changes: 4 additions & 29 deletions test/patterns/multiple_while/test_multiple_while.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
from unittest import TestCase
from aibolit.patterns.multiple_while.multiple_while import MultipleWhile
from pathlib import Path
Expand All @@ -29,41 +28,17 @@
class TestMultipleWhile(TestCase):

def test_simple(self):
lines = MultipleWhile().value(
Path(
Path(
os.path.realpath(__file__)
).parent, 'Simple.java'
)
)
lines = MultipleWhile().value(Path(__file__).parent.absolute() / 'Simple.java')
self.assertEqual(lines, [2])

def test_one_while(self):
lines = MultipleWhile().value(
Path(
Path(
os.path.realpath(__file__)
).parent, 'OneWhile.java'
)
)
lines = MultipleWhile().value(Path(__file__).parent.absolute() / 'OneWhile.java')
self.assertEqual(lines, [])

def test_if_while(self):
lines = MultipleWhile().value(
Path(
Path(
os.path.realpath(__file__)
).parent, 'IfWhile.java'
)
)
lines = MultipleWhile().value(Path(__file__).parent.absolute() / 'IfWhile.java')
self.assertEqual(lines, [2])

def test_multiple_while(self):
lines = MultipleWhile().value(
Path(
Path(
os.path.realpath(__file__)
).parent, 'MultipleWhile.java'
)
)
lines = MultipleWhile().value(Path(__file__).parent.absolute() / 'MultipleWhile.java')
self.assertEqual(lines, [])

0 comments on commit 0742432

Please sign in to comment.