OpenAPI: Can't seem to trigger "Introduce" refactorings.


I'm trying to get the various "Introduce Variable/Constant/Parameter" refactorings to work from a plugin quickfix, and don't seem to be able to. The following works fine for "Move" and "Rename" refactorings,
but does nothing for the Introduce refactorings.


Any ideas?

--Dave Griffith

3 comments
Comment actions Permalink

Dave Griffith wrote:


I'm trying to get the various "Introduce Variable/Constant/Parameter"
refactorings to work from a plugin quickfix, and don't seem to be able to.
The following works fine for "Move" and "Rename" refactorings, but does
nothing for the Introduce refactorings.

         public void applyFix(Project project, ProblemDescriptor
>         descriptor)
>         {
>             final RefactoringActionHandler introduceHandler =
>            
RefactoringActionHandlerFactory.getInstance().createIntroduceConstantHandler();
>             final PsiElement constant = descriptor.getPsiElement();
>             introduceHandler.invoke(project, new PsiElement[]{constant},
>             null);
>         }
> ]]>


Yup, this is a limitation of RefactoringActionHandlers for Introduce...
stuff. It is documented in the upcoming build and I'll try to fix this
stuff if I have enough time.

Friendly,
Dmitry

--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

Dmitry Lomov (JetBrains) wrote:

Dave Griffith wrote:

>>
>> I'm trying to get the various "Introduce Variable/Constant/Parameter"
>> refactorings to work from a plugin quickfix, and don't seem to be able
>> to.
>> The following works fine for "Move" and "Rename" refactorings, but does
>> nothing for the Introduce refactorings.
>>
>>

>         public void applyFix(Project project, ProblemDescriptor
>>         descriptor)
>>         {
>>             final RefactoringActionHandler introduceHandler =
>>            
>
RefactoringActionHandlerFactory.getInstance().createIntroduceConstantHandler();
>>             final PsiElement constant = descriptor.getPsiElement();
>>             introduceHandler.invoke(project, new PsiElement[]{constant},
>>             null);
>>         }
>> ]]>


Yup, this is a limitation of RefactoringActionHandlers for Introduce...
stuff. It is documented in the upcoming build and I'll try to fix this
stuff if I have enough time.


It turns out I have had enough time. This is fixed and will be available in
the next build. Please try it.

Friendly,
Dmitry


--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink


Thanks Dmitry, this works perfectly. I've added "Introduce Constant" quickfixes for the "Magic Number", "Magic Character", "String Literal" and "Zero-length array initialization" IG inspections, and "Introduce Variable" quickfixes for "Nested Method Call" and "Chained Method Call". Very sweet.

--Dave Griffith

0

Please sign in to leave a comment.