Inspired by the discussion here: http://www.intellij.net/tracker/idea/viewSCR?publicId=14308
I've decided to write a little and very simple plugin that can be used to evaluate the proposed
functionality and to allow everybody who is interested to make up their minds about this feature.
The plugin intercepts the Introduce Variable action if there is no selection and tries to select the
most complete expression, stopping at parameter lists in method calls. Simple reference expressions
like foo, Class.FIELD and literals are ignored in argument lists and the search for the
I don't know yet if it's useful... I'll have to use it for some time to make up my mind myself.
Examples (| = caret, resulting selection in ):
JFrame frame = new JFrame(["Greatest app in world - " + project.getName()]|);
final PsiElement startElement = psiFile.findElementAt(|);
final Project project = (Project)dataContext.getData(DataConstants.PROJECT;
The plugin can be temporarily disabled with Options->Smart Introduce Variable
NOTE: The plugin was developed to work with IDEA build #873 and uses the unofficial PSI-API.
The plugin isn't heavily tested. If you are using it and experience crashes with Introduce
Variable, please check the stack trace first before submitting an SCR to the tracker.