gr.uom.java.xmi.UMLModel Maven / Gradle / Ivy
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.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import org.refactoringminer.api.RefactoringMinerTimedOutException;
import com.github.gumtreediff.tree.TreeContext;
public class UMLModel {
private Set repositoryDirectories;
private List classList;
private List generalizationList;
private List realizationList;
private boolean partial;
private Map treeContextMap = new LinkedHashMap<>();
private Map> commentMap = new LinkedHashMap<>();
public UMLModel(Set repositoryDirectories) {
this.repositoryDirectories = repositoryDirectories;
classList = new ArrayList();
generalizationList = new ArrayList();
realizationList = new ArrayList();
}
public Map getTreeContextMap() {
return treeContextMap;
}
public Map> getCommentMap() {
return commentMap;
}
public boolean isPartial() {
return partial;
}
public void setPartial(boolean partial) {
this.partial = partial;
}
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 {
UMLModelDiff modelDiff = new UMLModelDiff(this, umlModel);
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(umlModel.repositoryDirectories, new UMLClassMatcher.Move());
modelDiff.checkForRenamedClasses(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();
modelDiff.addUMLClassDiff(classDiff);
}
}
modelDiff.checkForMovedClasses(umlModel.repositoryDirectories, new UMLClassMatcher.RelaxedMove());
modelDiff.checkForRenamedClasses(new UMLClassMatcher.RelaxedRename());
modelDiff.inferClassRenameBasedOnFilePaths(new UMLClassMatcher.RelaxedRename());
return modelDiff;
}
}