gr.uom.java.xmi.UMLModel 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;
import gr.uom.java.xmi.diff.UMLClassDiff;
import gr.uom.java.xmi.diff.UMLModelDiff;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import org.refactoringminer.api.RefactoringMinerTimedOutException;
public class UMLModel {
private Set repositoryDirectories;
private List classList;
private List generalizationList;
private List realizationList;
public UMLModel(Set repositoryDirectories) {
this.repositoryDirectories = repositoryDirectories;
classList = new ArrayList();
generalizationList = new ArrayList();
realizationList = new ArrayList();
}
public void addClass(UMLClass umlClass) {
classList.add(umlClass);
}
public void addGeneralization(UMLGeneralization umlGeneralization) {
generalizationList.add(umlGeneralization);
}
public void addRealization(UMLRealization umlRealization) {
realizationList.add(umlRealization);
}
public UMLClass getClass(UMLClass umlClassFromOtherModel) {
ListIterator it = classList.listIterator();
while(it.hasNext()) {
UMLClass umlClass = it.next();
if(umlClass.equals(umlClassFromOtherModel))
return umlClass;
}
return null;
}
public List getClassList() {
return this.classList;
}
public List getGeneralizationList() {
return this.generalizationList;
}
public List getRealizationList() {
return realizationList;
}
public UMLGeneralization matchGeneralization(UMLGeneralization otherGeneralization) {
ListIterator generalizationIt = generalizationList.listIterator();
while(generalizationIt.hasNext()) {
UMLGeneralization generalization = generalizationIt.next();
if(generalization.getChild().equals(otherGeneralization.getChild())) {
String thisParent = generalization.getParent();
String otherParent = otherGeneralization.getParent();
String thisParentComparedString = null;
if(thisParent.contains("."))
thisParentComparedString = thisParent.substring(thisParent.lastIndexOf(".")+1);
else
thisParentComparedString = thisParent;
String otherParentComparedString = null;
if(otherParent.contains("."))
otherParentComparedString = otherParent.substring(otherParent.lastIndexOf(".")+1);
else
otherParentComparedString = otherParent;
if(thisParentComparedString.equals(otherParentComparedString))
return generalization;
}
}
return null;
}
public UMLRealization matchRealization(UMLRealization otherRealization) {
ListIterator realizationIt = realizationList.listIterator();
while(realizationIt.hasNext()) {
UMLRealization realization = realizationIt.next();
if(realization.getClient().equals(otherRealization.getClient())) {
String thisSupplier = realization.getSupplier();
String otherSupplier = otherRealization.getSupplier();
String thisSupplierComparedString = null;
if(thisSupplier.contains("."))
thisSupplierComparedString = thisSupplier.substring(thisSupplier.lastIndexOf(".")+1);
else
thisSupplierComparedString = thisSupplier;
String otherSupplierComparedString = null;
if(otherSupplier.contains("."))
otherSupplierComparedString = otherSupplier.substring(otherSupplier.lastIndexOf(".")+1);
else
otherSupplierComparedString = otherSupplier;
if(thisSupplierComparedString.equals(otherSupplierComparedString))
return realization;
}
}
return null;
}
public UMLModelDiff diff(UMLModel umlModel) throws RefactoringMinerTimedOutException {
return this.diff(umlModel, Collections.emptyMap());
}
public UMLModelDiff diff(UMLModel umlModel, Map renamedFileHints) throws RefactoringMinerTimedOutException {
UMLModelDiff modelDiff = new UMLModelDiff();
for(UMLClass umlClass : classList) {
if(!umlModel.classList.contains(umlClass))
modelDiff.reportRemovedClass(umlClass);
}
for(UMLClass umlClass : umlModel.classList) {
if(!this.classList.contains(umlClass))
modelDiff.reportAddedClass(umlClass);
}
modelDiff.checkForMovedClasses(renamedFileHints, umlModel.repositoryDirectories, new UMLClassMatcher.Move());
modelDiff.checkForRenamedClasses(renamedFileHints, new UMLClassMatcher.Rename());
for(UMLGeneralization umlGeneralization : generalizationList) {
if(!umlModel.generalizationList.contains(umlGeneralization))
modelDiff.reportRemovedGeneralization(umlGeneralization);
}
for(UMLGeneralization umlGeneralization : umlModel.generalizationList) {
if(!this.generalizationList.contains(umlGeneralization))
modelDiff.reportAddedGeneralization(umlGeneralization);
}
modelDiff.checkForGeneralizationChanges();
for(UMLRealization umlRealization : realizationList) {
if(!umlModel.realizationList.contains(umlRealization))
modelDiff.reportRemovedRealization(umlRealization);
}
for(UMLRealization umlRealization : umlModel.realizationList) {
if(!this.realizationList.contains(umlRealization))
modelDiff.reportAddedRealization(umlRealization);
}
modelDiff.checkForRealizationChanges();
for(UMLClass umlClass : classList) {
if(umlModel.classList.contains(umlClass)) {
UMLClassDiff classDiff = new UMLClassDiff(umlClass, umlModel.getClass(umlClass), modelDiff);
classDiff.process();
if(!classDiff.isEmpty())
modelDiff.addUMLClassDiff(classDiff);
}
}
modelDiff.checkForMovedClasses(renamedFileHints, umlModel.repositoryDirectories, new UMLClassMatcher.RelaxedMove());
modelDiff.checkForRenamedClasses(renamedFileHints, new UMLClassMatcher.RelaxedRename());
return modelDiff;
}
}