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

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

package org.refactoringminer.astDiff.matchers.wrappers;

import com.github.gumtreediff.tree.Tree;
import gr.uom.java.xmi.LocationInfo;
import gr.uom.java.xmi.UMLEnumConstant;
import org.apache.commons.lang3.tuple.Pair;
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;
import org.refactoringminer.astDiff.matchers.TreeMatcher;
import org.refactoringminer.astDiff.matchers.statement.LeafMatcher;
import org.refactoringminer.astDiff.utils.TreeUtilFunctions;

import java.util.Set;

/* Created by pourya on 2024-05-22*/
public class EnumConstantsMatcher implements TreeMatcher {

    private final Set> commonEnumConstants;

    public EnumConstantsMatcher(Set> commonEnumConstants) {
        this.commonEnumConstants = commonEnumConstants;
    }

    @Override
    public void match(Tree srcTree, Tree dstTree, ExtendedMultiMappingStore mappingStore) {
        processEnumConstants(srcTree,dstTree,commonEnumConstants,mappingStore);
    }

    private void processEnumConstants(Tree srcTree, Tree dstTree, Set> commonEnumConstants, ExtendedMultiMappingStore mappingStore) {
        for (org.apache.commons.lang3.tuple.Pair commonEnumConstant : commonEnumConstants) {
            LocationInfo locationInfo1 = commonEnumConstant.getLeft().getLocationInfo();
            LocationInfo locationInfo2 = commonEnumConstant.getRight().getLocationInfo();
            Tree srcEnumConstant = TreeUtilFunctions.findByLocationInfo(srcTree,locationInfo1);
            Tree dstEnumConstant = TreeUtilFunctions.findByLocationInfo(dstTree,locationInfo2);
            new LeafMatcher().match(srcEnumConstant,dstEnumConstant,mappingStore);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy