Skip to content
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 40 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
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 Oct 12, 2020
10c441e
fixed path of code and added saving paths
Vitaly-Protasov Oct 13, 2020
29bceb0
fixed conflict
Vitaly-Protasov Oct 13, 2020
aef0dc2
fixed flake and mypy
Vitaly-Protasov Oct 13, 2020
5b18e6a
got rid of uuid. used more complex name instead
Vitaly-Protasov Oct 13, 2020
7f3dcaf
fixed
Vitaly-Protasov Oct 13, 2020
973809a
fixed encoding
Vitaly-Protasov Oct 13, 2020
711bb91
fixed
Vitaly-Protasov Oct 15, 2020
5de2be1
fixed with zhenya
Vitaly-Protasov Oct 15, 2020
04df243
fixed flake8
Vitaly-Protasov Oct 15, 2020
fced8e4
fixed bug with lines
Vitaly-Protasov Oct 15, 2020
43525f3
fixed bug with line
Vitaly-Protasov Oct 15, 2020
b5525fb
fixed spaces
Vitaly-Protasov Oct 15, 2020
90ec137
add info
Vitaly-Protasov Oct 15, 2020
4ec3bbb
fixed flake8
Vitaly-Protasov Oct 15, 2020
ff6875c
fixed smth
Vitaly-Protasov Oct 15, 2020
587828b
fixed mypy
Vitaly-Protasov Oct 15, 2020
647a0ac
fixed flake8
Vitaly-Protasov Oct 15, 2020
0bd3207
fixed comment
Vitaly-Protasov Oct 15, 2020
5808c1e
fixed bugs
Vitaly-Protasov Oct 15, 2020
546e41d
fixed flake and mypy
Vitaly-Protasov Oct 15, 2020
15d1ace
Merge branch 'master' of https://github.com/cqfn/veniq into issue-50_1
Vitaly-Protasov Oct 19, 2020
dd06035
fixed extra print
Vitaly-Protasov Oct 19, 2020
38f9f20
fixed processing 1st line
Vitaly-Protasov Oct 19, 2020
436d98d
fixed flake8 and mypy
Vitaly-Protasov Oct 19, 2020
49b21ca
fixed
Vitaly-Protasov Oct 19, 2020
5ec7664
added several tests
Vitaly-Protasov Oct 20, 2020
01a0c67
Merge branch 'master' of https://github.com/cqfn/veniq into issue-50_1
Vitaly-Protasov Oct 20, 2020
65b6ddc
fixed flake8
Vitaly-Protasov Oct 20, 2020
6bc6cdf
fixed tests
Vitaly-Protasov Oct 20, 2020
8d9d311
fixed flake
Vitaly-Protasov Oct 20, 2020
a7fbd52
fixed spaces and tabs problem
Vitaly-Protasov Oct 20, 2020
9642df4
restored
Vitaly-Protasov Oct 20, 2020
cfc990b
finally fixed spaces
Vitaly-Protasov Oct 20, 2020
bdacf35
fixed
Vitaly-Protasov Oct 20, 2020
e545c51
fixed spaces
Vitaly-Protasov Oct 20, 2020
5a50f62
fixed flake8
Vitaly-Protasov Oct 20, 2020
9e5d08c
fixed spaces and tabs finally
Vitaly-Protasov Oct 20, 2020
9a19f78
fixed test
Vitaly-Protasov Oct 20, 2020
6dc2ef0
Merge branch 'master' into issue-50_1
Vitaly-Protasov Oct 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions veniq/dataset_collection/augmentation.py
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Copy link
Member

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У меня кстати не было такого

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(
Expand All @@ -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]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do u make _ before each function? It's not a private function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я удалил потом

try:
AST.build_from_javalang(build_ast(str(file_path)))
except Exception:
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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()

Expand All @@ -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))
Loading