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 all 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
Empty file added test/augmentation/__init__.py
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions test/dataset_collection/InlineExamples/AbstractMarshaller_cut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {

public synchronized void removeChild(String propertyName, C component) {
verifyWrite();
if (component == null) {
throw new IllegalArgumentException("component == null"); //NOI18N
}
if (! _getChildren().contains(component)) {
throw new IllegalArgumentException(
"component to be deleted is not a child"); //NOI18N
}
_removeChildQuietly(component, _getChildren());
firePropertyChange(propertyName, component, null);
fireChildRemoved();
}

protected void fireChildRemoved() {
getModel().fireComponentChangedEvent(new ComponentEvent(this,
ComponentEvent.EventType.CHILD_REMOVED));
}
}
42 changes: 42 additions & 0 deletions test/dataset_collection/InlineExamples/EntityResolver_cut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
public abstract class Test {
private static final EntityResolver NO_OP_ENTITY_RESOLVER =
(publicId, systemId) -> new InputSource(new StringReader(""));

/** Logger available to subclasses. */
protected final Log logger = LogFactory.getLog(getClass());

private boolean supportDtd = false;

private boolean processExternalEntities = false;

@Nullable
private DocumentBuilderFactory documentBuilderFactory;

private final Object documentBuilderFactoryMonitor = new Object();

protected Document buildDocument() {
try {
DocumentBuilder documentBuilder;
synchronized (this.documentBuilderFactoryMonitor) {
if (this.documentBuilderFactory == null) {
this.documentBuilderFactory = createDocumentBuilderFactory();
}
documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
}
return documentBuilder.newDocument();
}
catch (ParserConfigurationException ex) {
throw new UnmarshallingFailureException("Could not create document placeholder: " + ex.getMessage(), ex);
}
}

protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd());
factory.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities());
return factory;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {

public synchronized void removeChild(String propertyName, C component) {
verifyWrite();
if (component == null) {
throw new IllegalArgumentException("component == null"); //NOI18N
}
if (! _getChildren().contains(component)) {
throw new IllegalArgumentException(
"component to be deleted is not a child"); //NOI18N
}
_removeChildQuietly(component, _getChildren());
firePropertyChange(propertyName, component, null);
getModel().fireComponentChangedEvent(new ComponentEvent(this,
ComponentEvent.EventType.CHILD_REMOVED));
}

protected void fireChildRemoved() {
getModel().fireComponentChangedEvent(new ComponentEvent(this,
ComponentEvent.EventType.CHILD_REMOVED));
}
}
47 changes: 47 additions & 0 deletions test/dataset_collection/InlineTestExamples/EntityResolver_cut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
public abstract class Test {
private static final EntityResolver NO_OP_ENTITY_RESOLVER =
(publicId, systemId) -> new InputSource(new StringReader(""));

/** Logger available to subclasses. */
protected final Log logger = LogFactory.getLog(getClass());

private boolean supportDtd = false;

private boolean processExternalEntities = false;

@Nullable
private DocumentBuilderFactory documentBuilderFactory;

private final Object documentBuilderFactoryMonitor = new Object();

protected Document buildDocument() {
try {
DocumentBuilder documentBuilder;
synchronized (this.documentBuilderFactoryMonitor) {
if (this.documentBuilderFactory == null) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd());
factory.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities());
this.documentBuilderFactory = factory;
}
documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
}
return documentBuilder.newDocument();
}
catch (ParserConfigurationException ex) {
throw new UnmarshallingFailureException("Could not create document placeholder: " + ex.getMessage(), ex);
}
}

protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd());
factory.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities());
return factory;
}

}
3 changes: 1 addition & 2 deletions test/dataset_collection/InlineTestExamples/PlanetDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public PlanetDialog(){
bloom.dispose();
bloom = null;
}

bloom = new Bloom(Core.graphics.getWidth()/4, Core.graphics.getHeight()/4, true, false, true){{
bloom = new Bloom(Core.graphics.getWidth()/4, Core.graphics.getHeight()/4, true, false, true){{
setClearColor(0, 0, 0, 0);
setThreshold(0.8f);
blurPasses = 6;
Expand Down
29 changes: 28 additions & 1 deletion test/dataset_collection/test_dataset_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
is_match_to_the_conditions)
from veniq.ast_framework import AST, ASTNodeType
from veniq.dataset_collection.types_identifier import (
InlineTypesAlgorithms, InlineWithoutReturnWithoutArguments, InlineWithReturnWithoutArguments)
InlineTypesAlgorithms,
InlineWithoutReturnWithoutArguments,
InlineWithReturnWithoutArguments,
AlgorithmFactory)
from veniq.utils.ast_builder import build_ast


Expand Down Expand Up @@ -277,3 +280,27 @@ def test_is_valid_function_with_return_in_the_middle(self):
if x.member == 'severalReturns'][0]
is_matched = is_match_to_the_conditions(ast, m_inv, m_decl_original)
self.assertEqual(is_matched, False)

def test_inline_invocation_inside_var_declaration(self):
filepath = self.current_directory / 'InlineExamples' / 'EntityResolver_cut.java'
test_filepath = self.current_directory / 'InlineTestExamples' / 'EntityResolver_cut.java'
temp_filename = self.current_directory / 'temp.java'
algorithm_type = InlineTypesAlgorithms.WITH_RETURN_WITHOUT_ARGUMENTS
algorithm_for_inlining = AlgorithmFactory().create_obj(algorithm_type)
algorithm_for_inlining().inline_function(filepath, 22, 34, 40, temp_filename)
with open(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())
temp_filename.unlink()

def test_inline_inside_invokation_several_lines(self):
filepath = self.current_directory / 'InlineExamples' / 'AbstractMarshaller_cut.java'
test_filepath = self.current_directory / 'InlineTestExamples' / 'AbstractMarshaller_cut.java'
temp_filename = self.current_directory / 'temp.java'
algorithm_type = InlineTypesAlgorithms.WITH_RETURN_WITHOUT_ARGUMENTS
algorithm_for_inlining = AlgorithmFactory().create_obj(algorithm_type)
algorithm_for_inlining().inline_function(filepath, 14, 18, 20, temp_filename)
with open(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())
temp_filename.unlink()
Loading