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

Support for composite replacements #3

Open
4 of 13 tasks
tsantalis opened this issue Oct 19, 2022 · 5 comments
Open
4 of 13 tasks

Support for composite replacements #3

tsantalis opened this issue Oct 19, 2022 · 5 comments

Comments

@tsantalis
Copy link

tsantalis commented Oct 19, 2022

  • Traditional try replaced with try-with-resources

Composite replacement: the resource expressions correspond to extra statements
NLPchina/ansj_seg@913704e#diff-37efb71e313d229310c23302fb8788212cafe759abfdcca86e60fbde9deb7c7cR105

neo4j/neo4j@d3533c1#diff-b32651bf4edb0ff7028d860d1deed635ff9a5ab38b7e422d4bcca2eeccb36124R144

DataInputStream dis = null;
        try
        {
            FileInputStream fis = new FileInputStream(privateKeyFile);
            dis = new DataInputStream(fis);

becomes

try(DataInputStream in = new DataInputStream(new FileInputStream(privateKeyFile)))
  • Replace Loop with Pipeline

http://refactoring.encs.concordia.ca/oracle/tool-refactorings/RefactoringMiner/TP/Replace%20Loop%20With%20Pipeline

  • Replace Pipeline with Loop

junit-team/junit5@62c433c#diff-3679a3039f048d756df1feebd214cc17df7b0a686dc3be77f24bff5bc61bbf4cR203-R222

  • Split Conditional

kiegroup/drools@1bf2875#diff-1e1bf3853477703f78c734cfb42a7cb2a2a0e55e5ac89265a9a9e73982d5438bL231-L233

nutzam/nutz@6599c74#diff-d47d95ef90d7f70d88b06a02d8505b58a81c7c1174c2494e56c9b09d090bc6edL307

graphhopper/graphhopper@7f80425#diff-619f379c7f10d178fba87944b27d543e3f36a9d34803fbdd5ab964a8c9f60a86L943

BuildCraft/BuildCraft@6abc40e#diff-0850b8a596d522bb87b55e5a3799a56612654c4c2b7d86a8157bf2d6bb8e5e0cL353-L356

JetBrains/intellij-community@1b70adb#diff-618af48f6b6713ae4367692615f2309a93d3ac39eb4453167d89ed33d0f8e35aL160

apache/giraph@03ade42
if(!conf.isStaticGraph() && !file.delete()) to [if(!conf.isStaticGraph() || serviceWorker.getSuperstep() == BspServiceWorker.INPUT_SUPERSTEP), if(!file.delete())]

While Split to While + If
thymeleaf/thymeleaf@378ba37#diff-fe47a14afb3317314d81d6f5278d04b52ae3ce0d65dedc1d84cb6c40aa3908ceR270-R278

While Split to If + While
apache/drill@711992f#diff-6c459fac9e29d1448e6a4a08041df7c7250f6aed611eaa036a24a529196b490dR148-R151

JetBrains/intellij-community@9f7de20#diff-ed6bc52ae4591f4de13f2398154358599d6380ef4f524b4442c3176d82fb037cR105-R107

  • Iterator-based while replaced with enhanced-for

checkstyle/checkstyle@f1afaf8#diff-b48cc2ff38026f94180847550cd260a0ebefb4a9cb9635e39f5fa2046311d72bR474

  • Inlined statements

netty/netty@d31fa31#diff-ac1404c2792cc01bf80c28d4a352a533a9e8d2937e7b97d65d16842e2b7f1ad4L80-L84

JetBrains/intellij-community@ff46945#diff-195db6e789b2625726917559b766417af74e54362fa8580ca7d4681c8eb3a435R107

  • Builder call chain decomposed to individual statements

open-keychain/open-keychain@c11fef6#diff-4d4436d415b26cfa599819885f9510c2da0cd152fcd5e1898a135b29ca90bce8R136-R146

linkedin/rest.li@54fa890#diff-ad956a39fb8d6f1ba66cc531080cbc28877e2f10781c2633b0ccc321b69d1c00R231-R234
public onRestRequest(req RestRequest, requestContext RequestContext, wireAttrs Map<String,String>, nextFilter NextFilter<RestRequest,RestResponse>) : void
req.builder().addHeaderValue(HttpConstants.ACCEPT_ENCODING, _acceptEncodingHeader).build(); is extracted to
public addResponseCompressionHeaders(responseCompressionOverride CompressionOption, req RestRequest) : RestRequest

CyanogenMod/android_frameworks_base@910397f#diff-3915a87990e3c24a5f92c176d5f80db4fcc23d08ed9b59cc3ec048e262ac4491R114-R116

linkedin/rest.li@ec5ea36#diff-fdf9da24acd0f3b1439a8ce6c9fd04484e15222cc08f615e837fec6a69426081L55-L57

  • StringBuilder declaration in chain decomposed to individual statement

jfinal/jfinal@881baed#diff-e19efa6dd99d3caacc529cb4b7d1038422f5f791ce618b4c6c48cbf9d2ef68e3R112

  • Collection data entry replaced with Collection.of() factory method (Java 9)

iluwatar/java-design-patterns@dd971d8

  • Merge catch blocks with Intersection type

jersey/fab1516773d50bf86d9cc37e2f6db13496f0ecae
core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/JarFileScanner.java

} catch (final IOException e) {
    LOGGER.log(Level.CONFIG, "Unable to read the next jar entry.", e);
    return false;
} catch (final SecurityException e) {
    LOGGER.log(Level.CONFIG, "Unable to read the next jar entry.", e);
    return false;
}

becomes

} catch (final IOException | SecurityException e) {
    LOGGER.log(Level.CONFIG, LocalizationMessages.JAR_SCANNER_UNABLE_TO_READ_ENTRY(), e);
    return false;
}

Graylog2/graylog2-server@2ef067f

  • Merge Conditionals

spring-projects/spring-integration@247232b#diff-e69bfd584978efc415e3ea5cca8bf35c943372e7968d73fe1c4eea27a02d53d4R366

facebook/buck@f26d234#diff-8b1672ed0167e6b7a425fbf4a33be8fc18c01a3a79d830495e4835a41797de14R246

apache/cassandra@3566843#diff-a5de948460b9aa759b9c5af1da662661484df0820d82615af7028089a7e87331R87

addthis/hydra@7fea4c9#diff-6e31c93704ae2e71e5bcda132ae0f9cb9d6cca9a0169f14cf32bac7697fc7868R75-R80

kiegroup/drools@1bf2875#diff-59225e3f98b0396f7a4b33b3de9c5c8aeb2369d213e0ee3575c737179e7f7e60R57-R58

  • Merge Conditionals with Duplicated Code in branches

spring-projects/spring-framework@7dd8dc6?diff=split#diff-ea43e736983102ff93143d5a8e5a0e63837233bafa3a5f8bae78256211ed9113R230

liferay/liferay-plugins@7c7ecf4#diff-685c23de6ec190cf9008b52295e9fe3714c9efa7fcd94f7747abb8d56909b154R45-R50

  • Variable Declaration Split to Declaration + Assignment statement

https://github.com/flozender/jgit/commit/45e79a526c7ffebaf8e4758a6cb6b7af05716707?diff=split#diff-61139ff71d8675ad33d046412d1fca65a59c31c8325cc757238d3283eb2219f6R128

@pouryafard75
Copy link
Owner

pouryafard75 commented Jan 13, 2023

Iterator-based while replaced with enhanced-for:
The current diff output for the checkstyle/checkstyle@f1afaf8#diff-b48cc2ff38026f94180847550cd260a0ebefb4a9cb9635e39f5fa2046311d72bR474 is as follows:
image
@tsantalis What do we expect to be the proper mappings?

@pouryafard75
Copy link
Owner

The current diff output for the StringBuilder declaration in chain decomposed to individual statement jfinal/jfinal@881baed#diff-e19efa6dd99d3caacc529cb4b7d1038422f5f791ce618b4c6c48cbf9d2ef68e3R112 is as follows
image
Must be checked carefully later

@tsantalis
Copy link
Author

@pouryafard75
We could also have an expression mapping between the variable names mListeners and listener
I guess you would need a LeafExpression mapping in that case?

@tsantalis
Copy link
Author

@pouryafard75
Some of the append calls have not been mapped properly. In general, if the argument is mapped, then the corresponding append calls containing the same argument should be mapped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants