Open krlu opened 5 years ago
Which type of element are you cloning? What happens when you call el.clone()
?
I'm using CtMethod When I do method.Clone() i get the following issue:
Error:(199, 12) method clone in class Object cannot be accessed in spoon.reflect.declaration.CtMethod[Any]
Access to protected method clone not permitted because
prefix type spoon.reflect.declaration.CtMethod[Any] does not conform to
object ProgramTransformer in package analysis where the access takes place
method.clone()
I should mention, I am doing these operations using scala, not java. Could that be a problem?
@monperrus any suggestions?
The problem comes from Scala and is related to #2710. I'm not knowledgeable enough in Scala to fix it. But I'd be happy to merge a PR that makes the life of Scala users easier.
Ah i see, ok I'll see what I can do. I'm happy to close this issue.
@monperrus
Hey I wanted to give an update. While not ideal, I find that if I encapsulate the el.clone() method call inside a java class and invoke that java class in my scala code, everything works just fine.
While I'm too busy to package that up nicely and submit a formal PR, I suspect the best thing to do would be to create a java utility method (i.e. CtElementUtil) that contains a trivial clone method, shown below. Perhaps one of you guys can do that?
public static CtElement clone(CtElement originalCtElement){
return originalCtElement.clone()
}
that's a good idea!
I would like to deep copy the entire AST of a CtElement, especially when I want to use parts of the sub-tree to create brand new CtElements
The Clone method available to all
CtElement
types are protected I had this issue last year, see link below1978
Any help much appreciated!