All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.refactoringminer.astDiff.moved.MovedASTDiffGenerator Maven / Gradle / Ivy

package org.refactoringminer.astDiff.moved;

import com.github.gumtreediff.matchers.Mapping;
import com.github.gumtreediff.tree.Tree;
import com.github.gumtreediff.tree.TreeContext;
import com.github.gumtreediff.utils.Pair;
import gr.uom.java.xmi.diff.UMLModelDiff;
import org.refactoringminer.astDiff.models.ASTDiff;
import org.refactoringminer.astDiff.models.ProjectASTDiff;
import org.refactoringminer.astDiff.actions.editscript.SimplifiedExtendedChawatheScriptGenerator;
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;

import java.util.*;

import static org.refactoringminer.astDiff.utils.Helpers.findTreeContexts;

public abstract class MovedASTDiffGenerator {
    protected final ProjectASTDiff projectASTDiff;
    protected final UMLModelDiff modelDiff;
    public MovedASTDiffGenerator(UMLModelDiff modelDiff, ProjectASTDiff projectASTDiff) {
        this.modelDiff = modelDiff;
        this.projectASTDiff = projectASTDiff;
    }
    protected abstract Map, List> makeFilePairMappings();
    public Set make() {
        Map, List> filePairMappings = makeFilePairMappings();
        Set movedDiffs = new LinkedHashSet<>();
        for(Pair pair : filePairMappings.keySet()) {
            Pair treeContextPairs = findTreeContexts(modelDiff, pair.first, pair.second);
            List mappings = filePairMappings.get(pair);
            if(!mappings.isEmpty()) {
                Tree leftRoot = treeContextPairs.first.getRoot();
                Tree rightRoot = treeContextPairs.second.getRoot();
                ExtendedMultiMappingStore store = new ExtendedMultiMappingStore(leftRoot, rightRoot);
                for(Mapping m : mappings) {
                    store.addMapping(m.first, m.second); //NOTE: SubClasses must provide all the mappings that are needed for the ASTDiff
                }
                ASTDiff diff = new ASTDiff(
                        pair.first,
                        pair.second,
                        treeContextPairs.first,
                        treeContextPairs.second,
                        store
                );
                movedDiffs.add(diff);
            }
        }
        return movedDiffs;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy