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

Dataset Collection. Fixing problems with inlining #85

Merged
merged 35 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0cdcfe5
fixed problem with comments
Vitaly-Protasov Oct 27, 2020
c74b1b5
fixed invocation inside other statements
Vitaly-Protasov Oct 27, 2020
12d1dbf
Merge branch 'master' of https://github.com/cqfn/veniq into issue-50_5
Vitaly-Protasov Oct 27, 2020
c95ca2c
fixed invocation inside other statements
Vitaly-Protasov Oct 27, 2020
08d69b5
fixed flake and logic
Vitaly-Protasov Oct 27, 2020
7bd36e5
fixed flake and logic
Vitaly-Protasov Oct 27, 2020
a94320a
fixed flake and logic
Vitaly-Protasov Oct 27, 2020
6826e38
added test for nesting
Vitaly-Protasov Oct 27, 2020
48593db
added new statements
Vitaly-Protasov Oct 27, 2020
c9a657c
fixed previous problem with inlining declaration var
Vitaly-Protasov Oct 27, 2020
b8028f4
fixed inling spaces
Vitaly-Protasov Oct 27, 2020
cc61660
added more statement
Vitaly-Protasov Oct 27, 2020
da8b094
resolved conflict
Vitaly-Protasov Oct 29, 2020
751d71b
resolved conflict
Vitaly-Protasov Oct 29, 2020
7936613
fixed test
Vitaly-Protasov Oct 29, 2020
f43eb24
pulled master
Vitaly-Protasov Oct 29, 2020
42218e6
added try
Vitaly-Protasov Oct 29, 2020
91c9432
fixed bug with none bounds
Vitaly-Protasov Oct 29, 2020
68c40c7
ADd exception
lyriccoder Nov 5, 2020
f673378
Fix
lyriccoder Nov 5, 2020
793cf11
Merge branch 'master' into issue-50_5
lyriccoder Nov 5, 2020
a115b2d
Merge branch 'validation' of https://github.com/cqfn/veniq into issue…
lyriccoder Nov 5, 2020
e0800cf
Merge branch 'master' of https://github.com/cqfn/veniq into issue-50_5
lyriccoder Nov 5, 2020
66021b8
Merge branch 'issue-50_5' of https://github.com/cqfn/veniq into issue…
lyriccoder Nov 5, 2020
17aee1d
Fix some prints
lyriccoder Nov 5, 2020
de11b43
Merge branch 'master' of https://github.com/cqfn/veniq into issue-50_5
lyriccoder Nov 13, 2020
6bb826d
Update veniq/dataset_collection/augmentation.py
lyriccoder Nov 13, 2020
49ce379
Fix comments + added tests
lyriccoder Nov 13, 2020
f199815
Merge branch 'issue-50_5' of https://github.com/cqfn/veniq into issue…
lyriccoder Nov 13, 2020
b9815e3
Fix flake8
lyriccoder Nov 13, 2020
f165c0e
Fix path in integration tests
lyriccoder Nov 13, 2020
c0a4a75
Fix test file
lyriccoder Nov 13, 2020
9f60b2f
Fix data \r
lyriccoder Nov 13, 2020
ec4b367
Update augmentation.py
lyriccoder Nov 17, 2020
1a349b9
Update test/dataset_collection/test_dataset_collection.py
lyriccoder Nov 17, 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
72 changes: 72 additions & 0 deletions test/dataset_collection/Example_nested.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
public class UninstallStep implements WizardDescriptor.FinishablePanel<WizardDescriptor> {
private void doAction () {
// proceed operation
Restarter r;
try {
if ((r = handleAction ()) != null) {
presentActionNeedsRestart (r);
} else {
presentActionDone ();
}
} catch (OperationException ex) {
presentActionFailed (ex);
}
fireChange ();
}

private Restarter handleAction () throws OperationException {
assert model.getBaseContainer () != null : "getBaseContainers() returns not null container.";
support = (OperationSupport) model.getBaseContainer ().getSupport ();
assert support != null : "OperationSupport cannot be null because OperationContainer " +
"contains elements: " + model.getBaseContainer ().listAll () + " and invalid elements " + model.getBaseContainer ().listInvalid ();
if (support == null) {
err.log(Level.WARNING, "OperationSupport cannot be null because OperationContainer contains elements: "
+ "{0} and invalid elements {1}", new Object[]{model.getBaseContainer().listAll(), model.getBaseContainer().listInvalid()});
if (!model.getBaseContainer().listInvalid().isEmpty()) {
// cannot continue if there are invalid elements
throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL,
UninstallStep_NullSupport_InvalidElements(model.getBaseContainer().listInvalid()));
} else if (model.getBaseContainer().listAll().isEmpty()) {
// it's weird, there must be any elemets for uninstall
throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL,
UninstallStep_NullSupport_NullElements());
}
throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL,
"OperationSupport cannot be null because OperationContainer "
+ "contains elements: " + model.getBaseContainer().listAll() + " and invalid elements " + model.getBaseContainer().listInvalid());
}
ProgressHandle handle = null;
switch (model.getOperation ()) {
case UNINSTALL :
handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Uninstall());
break;
case ENABLE :
handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Activate());
break;
case DISABLE :
handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Deactivate());
break;
default:
assert false : "Unknown OperationType " + model.getOperation ();
}

JComponent progressComponent = ProgressHandleFactory.createProgressComponent (handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent (handle);
JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent (handle);
model.modifyOptionsForDisabledCancel (wd);

panel.waitAndSetProgressComponents (mainLabel, progressComponent, detailLabel);

Restarter r = null;
try {
r = support.doOperation (handle);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(UninstallStep_Done()));
} catch (OperationException ex) {
err.log (Level.INFO, ex.getMessage (), ex);
panel.waitAndSetProgressComponents(mainLabel, progressComponent,
new JLabel(UninstallStep_Failed(ex.getLocalizedMessage())));
throw ex;
}
return r;
}
}
99 changes: 99 additions & 0 deletions test/dataset_collection/InlineExamples/ObjectProperties_cut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

public class ObjectPropertiesEditor extends AbstractDatabaseObjectEditor<DBSObject> implements IEntityStructureEditor,
IRefreshablePart,
IProgressControlProvider,
ITabbedFolderContainer,
ISearchContextProvider,
INavigatorModelView,
IEntityEditorContext,
IDatabasePostSaveProcessor
{
private void createPropertyBrowser(Composite container)
{
pageControl.setRedraw(false);
try {
TabbedFolderInfo[] folders = collectFolders(this);
if (folders.length == 0) {
createPropertiesPanel(container);
} else {
Composite foldersParent = container;
if (hasPropertiesEditor() && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.ENTITY_EDITOR_DETACH_INFO)) {
sashForm = UIUtils.createPartDivider(getSite().getPart(), container, SWT.VERTICAL);
sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
foldersParent = sashForm;

createPropertiesPanel(sashForm);
}
createFoldersPanel(foldersParent, folders);
}

// Create props
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.ENTITY_EDITOR_DETACH_INFO)) {
if (hasPropertiesEditor()) {
propertiesPanel = new TabbedFolderPageForm(this, pageControl, getEditorInput());

propertiesPanel.createControl(propsPlaceholder);
}
}

if (sashForm != null) {
//Runnable sashUpdater = this::updateSashWidths;
//sashUpdater.run();
//UIUtils.asyncExec(sashUpdater);
updateSashWidths();
}
pageControl.layout(true, true);
} finally {
pageControl.setRedraw(true);
}
}

private void updateSashWidths() {
if (sashForm.isDisposed()) {
return;
}

// if (propsPlaceholder != null) {
Point propsSize = propsPlaceholder.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point sashSize = sashForm.getParent().getSize();
if (sashSize.x <= 0 || sashSize.y <= 0) {
// This may happen if EntityEditor created with some other active editor (i.e. props editor not visible)
propsSize.y += 10;
sashSize = getParentSize(sashForm);
//sashSize.y += 20;
}
if (sashSize.x > 0 && sashSize.y > 0) {
float ratio = (float) propsSize.y / (float) sashSize.y;
int propsRatio = Math.min(1000, (int) (1000 * ratio));
int[] newWeights = {propsRatio, 1000 - propsRatio};
if (!Arrays.equals(newWeights, sashForm.getWeights())) {
sashForm.setWeights(newWeights);
//sashForm.layout();
}
}

/*
} else {
String sashStateStr = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.ENTITY_EDITOR_INFO_SASH_STATE);
int sashPanelHeight = !CommonUtils.isEmpty(sashStateStr) ? Integer.parseInt(sashStateStr) : 400;
if (sashPanelHeight < 0) sashPanelHeight = 0;
if (sashPanelHeight > 1000) sashPanelHeight = 1000;

sashForm.setWeights(new int[] { sashPanelHeight, 1000 - sashPanelHeight });
//sashForm.layout();

sashForm.getChildren()[0].addListener(SWT.Resize, event -> {
if (sashForm != null) {
int[] weights = sashForm.getWeights();
if (weights != null && weights.length > 0) {
int topWeight = weights[0];
if (topWeight == 0) topWeight = 1;
DBWorkbench.getPlatform().getPreferenceStore().setValue(NavigatorPreferences.ENTITY_EDITOR_INFO_SASH_STATE, topWeight);
}
}
});
}
*/
}

}
143 changes: 143 additions & 0 deletions test/dataset_collection/InlineTestExamples/ObjectProperties_cut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@

public class ObjectPropertiesEditor extends AbstractDatabaseObjectEditor<DBSObject> implements IEntityStructureEditor,
IRefreshablePart,
IProgressControlProvider,
ITabbedFolderContainer,
ISearchContextProvider,
INavigatorModelView,
IEntityEditorContext,
IDatabasePostSaveProcessor
{
private void createPropertyBrowser(Composite container)
{
pageControl.setRedraw(false);
try {
TabbedFolderInfo[] folders = collectFolders(this);
if (folders.length == 0) {
createPropertiesPanel(container);
} else {
Composite foldersParent = container;
if (hasPropertiesEditor() && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.ENTITY_EDITOR_DETACH_INFO)) {
sashForm = UIUtils.createPartDivider(getSite().getPart(), container, SWT.VERTICAL);
sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
foldersParent = sashForm;

createPropertiesPanel(sashForm);
}
createFoldersPanel(foldersParent, folders);
}

// Create props
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.ENTITY_EDITOR_DETACH_INFO)) {
if (hasPropertiesEditor()) {
propertiesPanel = new TabbedFolderPageForm(this, pageControl, getEditorInput());

propertiesPanel.createControl(propsPlaceholder);
}
}

if (sashForm != null) {
//Runnable sashUpdater = this::updateSashWidths;
//sashUpdater.run();
//UIUtils.asyncExec(sashUpdater);
if (sashForm.isDisposed()) {
return;
}

// if (propsPlaceholder != null) {
Point propsSize = propsPlaceholder.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point sashSize = sashForm.getParent().getSize();
if (sashSize.x <= 0 || sashSize.y <= 0) {
// This may happen if EntityEditor created with some other active editor (i.e. props editor not visible)
propsSize.y += 10;
sashSize = getParentSize(sashForm);
//sashSize.y += 20;
}
if (sashSize.x > 0 && sashSize.y > 0) {
float ratio = (float) propsSize.y / (float) sashSize.y;
int propsRatio = Math.min(1000, (int) (1000 * ratio));
int[] newWeights = {propsRatio, 1000 - propsRatio};
if (!Arrays.equals(newWeights, sashForm.getWeights())) {
sashForm.setWeights(newWeights);
//sashForm.layout();
}
}

/*
} else {
String sashStateStr = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.ENTITY_EDITOR_INFO_SASH_STATE);
int sashPanelHeight = !CommonUtils.isEmpty(sashStateStr) ? Integer.parseInt(sashStateStr) : 400;
if (sashPanelHeight < 0) sashPanelHeight = 0;
if (sashPanelHeight > 1000) sashPanelHeight = 1000;

sashForm.setWeights(new int[] { sashPanelHeight, 1000 - sashPanelHeight });
//sashForm.layout();

sashForm.getChildren()[0].addListener(SWT.Resize, event -> {
if (sashForm != null) {
int[] weights = sashForm.getWeights();
if (weights != null && weights.length > 0) {
int topWeight = weights[0];
if (topWeight == 0) topWeight = 1;
DBWorkbench.getPlatform().getPreferenceStore().setValue(NavigatorPreferences.ENTITY_EDITOR_INFO_SASH_STATE, topWeight);
}
}
});
}
*/
}
pageControl.layout(true, true);
} finally {
pageControl.setRedraw(true);
}
}

private void updateSashWidths() {
if (sashForm.isDisposed()) {
return;
}

// if (propsPlaceholder != null) {
Point propsSize = propsPlaceholder.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point sashSize = sashForm.getParent().getSize();
if (sashSize.x <= 0 || sashSize.y <= 0) {
// This may happen if EntityEditor created with some other active editor (i.e. props editor not visible)
propsSize.y += 10;
sashSize = getParentSize(sashForm);
//sashSize.y += 20;
}
if (sashSize.x > 0 && sashSize.y > 0) {
float ratio = (float) propsSize.y / (float) sashSize.y;
int propsRatio = Math.min(1000, (int) (1000 * ratio));
int[] newWeights = {propsRatio, 1000 - propsRatio};
if (!Arrays.equals(newWeights, sashForm.getWeights())) {
sashForm.setWeights(newWeights);
//sashForm.layout();
}
}

/*
} else {
String sashStateStr = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.ENTITY_EDITOR_INFO_SASH_STATE);
int sashPanelHeight = !CommonUtils.isEmpty(sashStateStr) ? Integer.parseInt(sashStateStr) : 400;
if (sashPanelHeight < 0) sashPanelHeight = 0;
if (sashPanelHeight > 1000) sashPanelHeight = 1000;

sashForm.setWeights(new int[] { sashPanelHeight, 1000 - sashPanelHeight });
//sashForm.layout();

sashForm.getChildren()[0].addListener(SWT.Resize, event -> {
if (sashForm != null) {
int[] weights = sashForm.getWeights();
if (weights != null && weights.length > 0) {
int topWeight = weights[0];
if (topWeight == 0) topWeight = 1;
DBWorkbench.getPlatform().getPreferenceStore().setValue(NavigatorPreferences.ENTITY_EDITOR_INFO_SASH_STATE, topWeight);
}
}
});
}
*/
}

}
30 changes: 30 additions & 0 deletions test/dataset_collection/test_dataset_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ def test_is_valid_function_with_one_return(self):
is_matched = is_match_to_the_conditions(self.example_ast, m_inv, m_decl_original)
self.assertEqual(is_matched, True)

def test_invocation_inside_if_not_process(self):
filepath = self.current_directory / "Example_nested.java"
ast = AST.build_from_javalang(build_ast(filepath))
m_decl = [
x for x in ast.get_proxy_nodes(ASTNodeType.METHOD_DECLARATION)
if x.name == 'doAction'][0]
m_decl_original = [
x for x in ast.get_proxy_nodes(ASTNodeType.METHOD_DECLARATION)
if x.name == 'handleAction'][0]
m_inv = [
x for x in ast.get_subtree(m_decl).get_proxy_nodes(ASTNodeType.METHOD_INVOCATION)
if x.member == 'handleAction'][0]
is_matched = is_match_to_the_conditions(ast, m_inv, m_decl_original)
self.assertEqual(is_matched, False)

def test_is_valid_function_with_return_in_the_middle(self):
m_decl_original = [
x for x in self.example_ast.get_proxy_nodes(ASTNodeType.METHOD_DECLARATION)
Expand Down Expand Up @@ -329,6 +344,21 @@ def test_inline_strange_body2(self):
open(test_filepath, encoding='utf-8') as test_ex:
self.assertEqual(actual_file.read(), test_ex.read())

def test_inline_comments_at_the_end(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some empty lines in the method body to break it into logical blocks for better understandability.

filepath = self.current_directory / 'InlineExamples' / 'ObjectProperties_cut.java'
test_filepath = self.current_directory / 'InlineTestExamples' / 'ObjectProperties_cut.java'
algorithm_type = InlineTypesAlgorithms.WITHOUT_RETURN_WITHOUT_ARGUMENTS
algorithm_for_inlining = AlgorithmFactory().create_obj(algorithm_type)
ast = AST.build_from_javalang(build_ast(filepath))
m_decl = [
x for x in ast.get_proxy_nodes(ASTNodeType.METHOD_DECLARATION)
if x.name == 'updateSashWidths'][0]
lyriccoder marked this conversation as resolved.
Show resolved Hide resolved
body_start_line, body_end_line = method_body_lines(m_decl, filepath)
algorithm_for_inlining().inline_function(filepath, 43, body_start_line, body_end_line, self.temp_filename)
with open(self.temp_filename, encoding='utf-8') as actual_file, \
open(test_filepath, encoding='utf-8') as test_ex:
self.assertEqual(actual_file.read(), test_ex.read())

def test_method_body_lines_1(self):
m_decl = [
x for x in self.example_ast.get_proxy_nodes(ASTNodeType.METHOD_DECLARATION)
Expand Down
Loading