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 with params #120

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
6b1004e
[86] Extract class ast getter.
aravij Nov 5, 2020
bdf4d7f
[86] Split test helper to inject tests with constructor.
aravij Nov 5, 2020
50d60d5
[86] Assume constructors in extraction semantic. Add test.
aravij Nov 5, 2020
04c03d0
Merge branch 'master' into issue-86
aravij Nov 5, 2020
1f22df4
[62] Make creation of extraction opportunities faster.
aravij Nov 12, 2020
7dc05e2
Merge branch 'master' into issue-62
aravij Nov 12, 2020
3475bd9
Merge branch 'master' into issue-86
aravij Nov 12, 2020
bc6dd8a
ADd refMIner execution
lyriccoder Nov 23, 2020
08af949
ADd similarity
lyriccoder Nov 25, 2020
fbd5966
Create dataset function
lyriccoder Nov 26, 2020
028f023
Fix flake8
lyriccoder Nov 26, 2020
0b9ee56
Fix tests
lyriccoder Nov 26, 2020
e3a0918
Fix
lyriccoder Nov 26, 2020
0b2dc31
Fix requirements
lyriccoder Nov 26, 2020
fce2d6d
Fix unittest
lyriccoder Nov 26, 2020
8ac23ae
Fix
lyriccoder Nov 26, 2020
0bd59e7
Add tests
lyriccoder Nov 27, 2020
c822878
Add similarity range + funtion end line
lyriccoder Nov 30, 2020
eb11c56
Fixed file
lyriccoder Nov 30, 2020
bbc980a
Fix tests
lyriccoder Dec 1, 2020
3db0222
Add files
lyriccoder Dec 1, 2020
7ac92a0
Add requirements
lyriccoder Dec 1, 2020
7a4d6ca
Merge branch 'master' into ref_miner
lyriccoder Dec 2, 2020
a176986
Fix bug
lyriccoder Dec 10, 2020
58d59ef
Merge branch 'master' into issue-111
lyriccoder Dec 10, 2020
815525a
Fix print
lyriccoder Dec 10, 2020
761ed52
Merge branch 'issue-111' of https://github.com/cqfn/veniq into issue-111
lyriccoder Dec 10, 2020
25242c0
Add tests
lyriccoder Dec 14, 2020
82464ef
Fix bug and tests
lyriccoder Dec 14, 2020
c58a275
Fix stupid flake
lyriccoder Dec 14, 2020
6cff2b2
Fix print
lyriccoder Dec 14, 2020
d651387
Add script for statistics collection
lyriccoder Dec 14, 2020
f852bf9
Fix some code
lyriccoder Dec 15, 2020
72dd3c0
Fix integration tests and add overloaded filter
lyriccoder Dec 15, 2020
0ac1719
Fix issue-111
lyriccoder Dec 15, 2020
375690f
Fix flake8
lyriccoder Dec 15, 2020
4e725a7
Add fixes
lyriccoder Dec 15, 2020
df75488
Merge branch 'master' into ref_miner
lyriccoder Dec 16, 2020
7d06a83
Fix contructor declaration
lyriccoder Dec 16, 2020
03d5638
Fix bug
lyriccoder Dec 16, 2020
3879e6d
Fix sys_Cores
lyriccoder Dec 16, 2020
d6f2838
Fix was_not_inlined_function
lyriccoder Dec 16, 2020
0e5e9fd
Fix gain sys_core
lyriccoder Dec 16, 2020
a170f28
Merge branch 'master' into check_synth_dataset
lyriccoder Dec 17, 2020
fb0e3e6
Fix f flake8
lyriccoder Dec 17, 2020
93e8051
Merge branch 'check_synth_dataset' of https://github.com/cqfn/veniq i…
lyriccoder Dec 17, 2020
417432b
Fix bug
lyriccoder Dec 17, 2020
2343078
Merge branch 'master' into ref_miner
lyriccoder Dec 18, 2020
32e5047
Merge branch 'issue-86' of https://github.com/cqfn/veniq into crap_da…
lyriccoder Jan 13, 2021
a07d3d6
Merge branch 'issue-62' of https://github.com/cqfn/veniq into crap_da…
lyriccoder Jan 13, 2021
387b325
Merge branch 'ref_miner' of https://github.com/cqfn/veniq into crap_d…
lyriccoder Jan 13, 2021
8eec40a
Merge branch 'issue-111' of https://github.com/cqfn/veniq into crap_d…
lyriccoder Jan 13, 2021
99c75f1
Merge branch 'crap_dataset' of https://github.com/cqfn/veniq into cra…
lyriccoder Jan 13, 2021
19b831a
First version of stats
lyriccoder Jan 13, 2021
e2dbb5d
Fix some filters
lyriccoder Jan 14, 2021
266f66d
Some fixes + collect stats
lyriccoder Jan 14, 2021
47ce581
ADd function for filter
lyriccoder Jan 15, 2021
09adebd
Fix ncss > 2
lyriccoder Jan 15, 2021
38a83cf
Remove cross varialbes
lyriccoder Jan 18, 2021
15bf775
Remove all var cross
lyriccoder Jan 18, 2021
ada0f23
Fix complex
lyriccoder Jan 20, 2021
c074c57
Add test for crossed vars
lyriccoder Jan 20, 2021
507ed01
Fix test due to functionality refactoring
lyriccoder Jan 20, 2021
ebe51e0
Fix constant
lyriccoder Jan 20, 2021
c79dce7
Fix stats
lyriccoder Jan 22, 2021
07765f4
Add case when throw in extracted
lyriccoder Jan 22, 2021
1a9ef96
Ignore cases when return is not inside main body
lyriccoder Jan 22, 2021
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ requirements:

unittest:
python3 -m unittest discover
python3 -m unittest test/integration/dataset_collection.py

install:
python3 -m pip install .
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ typing-extensions; python_version<'3.8'
tqdm == 4.32.1
bs4==0.0.1
pebble==4.5.3
pandas==1.1.2
pandas==1.1.2
sortedcontainers==2.3.0
textdistance==4.2.0
requests==2.25.0
4 changes: 4 additions & 0 deletions test/baselines/semi/SemanticExtractionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ void multilineStatement(int x, int y) {
void multipleStatementsPerLine(int x, int y) {
localMethod(x); localMethod(y);
}

SimpleMethods() { // first constructor
init();
}
}
69 changes: 42 additions & 27 deletions test/baselines/semi/test_extract_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@

from veniq.baselines.semi.extract_semantic import extract_method_statements_semantic
from veniq.baselines.semi._common_types import StatementSemantic
from .utils import objects_semantic, get_method_ast
from veniq.ast_framework import AST
from .utils import objects_semantic, get_method_ast, get_constructor_ast


class ExtractStatementSemanticTestCase(TestCase):
def test_block_method(self):
self._test_helper("block", [StatementSemantic(), objects_semantic("x"), StatementSemantic()])
self._test_method("block", [StatementSemantic(), objects_semantic("x"), StatementSemantic()])

def test_for_cycle_method(self):
self._test_helper(
self._test_method(
"forCycle",
[objects_semantic("x", "i"), objects_semantic("x", "i", "result"), StatementSemantic()],
)

def test_while_cycle_method(self):
self._test_helper("whileCycle", [objects_semantic("x"), objects_semantic("x"), StatementSemantic()])
self._test_method("whileCycle", [objects_semantic("x"), objects_semantic("x"), StatementSemantic()])

def test_do_while_cycle_method(self):
self._test_helper("doWhileCycle", [objects_semantic("x"), objects_semantic("x"), StatementSemantic()])
self._test_method("doWhileCycle", [objects_semantic("x"), objects_semantic("x"), StatementSemantic()])

def test_if_branching_method(self):
self._test_helper(
self._test_method(
"ifBranching",
[
objects_semantic("x"),
Expand All @@ -38,12 +39,12 @@ def test_if_branching_method(self):
)

def test_synchronized_block_method(self):
self._test_helper(
self._test_method(
"synchronizedBlock", [objects_semantic("x"), objects_semantic("x"), StatementSemantic()]
)

def test_switch_branching_method(self):
self._test_helper(
self._test_method(
"switchBranching",
[
objects_semantic("x"),
Expand All @@ -55,7 +56,7 @@ def test_switch_branching_method(self):
)

def test_try_block_method(self):
self._test_helper(
self._test_method(
"tryBlock",
[
StatementSemantic(),
Expand All @@ -73,47 +74,47 @@ def test_try_block_method(self):
)

def test_assert_statement_method(self):
self._test_helper("assertStatement", [objects_semantic("x")])
self._test_method("assertStatement", [objects_semantic("x")])

def test_return_statement_method(self):
self._test_helper("returnStatement", [objects_semantic("x")])
self._test_method("returnStatement", [objects_semantic("x")])

def test_expression_method(self):
self._test_helper("expression", [objects_semantic("x")])
self._test_method("expression", [objects_semantic("x")])

def test_throw_statement_method(self):
self._test_helper("throwStatement", [objects_semantic("x")])
self._test_method("throwStatement", [objects_semantic("x")])

def test_local_variable_declaration_method(self):
self._test_helper("localVariableDeclaration", [objects_semantic("x")])
self._test_method("localVariableDeclaration", [objects_semantic("x")])

def test_break_statement_method(self):
self._test_helper("breakStatement", [StatementSemantic(), StatementSemantic(), StatementSemantic()])
self._test_method("breakStatement", [StatementSemantic(), StatementSemantic(), StatementSemantic()])

def test_continue_statement_method(self):
self._test_helper(
self._test_method(
"continueStatement", [StatementSemantic(), StatementSemantic(), StatementSemantic()]
)

def test_local_method_call_method(self):
self._test_helper("localMethodCall", [StatementSemantic(used_methods={"localMethod"})])
self._test_method("localMethodCall", [StatementSemantic(used_methods={"localMethod"})])

def test_object_method_call_method(self):
self._test_helper(
self._test_method(
"objectMethodCall", [StatementSemantic(used_objects={"o"}, used_methods={"method"})]
)

def test_nested_object_method(self):
self._test_helper("nestedObject", [StatementSemantic(used_objects={"o.x"})])
self._test_method("nestedObject", [StatementSemantic(used_objects={"o.x"})])

def test_nested_object_method_call_method(self):
self._test_helper(
self._test_method(
"nestedObjectMethodCall",
[StatementSemantic(used_objects={"o.nestedObject"}, used_methods={"method"})],
)

def test_several_statement_method(self):
self._test_helper(
self._test_method(
"severalStatements",
[
objects_semantic("x"),
Expand All @@ -125,7 +126,7 @@ def test_several_statement_method(self):
)

def test_deep_nesting_method(self):
self._test_helper(
self._test_method(
"deepNesting",
[
objects_semantic("i"),
Expand All @@ -142,7 +143,7 @@ def test_deep_nesting_method(self):
)

def test_complex_expressions_method(self):
self._test_helper(
self._test_method(
"complexExpressions",
[
objects_semantic("x", "y"),
Expand All @@ -158,20 +159,34 @@ def test_complex_expressions_method(self):
)

def test_multiline_statement_method(self):
self._test_helper("multilineStatement", [objects_semantic("x", "y", "o")])
self._test_method("multilineStatement", [objects_semantic("x", "y", "o")])

def test_multiple_statements_per_line_method(self):
self._test_helper(
self._test_method(
"multipleStatementsPerLine",
[
StatementSemantic(used_methods={"localMethod"}, used_objects={"x"}),
StatementSemantic(used_methods={"localMethod"}, used_objects={"y"}),
],
)

def _test_helper(self, method_name: str, expected_statements_semantics: List[StatementSemantic]):
def test_constructor(self):
self._test_constructor(1, [StatementSemantic(used_methods={"init"})])

def _test_method(self, method_name: str, expected_statements_semantics: List[StatementSemantic]):
method_ast = get_method_ast("SemanticExtractionTest.java", "SimpleMethods", method_name)
method_semantic = extract_method_statements_semantic(method_ast)
self._test_ast(method_ast, expected_statements_semantics)

def _test_constructor(
self, constructor_index: int, expected_statements_semantics: List[StatementSemantic]
):
constructor_ast = get_constructor_ast(
"SemanticExtractionTest.java", "SimpleMethods", constructor_index
)
self._test_ast(constructor_ast, expected_statements_semantics)

def _test_ast(self, ast: AST, expected_statements_semantics: List[StatementSemantic]):
method_semantic = extract_method_statements_semantic(ast)
for (
comparison_index,
(statement, actual_statement_semantic, expected_statement_semantic),
Expand Down
29 changes: 26 additions & 3 deletions test/baselines/semi/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from itertools import islice
from pathlib import Path
from typing import List, Tuple, Union

Expand Down Expand Up @@ -30,7 +31,7 @@ def fill_extraction_opportunity(node: Union[Block, Statement]):
return tuple(extraction_opportunity_list), block_statement_graph


def get_method_ast(filename: str, class_name: str, method_name: str) -> AST:
def get_class_ast(filename: str, class_name: str) -> Tuple[AST, Path]:
current_directory = Path(__file__).absolute().parent
filepath = current_directory / filename
ast = AST.build_from_javalang(build_ast(str(filepath)))
Expand All @@ -41,9 +42,31 @@ def get_method_ast(filename: str, class_name: str, method_name: str) -> AST:
for node in ast.get_root().types
if node.node_type == ASTNodeType.CLASS_DECLARATION and node.name == class_name
)
except StopIteration:
raise RuntimeError(f"Failed to find class {class_name} in file {filepath}")

return ast.get_subtree(class_declaration), filepath


method_declaration = next(node for node in class_declaration.methods if node.name == method_name)
def get_method_ast(filename: str, class_name: str, method_name: str) -> AST:
class_ast, filepath = get_class_ast(filename, class_name)

try:
method_declaration = next(node for node in class_ast.get_root().methods if node.name == method_name)
except StopIteration:
raise RuntimeError(f"Failed to find method {method_name} in class {class_name} in file {filepath}")

return ast.get_subtree(method_declaration)
return class_ast.get_subtree(method_declaration)


def get_constructor_ast(filename: str, class_name: str, constructor_index: int) -> AST:
class_ast, filepath = get_class_ast(filename, class_name)

try:
constructor_declaration = next(islice(class_ast.get_root().constructors, constructor_index - 1, None))
except StopIteration:
raise RuntimeError(
f"Failed to find {constructor_index}th constructor in class {class_name} in file {filepath}"
)

return class_ast.get_subtree(constructor_declaration)
26 changes: 26 additions & 0 deletions test/dataset_collection/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,30 @@ public void runDelete() {
delete();
}

public int severalReturnsWithoutMainReturn() {
int i = 0, j = 0;
if (i < 0) {
return 0;
}
}

private Object returnInsideTry() {
try {
Object event = events.poll(10, TimeUnit.SECONDS);
if (event == null) {
throw new AssertionError("Timed out waiting for event.");
}
return event;
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}

public void runSeveralReturnsWithoutMainReturn() {
int a = severalReturnsWithoutMainReturn();
}
public void runSeveralReturnsInTry(String payload) {
Object actual = returnInsideTry();
assertThat(actual).isEqualTo(new Message(payload));
}
}
2 changes: 1 addition & 1 deletion test/dataset_collection/Example_nested.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ private void doAction () {
// proceed operation
Restarter r;
try {
if ((r = handleAction ()) != null) {
if (handleAction () != null) {
presentActionNeedsRestart (r);
} else {
presentActionDone ();
Expand Down
Loading