[Bug]: Refactoring via changeTypeName does not change all references
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2k
- Forks
- 393
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 36
Description
### Describe the bug
Calling `Refactoring.changeTypeName( clazz, newName );` does not change all references to a class. In particular, instantiations by invoking `new` appear to be ignored.
### Source code you are trying to analyze/transform
```Java
cd /tmp
git clone https://github.com/DaveJarvis/nts
```
### Source code for your Spoon processing
``` Java
import spoon.Launcher;
import spoon.refactoring.Refactoring;
import spoon.support.sniper.SniperJavaPrettyPrinter;
import java.io.File;
import java.util.regex.Pattern;
public class App {
public static void main( final String[] args ) {
final var outputDir = new File("/tmp/nts-new");
final var spoon = new Launcher();
final var env = spoon.getEnvironment();
env.setPrettyPrinterCreator(
() -> new SniperJavaPrettyPrinter( env )
);
spoon.setSourceOutputDirectory( outputDir );
spoon.addInputResource( "/tmp/nts/app/src/main/java/nts/app" );
spoon.addInputResource( "/tmp/nts/dvi/src/main/java/nts/dvi" );
spoon.addInputResource( "/tmp/nts/png/src/main/java/nts/png" );
spoon.addInputResource( "/tmp/nts/svg/src/main/java/nts/svg" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/align" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/base" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/builder" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/command" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/hyph" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/io" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/math" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/noad" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/node" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/render" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/tex" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/tfm" );
spoon.addInputResource( "/tmp/nts/tex/src/main/java/nts/typo" );
spoon.addInputResource( "/tmp/nts/tex/src/test/java/nts/io" );
final var model = spoon.buildModel();
final var p = Pattern.compile( "^(?!Kt).*" );
for( final var clazz : model.getAllTypes() ) {
final var name = clazz.getSimpleName();
final var m = p.matcher( name );
if( m.matches() ) {
final var newName = "Kt" + name;
System.out.println( "rename " + name + " to " + newName );
Refactoring.changeTypeName( clazz, newName );
}
}
if( outputDir.exists() || outputDir.mkdirs() ) {
spoon.prettyprint();
}
}
}
```
### Actual output
The class `KtAccentNoad` contains the following line:
```Java
KtNoad noad = new OrdNoad(nucleus);
```
### Expected output
The class `KtAccentNoad` contains the following line:
```Java
KtNoad noad = new KtOrdNoad(nucleus);
```
### Spoon Version
Latest
### JVM Version
18
### What operating system are you using?
Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Refactoring.changeTypeName and reproduce the reported case with the provided App processing code and nts source tree. Trace how type references are updated, paying particular attention to constructor invocations, and verify that the generated KtAccentNoad code changes new OrdNoad to new KtOrdNoad.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100