gr.uom.java.xmi.decomposition.replacement.ConsistentReplacementDetector 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 gr.uom.java.xmi.decomposition.replacement;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
public class ConsistentReplacementDetector {
private static Set inconsistentRenames(
Set currentRenames, T newRename) {
Set inconsistentRenames = new LinkedHashSet();
for(T rename : currentRenames) {
if(rename.getBefore().equals(newRename.getBefore()) && !rename.getAfter().equals(newRename.getAfter())) {
inconsistentRenames.add(rename);
}
else if(!rename.getBefore().equals(newRename.getBefore()) && rename.getAfter().equals(newRename.getAfter())) {
inconsistentRenames.add(rename);
}
}
return inconsistentRenames;
}
public static void updateRenames(
Set allConsistentRenames,
Set allInconsistentRenames,
Set renames) {
for(T newRename : renames) {
Set inconsistentRenames = inconsistentRenames(allConsistentRenames, newRename);
if(inconsistentRenames.isEmpty()) {
allConsistentRenames.add(newRename);
}
else {
allInconsistentRenames.addAll(inconsistentRenames);
allInconsistentRenames.add(newRename);
}
}
}
public static void updateRenames(
Set allConsistentRenames,
Set allInconsistentRenames,
Set renames,
Map> aliasedAttributesInOriginalClass,
Map> aliasedAttributesInNextClass) {
for(T newRename : renames) {
Set inconsistentRenames = inconsistentRenames(allConsistentRenames, newRename);
filter(inconsistentRenames, aliasedAttributesInOriginalClass, aliasedAttributesInNextClass);
if(inconsistentRenames.isEmpty()) {
allConsistentRenames.add(newRename);
}
else {
allInconsistentRenames.addAll(inconsistentRenames);
allInconsistentRenames.add(newRename);
}
}
}
private static Set filter(Set inconsistentRenames,
Map> aliasedAttributesInOriginalClass,
Map> aliasedAttributesInNextClass) {
Set renamesToBeRemoved = new LinkedHashSet();
for(String key : aliasedAttributesInOriginalClass.keySet()) {
Set aliasedAttributes = aliasedAttributesInOriginalClass.get(key);
for(T r : inconsistentRenames) {
if(aliasedAttributes.contains(r.getBefore())) {
renamesToBeRemoved.add(r);
}
}
}
for(String key : aliasedAttributesInNextClass.keySet()) {
Set aliasedAttributes = aliasedAttributesInNextClass.get(key);
for(T r : inconsistentRenames) {
if(aliasedAttributes.contains(r.getAfter())) {
renamesToBeRemoved.add(r);
}
}
}
inconsistentRenames.removeAll(renamesToBeRemoved);
return inconsistentRenames;
}
}