Skip to content

Commit

Permalink
refactoring-aware Javadoc diff
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 15, 2024
1 parent 19af472 commit 3b50468
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ else if(mapping instanceof CompositeStatementObjectMapping) {
processLeaves(leaves1, leaves2, new LinkedHashMap<String, String>(), false);
}
if(operation1.getJavadoc() != null && operation2.getJavadoc() != null) {
UMLJavadocDiff diff = new UMLJavadocDiff(operation1.getJavadoc(), operation2.getJavadoc());
UMLJavadocDiff diff = new UMLJavadocDiff(operation1.getJavadoc(), operation2.getJavadoc(), operationSignatureDiff);
this.javadocDiff = Optional.of(diff);
}
this.commentListDiff = new UMLCommentListDiff(container1.getComments(), container2.getComments());
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLJavadocDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class UMLJavadocDiff {
private List<UMLDocElement> deletedDocElements;
private List<UMLDocElement> addedDocElements;
private boolean manyToManyReformat;
private UMLOperationDiff signatureDiff;

public UMLJavadocDiff(UMLJavadoc javadocBefore, UMLJavadoc javadocAfter) {
this.javadocBefore = javadocBefore;
Expand All @@ -40,6 +41,26 @@ public UMLJavadocDiff(UMLJavadoc javadocBefore, UMLJavadoc javadocAfter) {
this.addedNestedTags = new ArrayList<UMLTagElement>();
this.deletedDocElements = new ArrayList<UMLDocElement>();
this.addedDocElements = new ArrayList<UMLDocElement>();
process(javadocBefore, javadocAfter);
}

public UMLJavadocDiff(UMLJavadoc javadocBefore, UMLJavadoc javadocAfter, UMLOperationDiff signatureDiff) {
this.javadocBefore = javadocBefore;
this.javadocAfter = javadocAfter;
this.commonTags = new ArrayList<Pair<UMLTagElement,UMLTagElement>>();
this.commonNestedTags = new ArrayList<Pair<UMLTagElement,UMLTagElement>>();
this.commonDocElements = new ArrayList<Pair<UMLDocElement,UMLDocElement>>();
this.deletedTags = new ArrayList<UMLTagElement>();
this.addedTags = new ArrayList<UMLTagElement>();
this.deletedNestedTags = new ArrayList<UMLTagElement>();
this.addedNestedTags = new ArrayList<UMLTagElement>();
this.deletedDocElements = new ArrayList<UMLDocElement>();
this.addedDocElements = new ArrayList<UMLDocElement>();
this.signatureDiff = signatureDiff;
process(javadocBefore, javadocAfter);
}

private void process(UMLJavadoc javadocBefore, UMLJavadoc javadocAfter) {
List<UMLTagElement> tagsBefore = javadocBefore.getTags();
List<UMLTagElement> tagsAfter = javadocAfter.getTags();
List<UMLTagElement> deletedTags = new ArrayList<UMLTagElement>(tagsBefore);
Expand Down Expand Up @@ -89,6 +110,30 @@ public UMLJavadocDiff(UMLJavadoc javadocBefore, UMLJavadoc javadocAfter) {
break;
}
}
else if(signatureDiff != null) {
boolean matchFound = false;
for(UMLParameterDiff diff : signatureDiff.getParameterDiffList()) {
if(diff.getRemovedParameter().getName().equals(paramNameBefore) &&
diff.getAddedParameter().getName().equals(paramNameAfter)) {
//match name
matchFound = true;
UMLDocElement docElementBefore = tagBefore.getFragments().get(0);
UMLDocElement docElementAfter = tagAfter.getFragments().get(0);
Pair<UMLDocElement, UMLDocElement> docElementPair = Pair.of(docElementBefore, docElementAfter);
commonDocElements.add(docElementPair);
processModifiedTags(tagBefore, tagAfter);
deletedToBeDeleted.add(tagBefore);
addedToBeDeleted.add(tagAfter);
Pair<UMLTagElement, UMLTagElement> pair = Pair.of(tagBefore, tagAfter);
commonTags.add(pair);
matchNestedTags(tagBefore, tagAfter);
break;
}
}
if(matchFound) {
break;
}
}
}
else if(tagBefore.isReturn() && tagAfter.isReturn()) {
boolean match = processModifiedTags(tagBefore, tagAfter);
Expand Down

0 comments on commit 3b50468

Please sign in to comment.