-
Notifications
You must be signed in to change notification settings - Fork 1
Understanding current Scala implementations
The Scala implementation studied is implemented in the Intellij Community Scala plugin in this precise folder.
-
Check if the last selected statement is a
return, and get its type. -
Check if there is a
returnstatement in the selected statements. -
Find smallest scope to scan for
siblings.
val visitor = new ScalaRecursiveElementVisitor {
override def visitReference(ref: ScReference): Unit = {
scopeBound(ref) match {
case Some(bound: PsiElement) if PsiTreeUtil.isAncestor(result, bound, true) => result = bound
case _ =>
}
}
}It appears to restrict the bound each time a new one that is smaller is found.
-
Find the
siblingswhich are parents of the first element that are within scope. -
Invoke dialog:
a. Use CFG to findReaching Definitionsfor the elements and itssiblingand calculate possible input and output variables.
b. Get user's input for selecting input and output variables then generate settings for creating method. -
Perform refactoring:
a. Create method from settings (need more work to find out details that could impact lifetime).
b. Insert method according to settings.
The scoping here cannot account for the lifetime requirement of Rust using only Reaching Definition criteria alone. The create method function (need further work) need to also be customizable to different ownership modes in Rust.
https://youtu.be/IPO-cY_giNA?t=546
https://plugins.jetbrains.com/docs/intellij/navigating-psi.html#bottom-up-navigation
https://en.wikipedia.org/wiki/Visitor_pattern
https://plugins.jetbrains.com/docs/intellij/psi-references.html
https://en.wikipedia.org/wiki/Reaching_definition