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

How to deep clone a CTExpression? #1978

Closed
krlu opened this issue Apr 26, 2018 · 6 comments
Closed

How to deep clone a CTExpression? #1978

krlu opened this issue Apr 26, 2018 · 6 comments
Labels

Comments

@krlu
Copy link

krlu commented Apr 26, 2018

I'm noticing that when I do a transformation on a CTElement (specifically an expression) it does not create a new element but rather mutates the original .

I would like to copy the original element and output a transformed version (i.e. using replace, add, or delete) without modifying the original element.

Any suggestions much appreciated!

@tdurieux
Copy link
Collaborator

Use the clone method that is available on all CtElement

@krlu
Copy link
Author

krlu commented Apr 26, 2018

Ah yes, I forgot to mention I tried that but then my code doesn't build.

Error:(60, 35) method clone in class Object cannot be accessed in spoon.reflect.code.CtExpression[Any]
Access to protected method clone not permitted because
prefix type spoon.reflect.code.CtExpression[Any] does not conform to
object ProgramTransformer in package codeanalysis where the access take place
constantFieldAssignments.head.clone()

@tdurieux
Copy link
Collaborator

Are you in Scala?

@krlu
Copy link
Author

krlu commented Apr 26, 2018

Yes I am using Scala 2.12

@monperrus
Copy link
Collaborator

And what about Factory#clone?

@monperrus monperrus changed the title Trying to deep clone a CTExpression How to deep clone a CTExpression? Apr 30, 2018
@monperrus
Copy link
Collaborator

Closing this issue, don't hesitate to reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants