Skip to content

Commit

Permalink
Support the detection of moved enum constants
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 9, 2025
1 parent 0ac6764 commit 8c526d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/main/java/gr/uom/java/xmi/UMLAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,19 @@ public String toQualifiedString() {
sb.append(" ");
sb.append(name);
sb.append(" : ");
sb.append(type.toQualifiedString());
if(this instanceof UMLEnumConstant) {
String string = type.toString();
if(string.contains(".")) {
String suffix = string.substring(string.lastIndexOf(".")+1, string.length());
sb.append(suffix);
}
else {
sb.append(type);
}
}
else {
sb.append(type.toQualifiedString());
}
return sb.toString();
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLAttributeDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import gr.uom.java.xmi.UMLAnnotation;
import gr.uom.java.xmi.UMLAttribute;
import gr.uom.java.xmi.UMLEnumConstant;
import gr.uom.java.xmi.UMLOperation;
import gr.uom.java.xmi.UMLParameter;
import gr.uom.java.xmi.VariableDeclarationContainer;
Expand Down Expand Up @@ -373,6 +374,9 @@ public boolean encapsulated() {
}

private boolean changeTypeCondition() {
if(removedAttribute instanceof UMLEnumConstant && addedAttribute instanceof UMLEnumConstant) {
return false;
}
return (isTypeChanged() || isQualifiedTypeChanged()) && !enumConstantsDeclaredInTheSameEnumDeclarationType();
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ private MoveAttributeRefactoring processPairOfAttributes(UMLAttribute addedAttri
return null;
}
if(addedAttribute.getName().equals(removedAttribute.getName()) &&
addedAttribute.getType().equals(removedAttribute.getType())) {
(addedAttribute.getType().equals(removedAttribute.getType()) || (removedAttribute instanceof UMLEnumConstant && addedAttribute instanceof UMLEnumConstant))) {
if(isSubclassOf(removedAttribute.getClassName(), addedAttribute.getClassName())) {
UMLAttributeDiff attributeDiff = new UMLAttributeDiff(removedAttribute, addedAttribute, Collections.emptyList());
if(!movedAttributeDiffList.contains(attributeDiff)) {
Expand Down Expand Up @@ -1944,12 +1944,15 @@ public List<UMLAttribute> getAddedAttributesInCommonClasses() {
List<UMLAttribute> addedAttributes = new ArrayList<UMLAttribute>();
for(UMLClassDiff classDiff : commonClassDiffList) {
addedAttributes.addAll(classDiff.getAddedAttributes());
addedAttributes.addAll(classDiff.getAddedEnumConstants());
}
for(UMLClassMoveDiff classDiff : classMoveDiffList) {
addedAttributes.addAll(classDiff.getAddedAttributes());
addedAttributes.addAll(classDiff.getAddedEnumConstants());
}
for(UMLClassRenameDiff classDiff : classRenameDiffList) {
addedAttributes.addAll(classDiff.getAddedAttributes());
addedAttributes.addAll(classDiff.getAddedEnumConstants());
}
return addedAttributes;
}
Expand All @@ -1958,12 +1961,15 @@ public List<UMLAttribute> getRemovedAttributesInCommonClasses() {
List<UMLAttribute> removedAttributes = new ArrayList<UMLAttribute>();
for(UMLClassDiff classDiff : commonClassDiffList) {
removedAttributes.addAll(classDiff.getRemovedAttributes());
removedAttributes.addAll(classDiff.getRemovedEnumConstants());
}
for(UMLClassMoveDiff classDiff : classMoveDiffList) {
removedAttributes.addAll(classDiff.getRemovedAttributes());
removedAttributes.addAll(classDiff.getRemovedEnumConstants());
}
for(UMLClassRenameDiff classDiff : classRenameDiffList) {
removedAttributes.addAll(classDiff.getRemovedAttributes());
removedAttributes.addAll(classDiff.getRemovedEnumConstants());
}
return removedAttributes;
}
Expand Down

0 comments on commit 8c526d4

Please sign in to comment.