// Add as many ../ as folders in the relative folder
@Override
    // TODO: copy header file inclusion
    public AFunction cloneOnFileImpl(String newName, AFile file) {
        // if (!function.hasBody()) {
        // /*add the clone to the original place in order to be included where needed */
        // return makeCloneAndInsert(newName, function, true);
        // }
        /* if this is a definition, add the clone to the correct file */
        // App app = getRootImpl().getNode();
        //
        // Optional<TranslationUnit> file = app.getFile(fileName);
        //
        // if (!file.isPresent()) {
        //
        // TranslationUnit tu = getFactory().translationUnit(new File(fileName), Collections.emptyList());
        //
        // app.addFile(tu);
        //
        // file = Optional.of(tu);
        // }
        var tu = (TranslationUnit) file.getNode();
        var cloneFunction = makeCloneAndInsert(newName, tu, true);
        /* copy headers from the current file to the file with the clone */
        TranslationUnit originalFile = function.getAncestorTry(TranslationUnit.class).orElse(null);
        if (originalFile != null) {
            var includesCopy = TreeNodeUtils.copy(originalFile.getIncludes().getIncludes());
            // List<IncludeDecl> allIncludes = getIncludesCopyFromFile(originalFile);
            File baseIncludePath = null;
            // Add as many ../ as folders in the relative folder
            var relativeFolderDepth = tu.getRelativeFolderpath().map(folder -> SpecsIo.getDepth(new File(folder)))
                    .orElse(0);
            for (int i = 0; i < relativeFolderDepth; i++) {
                baseIncludePath = new File(baseIncludePath, "../");
            }
            // Add relative folder of original file
            var relativeDepth = baseIncludePath;
            baseIncludePath = originalFile.getRelativeFolderpath()
                    .map(relativeFolder -> new File(relativeDepth, relativeFolder))
                    .orElse(baseIncludePath);
            // System.out.println("BASE: " + baseIncludePath);
            // System.out.println("DEPTH: " + relativeFolderDepth);
            // Adapt includes
            for (var includeDecl : includesCopy) {
                var include = includeDecl.getInclude();
                // If angled, ignore
                if (include.isAngled()) {
                    continue;
                }
                // System.out.println("INCLUDE BEFORE: " + includeDecl.getCode());
                var newInclude = include.setInclude(new File(baseIncludePath, include.getInclude()).toString());
                includeDecl.set(IncludeDecl.INCLUDE, newInclude);
                // System.out.println("INCLUDE AFTER: " + includeDecl.getCode());
            }
            // Add includes
            includesCopy.stream().forEach(tu::addInclude);
        }
        return cloneFunction;
    }
// List<IncludeDecl> allIncludes = getIncludesCopyFromFile(originalFile);
File baseIncludePath = null;
// Add as many ../ as folders in the relative folder
var relativeFolderDepth = tu.getRelativeFolderpath().map(folder -> SpecsIo.getDepth(new File(folder)))
.orElse(0);
// file = Optional.of(tu);
// }
var tu = (TranslationUnit) file.getNode();
var cloneFunction = makeCloneAndInsert(newName, tu, true);
/* copy headers from the current file to the file with the clone */
TranslationUnit originalFile = function.getAncestorTry(TranslationUnit.class).orElse(null);
if (originalFile != null) {
var includesCopy = TreeNodeUtils.copy(originalFile.getIncludes().getIncludes());
// List<IncludeDecl> allIncludes = getIncludesCopyFromFile(originalFile);
File baseIncludePath = null;
// Add as many ../ as folders in the relative folder
var relativeFolderDepth = tu.getRelativeFolderpath().map(folder -> SpecsIo.getDepth(new File(folder)))
.orElse(0);
for (int i = 0; i < relativeFolderDepth; i++) {
baseIncludePath = new File(baseIncludePath, "../");
}
// Add relative folder of original file
var relativeDepth = baseIncludePath;
baseIncludePath = originalFile.getRelativeFolderpath()
.map(relativeFolder -> new File(relativeDepth, relativeFolder))
.orElse(baseIncludePath);
// App app = getRootImpl().getNode();
//
// Optional<TranslationUnit> file = app.getFile(fileName);
//
// if (!file.isPresent()) {
//
// TranslationUnit tu = getFactory().translationUnit(new File(fileName), Collections.emptyList());
//
// app.addFile(tu);
//
// file = Optional.of(tu);
// }
var tu = (TranslationUnit) file.getNode();
var cloneFunction = makeCloneAndInsert(newName, tu, true);
/* copy headers from the current file to the file with the clone */
TranslationUnit originalFile = function.getAncestorTry(TranslationUnit.class).orElse(null);
if (originalFile != null) {
var includesCopy = TreeNodeUtils.copy(originalFile.getIncludes().getIncludes());
// List<IncludeDecl> allIncludes = getIncludesCopyFromFile(originalFile);
File baseIncludePath = null;
// Add as many ../ as folders in the relative folder
var relativeFolderDepth = tu.getRelativeFolderpath().map(folder -> SpecsIo.getDepth(new File(folder)))
.orElse(0);
for (int i = 0; i < relativeFolderDepth; i++) {
baseIncludePath = new File(baseIncludePath, "../");
}
// Add relative folder of original file
var relativeDepth = baseIncludePath;
baseIncludePath = originalFile.getRelativeFolderpath()
.map(relativeFolder -> new File(relativeDepth, relativeFolder))
.orElse(baseIncludePath);
// System.out.println("BASE: " + baseIncludePath);
// System.out.println("DEPTH: " + relativeFolderDepth);
// Adapt includes
for (var includeDecl : includesCopy) {
var include = includeDecl.getInclude();
// If angled, ignore
if (include.isAngled()) {
continue;
}
// System.out.println("INCLUDE BEFORE: " + includeDecl.getCode());