-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline method Improvement #54
Merged
Merged
Changes from 7 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
66ba620
fixed some bugs
Vitaly-Protasov 10c441e
fixed path of code and added saving paths
Vitaly-Protasov 29bceb0
fixed conflict
Vitaly-Protasov aef0dc2
fixed flake and mypy
Vitaly-Protasov 5b18e6a
got rid of uuid. used more complex name instead
Vitaly-Protasov 7f3dcaf
fixed
Vitaly-Protasov 973809a
fixed encoding
Vitaly-Protasov 711bb91
fixed
Vitaly-Protasov 5de2be1
fixed with zhenya
Vitaly-Protasov 04df243
fixed flake8
Vitaly-Protasov fced8e4
fixed bug with lines
Vitaly-Protasov 43525f3
fixed bug with line
Vitaly-Protasov b5525fb
fixed spaces
Vitaly-Protasov 90ec137
add info
Vitaly-Protasov 4ec3bbb
fixed flake8
Vitaly-Protasov ff6875c
fixed smth
Vitaly-Protasov 587828b
fixed mypy
Vitaly-Protasov 647a0ac
fixed flake8
Vitaly-Protasov 0bd3207
fixed comment
Vitaly-Protasov 5808c1e
fixed bugs
Vitaly-Protasov 546e41d
fixed flake and mypy
Vitaly-Protasov 15d1ace
Merge branch 'master' of https://github.com/cqfn/veniq into issue-50_1
Vitaly-Protasov dd06035
fixed extra print
Vitaly-Protasov 38f9f20
fixed processing 1st line
Vitaly-Protasov 436d98d
fixed flake8 and mypy
Vitaly-Protasov 49b21ca
fixed
Vitaly-Protasov 5ec7664
added several tests
Vitaly-Protasov 01a0c67
Merge branch 'master' of https://github.com/cqfn/veniq into issue-50_1
Vitaly-Protasov 65b6ddc
fixed flake8
Vitaly-Protasov 6bc6cdf
fixed tests
Vitaly-Protasov 8d9d311
fixed flake
Vitaly-Protasov a7fbd52
fixed spaces and tabs problem
Vitaly-Protasov 9642df4
restored
Vitaly-Protasov cfc990b
finally fixed spaces
Vitaly-Protasov bdacf35
fixed
Vitaly-Protasov e545c51
fixed spaces
Vitaly-Protasov 5a50f62
fixed flake8
Vitaly-Protasov 9e5d08c
fixed spaces and tabs finally
Vitaly-Protasov 9a19f78
fixed test
Vitaly-Protasov 6dc2ef0
Merge branch 'master' into issue-50_1
Vitaly-Protasov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 +1,12 @@ | ||
import csv | ||
import uuid | ||
from argparse import ArgumentParser | ||
import os | ||
from collections import defaultdict | ||
from functools import partial | ||
from typing import Tuple, Dict, List, Any | ||
from typing import Tuple, Dict, List, Any, Set | ||
from pathlib import Path | ||
|
||
import shutil | ||
import uuid | ||
import typing | ||
from pebble import ProcessPool | ||
from tqdm import tqdm | ||
|
@@ -142,7 +142,7 @@ def is_match_to_the_conditions( | |
|
||
def check_whether_method_has_return_type( | ||
method_decl: AST, | ||
var_decls: typing.Set[str]) -> InlineTypesAlgorithms: | ||
var_decls: Set[str]) -> InlineTypesAlgorithms: | ||
""" | ||
Run function to check whether Method declaration can be inlined | ||
:param method_decl: method, where invocation occurred | ||
|
@@ -236,21 +236,18 @@ def insert_code_with_new_file_creation( | |
file_name = file_path.stem | ||
if not os.path.exists(output_path): | ||
output_path.mkdir(parents=True) | ||
|
||
id = uuid.uuid1() | ||
new_full_filename = Path(output_path, f'{file_name}_{invocation_node.member}_{method_node.name}{id}.java') | ||
new_full_filename = Path(output_path, f'{file_name}_{method_node.name}_{invocation_node.line}.java') | ||
original_func = dict_original_invocations.get(invocation_node.member)[0] # type: ignore | ||
body_start_line, body_end_line = method_body_lines(original_func, file_path) | ||
text_lines = read_text_with_autodetected_encoding(str(file_path)).split('\n') | ||
|
||
line_to_csv = [ | ||
str(file_path), | ||
file_path, | ||
class_name, | ||
text_lines[invocation_node.line - 1].strip(' '), | ||
invocation_node.line, | ||
original_func.line, | ||
method_node.name, | ||
id, | ||
] | ||
|
||
algorithm_for_inlining = AlgorithmFactory().create_obj( | ||
|
@@ -267,7 +264,7 @@ def insert_code_with_new_file_creation( | |
return line_to_csv | ||
|
||
|
||
def analyze_file(file_path: Path, output_path: Path) -> List[Any]: | ||
def _analyze_file(file_path: Path, output_path: Path) -> List[Any]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do u make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я удалил потом |
||
try: | ||
AST.build_from_javalang(build_ast(str(file_path))) | ||
except Exception: | ||
|
@@ -312,6 +309,12 @@ def analyze_file(file_path: Path, output_path: Path) -> List[Any]: | |
return results | ||
|
||
|
||
def _save_inpit_file(input_dir: Path, filename: Path) -> None: | ||
saved_path_of_original = input_dir.joinpath(filename.name) | ||
if not os.path.exists(saved_path_of_original): | ||
shutil.copyfile(filename, saved_path_of_original) | ||
|
||
|
||
if __name__ == '__main__': | ||
system_cores_qty = os.cpu_count() or 1 | ||
parser = ArgumentParser() | ||
|
@@ -338,10 +341,14 @@ def analyze_file(file_path: Path, output_path: Path) -> List[Any]: | |
not_test_files = set(Path(args.dir).glob('**/*.java')) | ||
files_without_tests = list(not_test_files.difference(test_files)) | ||
|
||
output_dir = Path(args.output) | ||
output_dir = Path(args.output).joinpath('output_files') | ||
if not output_dir.exists(): | ||
output_dir.mkdir(parents=True) | ||
|
||
input_dir = Path(args.output).joinpath('input_files') | ||
if not input_dir.exists(): | ||
input_dir.mkdir(parents=True) | ||
|
||
with open(Path(output_dir, 'out.csv'), 'w', newline='\n') as csvfile, ProcessPool(1) as executor: | ||
writer = csv.writer(csvfile, delimiter=',', | ||
quotechar='"', quoting=csv.QUOTE_MINIMAL) | ||
|
@@ -354,7 +361,7 @@ def analyze_file(file_path: Path, output_path: Path) -> List[Any]: | |
'invocation function name', | ||
'unique id']) | ||
|
||
p_analyze = partial(analyze_file, output_path=output_dir.absolute()) | ||
p_analyze = partial(_analyze_file, output_path=output_dir.absolute()) | ||
future = executor.map(p_analyze, files_without_tests, timeout=1000, ) | ||
result = future.result() | ||
|
||
|
@@ -364,8 +371,7 @@ def analyze_file(file_path: Path, output_path: Path) -> List[Any]: | |
if single_file_features: | ||
for i in single_file_features: | ||
writer.writerow(i) | ||
_save_inpit_file(input_dir, filename) | ||
csvfile.flush() | ||
except TimeoutError: | ||
print(f"Processing {filename} is aborted due to timeout in {args.timeout} seconds.") | ||
except Exception as e: | ||
print(str(e)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here must be a string, otherwise there will be dirty string like Path("A/b/A") instead of "A/b/A"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У меня кстати не было такого