org.refactoringminer.astDiff.matchers.wrappers.PackageDeclarationMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of refactoring-miner Show documentation
Show all versions of refactoring-miner Show documentation
RefactoringMiner is a library/API written in Java that can detect refactorings applied in the history of a Java project.
package org.refactoringminer.astDiff.matchers.wrappers;
import com.github.gumtreediff.tree.Tree;
import org.refactoringminer.astDiff.utils.Constants;
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;
import org.refactoringminer.astDiff.matchers.TreeMatcher;
import java.util.List;
/* Created by pourya on 2024-05-22*/
public class PackageDeclarationMatcher implements TreeMatcher {
@Override
public void match(Tree srcTree, Tree dstTree, ExtendedMultiMappingStore mappingStore) {
Tree srcPackageDeclaration = findPackageDeclaration(srcTree);
Tree dstPackageDeclaration = findPackageDeclaration(dstTree);
if (srcPackageDeclaration != null && dstPackageDeclaration != null)
mappingStore.addMappingRecursively(srcPackageDeclaration,dstPackageDeclaration);
}
private Tree findPackageDeclaration(Tree inputTree) {
String searchingType = Constants.PACKAGE_DECLARATION;
if (!inputTree.getChildren().isEmpty()) {
List children = inputTree.getChildren();
for(Tree child: children) {
if (child.getType().name.equals(searchingType))
return child;
}
}
return null;
}
}