-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from aibolit.ast_framework.ast_node_type import ASTNodeType # noqa: F401 | ||
from aibolit.ast_framework.ast_node import ASTNode # noqa: F401 | ||
from aibolit.ast_framework.ast import AST # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
import javalang | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 Aibolit | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
from typing import List | ||
|
||
from aibolit.ast_framework.ast import AST, ASTNodeType | ||
from aibolit.utils.ast_builder import build_ast | ||
|
||
|
||
class ImplementsMultiFinder: | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def value(self, filename: str): | ||
tree = build_ast(filename).filter(javalang.tree.ClassDeclaration) | ||
return [node._position.line for _, node in tree if node.implements and (len(node.implements) > 1)] | ||
def value(self, filename: str) -> List[int]: | ||
tree = AST.build_from_javalang(build_ast(filename)) | ||
lines: List[int] = [] | ||
for node in tree.get_proxy_nodes(ASTNodeType.CLASS_DECLARATION): | ||
if node.implements and len(node.implements) > 1: | ||
lines.append(node.line) | ||
return lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
from aibolit.ast_framework.ast import ASTNodeType | ||
from aibolit.ast_framework.java_package import JavaPackage | ||
from typing import List | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 Aibolit | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
from typing import List | ||
|
||
class SuperMethod: | ||
from aibolit.ast_framework.ast import AST, ASTNodeType | ||
from aibolit.utils.ast_builder import build_ast | ||
|
||
def __init__(self): | ||
pass | ||
|
||
class SuperMethod: | ||
def value(self, filename: str) -> List[int]: | ||
""" | ||
Iterates over functions and finds super.func() calls. | ||
Javalang doesn't have code line for super.func() call, | ||
that's why we can only count the first match of a call inside some function. | ||
It has MULTIPLE MATCHES if we call super.func() inside a ANONYMOUS CLASS. | ||
:param filename: | ||
:return: Lines of code | ||
""" | ||
results = [] | ||
tree = JavaPackage(filename) | ||
for ast_method in tree.get_subtrees(ASTNodeType.METHOD_DECLARATION): | ||
for statement in ast_method.get_nodes(ASTNodeType.STATEMENT_EXPRESSION): | ||
code_line = ast_method.get_attr(statement, 'line') | ||
all_super_methods = ast_method.children_with_type(statement, ASTNodeType.SUPER_METHOD_INVOCATION) | ||
if len(list(all_super_methods)): | ||
results.append(code_line) | ||
return results | ||
ast = AST.build_from_javalang(build_ast(filename)) | ||
lines: List[int] = [] | ||
for statement in ast.get_proxy_nodes(ASTNodeType.STATEMENT_EXPRESSION): | ||
if any(child.node_type == ASTNodeType.SUPER_METHOD_INVOCATION | ||
for child in statement.children): | ||
lines.append(statement.line) | ||
return lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters