Overriding ChangeSignatureDialogBase, createParametersInfoModel troubles

What I'm attempting to do is override ChangeSignatureDailoBase so that I can piggyback off of the existing refactoring code in order to create a plugin I need. My plugin is pretty simple:I have XML files which are metadata representing Java Classes that I generate at compile time.What I'm attempting to do via plugin is I can go to the Refactor Menu in one of the XML files, click on a new Action I added, and it shows a list of all class properties and let's me edit the name, return type, and parameter type (each generated method only has at most 1 parameter). When "Ok" is clicked on this Dialog, it should find the Java file that this XML file has generated before, and refactor each one of these method signatures using the existing refactor code. This will mean all of the usages will be udpated too.

So far I'm at the point where I am showing the existing Change Signature Dialog and I'm having trouble changing how it looks. For the name it shouldn't say the name of the method, but the new name that was entered on the previous Dialog. I got that working easily by just setting the text on myNameField. Likewise, the return type is easy to change what is shown by just setting the text on myReturnTypeField. The problem is I need to change the parameter info if the method has a parameter. This isn't so easy because it's accessed inside a JBTable in the form of a ParameterTableModelBase.

This code is executed in JavaChangeSignatureDialog:

  protected ParameterTableModelBase<ParameterInfoImpl> createParametersInfoModel(MethodDescriptor<ParameterInfoImpl> descriptor) {
    final PsiParameterList parameterList = ((JavaMethodDescriptor)descriptor).getMethod().getParameterList();
    return new JavaParameterTableModel(parameterList, myDefaultValueContext, this);

Now, the method passed in is the method that is actually in the file I'm refactoring. My new parameter type is passed in elsewhere and it's just a String. I need to somehow create a method that doesn't exist and use that here instead of using descriptor.getMethod. How can I do this?

Is there a way I can create a method but not put it into a file? That way I could have a reference to that and pass it along into the refactoring dialog.

For your reference, here are the Classes I'm having trouble with:


1 comment
Comment actions Permalink

Not 10 minutes after asking this question, I skimmed through one of the webinars again and found this code:

PsiMethod method = JavaPsiFacade.getElementFactory(project).createMethodFromText(string, psiClass);

This might be exactly what I'm looking for? I could create this after my first dialog, and then pass this in to the 2nd dialog so that it can have the correct parameter type?


Please sign in to leave a comment.