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

Renaming target or reference using constructor parameter name doesn't work #127

Closed
KENNYSOFT opened this issue Apr 23, 2023 · 2 comments
Closed

Comments

@KENNYSOFT
Copy link
Contributor

testData/rename/RenamingConstructorTargetParameter.java & RenamingConstructorTargetParameterAfter.java

Expected behavior

 /*
  * Copyright MapStruct Authors.
  *
  * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
  */
 package org.mapstruct.intellij.test.examples;
 
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 
 @Mapper
 public interface SimpleMapper {
 
-    @Mapping(source = "name", target = "testName<caret>")
+    @Mapping(source = "name", target = "newName<caret>")
     Target map(Source source);
 
     class Source {
 
         private String name;
 
         public String getName() {
             return name;
         }
 
         public void setName(String name) {
             this.name = name;
         }
     }
 
     class Target {
 
         private String testName;
 
         public String getTestName() {
             return testName;
         }
 
-        public Target(String testName) {
-            this.testName = testName;
+        public Target(String newName) {
+            this.testName = newName;
         }
     }
 }

Actual result

java.lang.Throwable: file: PsiJavaFile:RenameConstructorTargetParameter.java container: RangeMarker(729,809) 6 markers: [[testName]336, 344], [[testName]750, 758], [[testName]790, 798]
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:182)
at com.intellij.codeInsight.template.TemplateBuilderImpl.initTemplate(TemplateBuilderImpl.java:212)
at com.intellij.codeInsight.template.TemplateBuilderImpl.buildTemplate(TemplateBuilderImpl.java:202)
at com.intellij.codeInsight.template.TemplateBuilderImpl.buildInlineTemplate(TemplateBuilderImpl.java:179)
at com.intellij.refactoring.rename.inplace.InplaceRefactoring.startTemplate(InplaceRefactoring.java:412)
at com.intellij.refactoring.rename.inplace.InplaceRefactoring.lambda$buildTemplateAndStart$0(InplaceRefactoring.java:360)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:143)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:936)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:141)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:216)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:182)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:150)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:117)
at com.intellij.refactoring.rename.inplace.InplaceRefactoring.buildTemplateAndStart(InplaceRefactoring.java:360)
at com.intellij.refactoring.rename.inplace.VariableInplaceRenamer.buildTemplateAndStart(VariableInplaceRenamer.java:116)
at com.intellij.refactoring.rename.inplace.InplaceRefactoring.performInplaceRefactoring(InplaceRefactoring.java:211)
at com.intellij.refactoring.rename.inplace.VariableInplaceRenamer.performInplaceRename(VariableInplaceRenamer.java:91)
at com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler.doRename(VariableInplaceRenameHandler.java:119)

Actually, I don't think VariableInplaceRenameHandler should be called. We have MapstructSourceTargetParameterRenameHandler, but it just handles PsiMethod so it was passed.

But changing it to accept PsiParameter also does not fix the problem:

  1. VariableInplaceRenameHandler is not disabled so there are two choices for the rename.
    image
  2. Renaming by selecting custom handler only changes the name of the constructor parameter, not the target string literal.

testData/usages/RenameConstructorTargetReference.java & RenameConstructorTargetReferenceAfter.java

Expected behavior

 /*
  * Copyright MapStruct Authors.
  *
  * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
  */
 package org.mapstruct.intellij.test.examples;
 
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 
 @Mapper
 public interface SimpleMapper {
 
-    @Mapping(source = "name", target = "testName")
+    @Mapping(source = "name", target = "newName")
     Target map(Source source);
 
     class Source {
 
         private String name;
 
         public String getName() {
             return name;
         }
 
         public void setName(String name) {
             this.name = name;
         }
     }
 
     class Target {
 
         private String testName;
 
         public String getTestName() {
             return testName;
         }
 
-        public Target(String testName<caret>) {
-            this.testName = testName;
+        public Target(String newName<caret>) {
+            this.testName = newName;
         }
     }
 }

Actual result

Renaming only changes the name of the constructor parameter, not the target string literal.

@filiphr
Copy link
Member

filiphr commented Apr 23, 2023

Thanks for reporting this @KENNYSOFT. I'll need to investigate how to hide the VariableInplaceRenameHandler, I remember needing to do something similar for the method one

@filiphr
Copy link
Member

filiphr commented Apr 23, 2023

This is actually the same as #46, which I just remember that I was trying to fix at some point, but without much success. I'll close this so that we can use #46 for fixing this.

@filiphr filiphr closed this as completed Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants