gr.uom.java.xmi.diff.UMLClassMoveDiff Maven / Gradle / Ivy
package gr.uom.java.xmi.diff;
import org.apache.commons.lang3.tuple.Pair;
import org.refactoringminer.api.RefactoringMinerTimedOutException;
import gr.uom.java.xmi.UMLAttribute;
import gr.uom.java.xmi.UMLClass;
import gr.uom.java.xmi.UMLClassMatcher.MatchResult;
public class UMLClassMoveDiff extends UMLClassBaseDiff {
private MatchResult matchResult;
public UMLClassMoveDiff(UMLClass originalClass, UMLClass movedClass, UMLModelDiff modelDiff, MatchResult matchResult) {
super(originalClass, movedClass, modelDiff);
this.matchResult = matchResult;
}
public UMLClass getMovedClass() {
return (UMLClass) nextClass;
}
public MatchResult getMatchResult() {
return matchResult;
}
protected void processAttributes() throws RefactoringMinerTimedOutException {
for(UMLAttribute attribute : originalClass.getAttributes()) {
UMLAttribute matchingAttribute = nextClass.containsAttribute(attribute);
if(matchingAttribute == null) {
this.reportRemovedAttribute(attribute);
}
else {
UMLAttributeDiff attributeDiff = new UMLAttributeDiff(attribute, matchingAttribute, this, modelDiff);
if(!attributeDiff.isEmpty()) {
refactorings.addAll(attributeDiff.getRefactorings());
if(!attributeDiffList.contains(attributeDiff)) {
attributeDiffList.add(attributeDiff);
}
}
else {
Pair pair = Pair.of(attribute, matchingAttribute);
if(!commonAtrributes.contains(pair)) {
commonAtrributes.add(pair);
}
if(attributeDiff.encapsulated()) {
refactorings.addAll(attributeDiff.getRefactorings());
}
}
}
}
for(UMLAttribute attribute : nextClass.getAttributes()) {
UMLAttribute matchingAttribute = originalClass.containsAttribute(attribute);
if(matchingAttribute == null) {
this.reportAddedAttribute(attribute);
}
else {
UMLAttributeDiff attributeDiff = new UMLAttributeDiff(matchingAttribute, attribute, this, modelDiff);
if(!attributeDiff.isEmpty()) {
refactorings.addAll(attributeDiff.getRefactorings());
if(!attributeDiffList.contains(attributeDiff)) {
attributeDiffList.add(attributeDiff);
}
}
else {
Pair pair = Pair.of(matchingAttribute, attribute);
if(!commonAtrributes.contains(pair)) {
commonAtrributes.add(pair);
}
if(attributeDiff.encapsulated()) {
refactorings.addAll(attributeDiff.getRefactorings());
}
}
}
}
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ");
sb.append(originalClass.getName());
sb.append(" was moved to ");
sb.append(nextClass.getName());
sb.append("\n");
return sb.toString();
}
public boolean equals(Object o) {
if(this == o) {
return true;
}
if(o instanceof UMLClassMoveDiff) {
UMLClassMoveDiff classMoveDiff = (UMLClassMoveDiff)o;
return this.originalClass.equals(classMoveDiff.originalClass) && this.nextClass.equals(classMoveDiff.nextClass);
}
return false;
}
}