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

org.refactoringminer.astDiff.matchers.wrappers.ClassDiffMatcher Maven / Gradle / Ivy

Go to download

RefactoringMiner is a library/API written in Java that can detect refactorings applied in the history of a Java project.

There is a newer version: 3.0.9
Show newest version
package org.refactoringminer.astDiff.matchers.wrappers;

import com.github.gumtreediff.tree.Tree;
import gr.uom.java.xmi.decomposition.UMLOperationBodyMapper;
import gr.uom.java.xmi.diff.UMLAbstractClassDiff;
import gr.uom.java.xmi.diff.UMLClassBaseDiff;
import org.refactoringminer.api.Refactoring;
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;
import org.refactoringminer.astDiff.models.OptimizationData;

import java.util.List;

/* Created by pourya on 2024-06-06*/
public class ClassDiffMatcher extends OptimizationAwareMatcher{
    private final UMLAbstractClassDiff classDiff;
    private final boolean mergeFlag;
    private final List modelDiffRefactorings;

    public ClassDiffMatcher(UMLAbstractClassDiff classDiff, boolean mergeFlag, List modelDiffRefactorings) {
        this.classDiff = classDiff;
        this.mergeFlag = mergeFlag;
        this.modelDiffRefactorings = modelDiffRefactorings;
    }

    public ClassDiffMatcher(OptimizationData optimizationData, UMLAbstractClassDiff classDiff, boolean mergeFlag, List modelDiffRefactorings) {
        super(optimizationData);
        this.classDiff = classDiff;
        this.mergeFlag = mergeFlag;
        this.modelDiffRefactorings = modelDiffRefactorings;
    }

    @Override
    void matchAndUpdateOptimizationStore(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) {
        classDiffMatcher(classDiff, mergeFlag, mappingStore, src, dst, optimizationData);
    }

    private void classDiffMatcher(UMLAbstractClassDiff classDiff, boolean mergeFlag, ExtendedMultiMappingStore mappingStore, Tree srcTree, Tree dstTree, OptimizationData optimizationData) {
        if (!mergeFlag) {
            mappingStore.addMapping(srcTree, dstTree);
            new PackageDeclarationMatcher().match(srcTree, dstTree, mappingStore);
        }
        boolean isBaseDiff = classDiff instanceof UMLClassBaseDiff;
        if (isBaseDiff) {
            UMLClassBaseDiff baseClassDiff = (UMLClassBaseDiff) classDiff;
            new ImportMatcher(baseClassDiff.getImportDiffList()).match(srcTree, dstTree, mappingStore);
            new ClassDeclarationMatcher(optimizationData, baseClassDiff).match(srcTree, dstTree, mappingStore);
        }
        new ClassAttrMatcher(optimizationData, classDiff).match(srcTree, dstTree, mappingStore);
        new EnumConstantsMatcher(classDiff.getCommonEnumConstants()).match(srcTree, dstTree, mappingStore);
        for(UMLOperationBodyMapper umlOperationBodyMapper : classDiff.getOperationBodyMapperList())
            new MethodMatcher(optimizationData, umlOperationBodyMapper).match(srcTree, dstTree, mappingStore);

        if (isBaseDiff){
            UMLClassBaseDiff baseClassDiff = (UMLClassBaseDiff) classDiff;
            new RefactoringMatcher(optimizationData, modelDiffRefactorings, baseClassDiff).match(srcTree, dstTree, mappingStore);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy