Skip to content
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

File rename refactoring also renames constructor #785

Closed
mayakwd opened this issue Mar 27, 2018 · 5 comments

Comments

@mayakwd
Copy link
Member

commented Mar 27, 2018

Actual behavior:

class Test {
  public function new() {
  }
}

After rename:

class RenamedTest {
  public function RenamedTest() {
  }
}

Expected result: constructor's name remaining the same

@mayakwd mayakwd self-assigned this Mar 27, 2018

@mayakwd mayakwd changed the title Class rename refactoring also renames constructor File rename refactoring also renames constructor Mar 27, 2018

@mayakwd mayakwd added Priority 4 and removed Priority 2 labels Mar 28, 2018

@mayakwd

This comment has been minimized.

Copy link
Member Author

commented Mar 28, 2018

During investigation I discovered that it's not possible to fix issue by implement custom RenameProcessor. It happens because all compatible rename processors are triggered in the rename chain. RenameJavaClassProcessor is compatible as well because the only guard that it uses: "PsiElement should be instance of PsiClass", and it renaming the class constructor. The only possible solution without rewriting whole plugin psi-structures is to rename constructor backward after it was renamed.

@EricBishton

This comment has been minimized.

Copy link
Member

commented Jan 16, 2019

Also see #292, #776

@EricBishton

This comment has been minimized.

Copy link
Member

commented Jan 17, 2019

To be clear: Refactor->Rename File... does NOT change the name of the constructor, but it does change the name of the class (correctly). Refactor->Rename... (Shift+F6), which is a more common operation, exhibits the bug.

Verified on 1.1(+develop).

@EricBishton

This comment has been minimized.

Copy link
Member

commented Jan 18, 2019

Turns out that if you change the class name when the class name is under the cursor, then everything works correctly. However, if the cursor is on a secondary position (e.g. the return type specification for a function), then the constructor's name will be changed.

Also, selecting the name to change as part of a new expression (var a = new Thing();) will NOT change the name of the constructor OR the instance that was under the cursor.

Placing the cursor on the function name new on the constructor and refactoring will change the name of the constructor (so it's not a constructor any more) but does not affect other new expressions that refer to the constructor. (Not sure what correct behavior should be here.)

@EricBishton

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

Fixed #922

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.