[ClavaAst] FunctionDecl.cloneAndInsert() insertion is now optional
@@ -854,15 +854,15 @@ public class FunctionDecl extends DeclaratorDecl implements NodeWithScope {
* @return the definition or the declaration of the cloned function, according to this node being a definition or a
* declaration.
*/
- public FunctionDecl cloneAndInsert(String newName) {
- return cloneAndInsert(newName, null);
+ public FunctionDecl cloneAndInsert(String newName, boolean insert) {
+ return cloneAndInsert(newName, null, insert);
}
- public FunctionDecl cloneAndInsertOnFile(String newName, TranslationUnit destinationUnit) {
- return cloneAndInsert(newName, destinationUnit);
+ public FunctionDecl cloneAndInsertOnFile(String newName, TranslationUnit destinationUnit, boolean insert) {
+ return cloneAndInsert(newName, destinationUnit, insert);
}
- private FunctionDecl cloneAndInsert(String newName, TranslationUnit destinationUnit) {
+ private FunctionDecl cloneAndInsert(String newName, TranslationUnit destinationUnit, boolean insert) {
// Get both declaration and definition (if present)
Optional<FunctionDecl> definition = getDefinition();
Optional<FunctionDecl> declaration = getDeclaration();
@@ -871,6 +871,7 @@ public class FunctionDecl extends DeclaratorDecl implements NodeWithScope {
Optional<FunctionDecl> newDeclaration = declaration.map(decl -> ((FunctionDecl) decl.copy()).setName(newName));
+ if (insert) {
if (destinationUnit == null) {
definition.ifPresent(def -> NodeInsertUtils.insertAfter(def, newDefinition.get()));
declaration.ifPresent(decl -> NodeInsertUtils.insertAfter(decl, newDeclaration.get()));
@@ -888,6 +889,7 @@ public class FunctionDecl extends DeclaratorDecl implements NodeWithScope {
*/
}
+ }
// Return corresponding clone
if (hasBody()) {
