INRIA / INRIA/spoon

Set position on CtClass after changing its name

Open
#3,039 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

Hey,

I am holding some CtClass-elements in my application representing the source files of a project. The Class names of these objects then may change (`setSimpleName("NewName"))` which gets propagated to the underlying java project. The changed .java-files get simply created by calling `prettyprint()` on the launcher and I for now manually delete the old files via `getPosition().getFile().delete()`.

Now, when this happens a second time at runtime - meaning the CtClass gets its simpleName changed a 2nd time - the deleting of the former file does not work. I guess this is due to the fact that its SourcePosition did not get changed along with the renaming of the class-name. So I would have to somehow manually change the SourcePosition to the newly created file with the new class name everytime it gets changed, so I can delete it when it gets changed further times at runtime.

The `setPosition()` method requires a `SourcePosition` object. My guess was to retrieve the old SourcePosition object and simply change the file to its new location with the changed name of the .java-file. But there is nothing like `setFile()` on SourcePosition.

So how can I change the SourcePosition of a CtClass so it still holds the position of the respective file after having changed its class-name at runtime?

Thanks a lot.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.