-
Notifications
You must be signed in to change notification settings - Fork 201
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
Add regex stuff #529
Add regex stuff #529
Changes from 4 commits
4a413d0
f32bb95
80adac8
786dee6
2b0b086
6857c6e
99fd457
8ed0493
c55bca1
99d2218
1454962
3ac21b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -30,30 +30,75 @@ replace_node = "m_def" | |||||
replace = "fed" | ||||||
|
||||||
|
||||||
# The below three rules do a dummy type migration from List<Integer> to NewList | ||||||
# The below three rules do a dummy type migration from OurListOfInteger to List<Integer> | ||||||
|
||||||
# Updates the import statement from `java.util.List` to `com.uber.NEwList` | ||||||
# Updates the import statement from `java.util.List` to `com.uber.NewList` | ||||||
[[rules]] | ||||||
name = "update_import" | ||||||
query = """rgx (?P<n>java\\.util\\.List)""" | ||||||
query = """rgx (?P<n>our\\.list\\.OurListOfInteger)""" | ||||||
replace_node = "n" | ||||||
replace = "com.uber.NewList" | ||||||
replace = "java.util.List" | ||||||
|
||||||
# Updates the type of local variables from `List<Integer>` to `com.uber.NewList` | ||||||
# Updates the type of local variables from `OurListOfInteger` to `List<Integer>` | ||||||
[[rules]] | ||||||
name = "update_list_int" | ||||||
query = """rgx (?P<var_decl>(?P<type>List<Integer>)\\s*(?P<name>\\w+)\\s*=.*;)""" | ||||||
query = """rgx (?P<var_decl>(?P<type>OurListOf(?P<param>Integer))\\s*(?P<name>\\w+)\\s*=.*;)""" | ||||||
replace_node = "type" | ||||||
replace = "NewList" | ||||||
replace = "List<@param>" | ||||||
is_seed_rule = false | ||||||
[[rules.filter]] | ||||||
enclosing_node = "(method_declaration) @cmd" | ||||||
|
||||||
# Updates the relevant callsite from `add` to `addToNewList` | ||||||
# Updates the relevant callsite from `addToOurList` to `add` | ||||||
[[rules]] | ||||||
name = "update_add" | ||||||
query = """rgx (?P<call>@name\\.(?P<m_name>add)\\(\\w+\\))""" | ||||||
query = """rgx (?P<call>@name\\.(?P<m_name>addToOurList)\\(\\w+\\))""" | ||||||
replace_node = "m_name" | ||||||
replace = "addToNewList" | ||||||
replace = "add" | ||||||
holes = ["name"] | ||||||
is_seed_rule = false | ||||||
|
||||||
|
||||||
# The below three rules do a dummy type migration like - from OurMapOfStringInteger to HashMap<String, Integer> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# Deletes the import statement `our.map.OurMapOf...` | ||||||
[[rules]] | ||||||
name = "delete_import_our_map_of" | ||||||
query = """rgx (?P<n>import our\\.map\\.OurMapOf\\w+;)""" | ||||||
replace_node = "n" | ||||||
replace = "" | ||||||
|
||||||
# Adds Import to java.util.hashmap if absent | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
[[rules]] | ||||||
name = "add_import_For_hashmap" | ||||||
query = """(package_declaration) @pkg""" | ||||||
replace_node = "pkg" | ||||||
replace = "@pkg\nimport java.util.HashMap;" | ||||||
is_seed_rule = false | ||||||
[[rules.filters]] | ||||||
enclosing_node = "(program) @prgrm" | ||||||
not_contains = [ | ||||||
"((import_declaration) @im (#match? @im \"java.util.HashMap\"))", | ||||||
] | ||||||
|
||||||
# Before: | ||||||
# OurMapOfStringInteger | ||||||
# After: | ||||||
# HashMap<String, Integer> | ||||||
[[rules]] | ||||||
name = "change_type_from_OurHashMap" | ||||||
query = """rgx (?P<var_decl>(?P<type>\\bOurMapOf(?P<param1>[A-Z]\\w+)(?P<param2>[A-Z]\\w+))\\s*(?P<name>\\w+)\\s*=.*;)""" | ||||||
replace_node = "type" | ||||||
replace = "HashMap<@param1, @param2>" | ||||||
is_seed_rule = false | ||||||
[[rules.filter]] | ||||||
enclosing_node = "(method_declaration) @cmd" | ||||||
|
||||||
# Updates the relevant callsite from `pushIntoOurMap` to `push` | ||||||
[[rules]] | ||||||
name = "update_push" | ||||||
query = """rgx (?P<call>@name\\.(?P<m_name>pushIntoOurMap)\\(.*\\))""" | ||||||
replace_node = "m_name" | ||||||
replace = "push" | ||||||
holes = ["name"] | ||||||
is_seed_rule = false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every Or is something like that not meant to be supported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats a brilliant idea ! We can absolutely do that! Done ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.