Skip to content

Commit

Permalink
Fix for issue #194
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Nov 13, 2024
1 parent a870ce7 commit 3b0ceec
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 36 deletions.
89 changes: 60 additions & 29 deletions src/main/java/org/codetracker/CommentTrackerChangeHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,38 +204,69 @@ public boolean checkForExtractionOrInline(Version currentVersion, Version parent
if (equalMethod.test(extractedMethod)) {
UMLComment matchedCommentFromSourceMethod = null;
UMLOperationBodyMapper bodyMapper = extractOperationRefactoring.getBodyMapper();
UMLCommentListDiff commentListDiff = bodyMapper.getCommentListDiff();
if (commentListDiff != null) {
for (Pair<UMLComment, UMLComment> mapping : commentListDiff.getCommonComments()) {
Comment matchedCommentInsideExtractedMethodBody = Comment.of(mapping.getRight(), bodyMapper.getContainer2(), currentVersion);
if (matchedCommentInsideExtractedMethodBody.equalIdentifierIgnoringVersion(rightComment)) {
matchedCommentFromSourceMethod = mapping.getLeft();
Comment commentBefore = Comment.of(mapping.getLeft(), bodyMapper.getContainer1(), parentVersion);
if (!commentBefore.getComment().getText().equals(matchedCommentInsideExtractedMethodBody.getComment().getText())) {
processChange(commentBefore, matchedCommentInsideExtractedMethodBody);
}
break;
if(rightComment.getComment() instanceof UMLComment) {
UMLCommentListDiff commentListDiff = bodyMapper.getCommentListDiff();
if (commentListDiff != null) {
for (Pair<UMLComment, UMLComment> mapping : commentListDiff.getCommonComments()) {
Comment matchedCommentInsideExtractedMethodBody = Comment.of(mapping.getRight(), bodyMapper.getContainer2(), currentVersion);
if (matchedCommentInsideExtractedMethodBody.equalIdentifierIgnoringVersion(rightComment)) {
matchedCommentFromSourceMethod = mapping.getLeft();
Comment commentBefore = Comment.of(mapping.getLeft(), bodyMapper.getContainer1(), parentVersion);
if (!commentBefore.getComment().getText().equals(matchedCommentInsideExtractedMethodBody.getComment().getText())) {
processChange(commentBefore, matchedCommentInsideExtractedMethodBody);
}
break;
}
}
}
Comment commentBefore;
if (rightComment.getOperation().isPresent())
commentBefore = Comment.of(rightComment.getComment(), rightComment.getOperation().get(), parentVersion);
else
commentBefore = Comment.of(rightComment.getComment(), rightComment.getClazz().get(), parentVersion);
if (matchedCommentFromSourceMethod == null) {
commentChangeHistory.handleAdd(commentBefore, rightComment, extractOperationRefactoring.toString());
if(extractMatches == 0) {
elements.addFirst(commentBefore);
}
}
else {
VariableDeclarationContainer sourceOperation = extractOperationRefactoring.getSourceOperationBeforeExtraction();
Method sourceMethod = Method.of(sourceOperation, parentVersion);
Comment leftComment = Comment.of(matchedCommentFromSourceMethod, sourceMethod);
if(extractMatches == 0) {
elements.addFirst(leftComment);
}
}
}
if(bodyMapper.getJavadocDiff().isPresent()) {
UMLJavadocDiff extractedJavadocDiff = bodyMapper.getJavadocDiff().get();
Comment commentAfter = Comment.of(extractedJavadocDiff.getJavadocAfter(), bodyMapper.getContainer2(), currentVersion);
if (commentAfter != null && commentAfter.equalIdentifierIgnoringVersion(rightComment)) {
Comment commentBefore = Comment.of(extractedJavadocDiff.getJavadocBefore(), bodyMapper.getContainer1(), parentVersion);
if (!commentBefore.getComment().getText().equals(commentAfter.getComment().getText())) {
processChange(commentBefore, commentAfter);
}
}
}
Comment commentBefore;
if (rightComment.getOperation().isPresent())
commentBefore = Comment.of(rightComment.getComment(), rightComment.getOperation().get(), parentVersion);
else
commentBefore = Comment.of(rightComment.getComment(), rightComment.getClazz().get(), parentVersion);
if (matchedCommentFromSourceMethod == null) {
commentChangeHistory.handleAdd(commentBefore, rightComment, extractOperationRefactoring.toString());
if(extractMatches == 0) {
elements.addFirst(commentBefore);
}
else {
commentChangeHistory.addChange(commentBefore, commentAfter, ChangeFactory.of(AbstractChange.Type.NO_CHANGE));
}
if(extractMatches == 0) {
elements.addFirst(commentBefore);
}
}
}
else {
VariableDeclarationContainer sourceOperation = extractOperationRefactoring.getSourceOperationBeforeExtraction();
Method sourceMethod = Method.of(sourceOperation, parentVersion);
Comment leftComment = Comment.of(matchedCommentFromSourceMethod, sourceMethod);
if(extractMatches == 0) {
elements.addFirst(leftComment);
}
Comment commentBefore;
if (rightComment.getOperation().isPresent())
commentBefore = Comment.of(rightComment.getComment(), rightComment.getOperation().get(), parentVersion);
else
commentBefore = Comment.of(rightComment.getComment(), rightComment.getClazz().get(), parentVersion);
if (matchedCommentFromSourceMethod == null) {
commentChangeHistory.handleAdd(commentBefore, rightComment, extractOperationRefactoring.toString());
if(extractMatches == 0) {
elements.addFirst(commentBefore);
}
}
}
commentChangeHistory.connectRelatedNodes();
extractMatches++;
Expand Down
14 changes: 7 additions & 7 deletions src/test/resources/blame/blameTestWithLocalRepo6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,15 @@ b204437ce spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method
b204437ce spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Juergen Hoeller 2016-07-02 12:48:15 +0000 346) return getProducibleMediaTypes(request, valueClass, null);
af1dfd357 org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/AbstractMessageConverterMethodProcessor.java (Rossen Stoyanchev 2011-05-17 13:02:48 +0000 347) }
348)
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 349) /**
af1dfd357 org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/AbstractMessageConverterMethodProcessor.java (Rossen Stoyanchev 2011-05-17 13:02:48 +0000 349) /**
e0480f75a spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Phillip Webb 2018-06-28 08:28:44 +0000 350) * Returns the media types that can be produced. The resulting media types are:
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 351) * <ul>
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 352) * <li>The producible media types specified in the request mappings, or
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 353) * <li>Media types of configured converters that can write the specific return value, or
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 354) * <li>{@link MediaType#ALL}
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 355) * </ul>
af1dfd357 org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/AbstractMessageConverterMethodProcessor.java (Rossen Stoyanchev 2011-05-17 13:02:48 +0000 351) * <ul>
ec7d80b85 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Juergen Hoeller 2014-04-23 21:03:47 +0000 352) * <li>The producible media types specified in the request mappings, or
ec7d80b85 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Juergen Hoeller 2014-04-23 21:03:47 +0000 353) * <li>Media types of configured converters that can write the specific return value, or
ec7d80b85 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Juergen Hoeller 2014-04-23 21:03:47 +0000 354) * <li>{@link MediaType#ALL}
1eaca6572 org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/AbstractMessageConverterMethodProcessor.java (Arjen Poutsma 2011-05-18 11:34:47 +0000 355) * </ul>
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 356) * @since 4.2
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 357) */
af1dfd357 org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/AbstractMessageConverterMethodProcessor.java (Rossen Stoyanchev 2011-05-17 13:02:48 +0000 357) */
289f35da3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Sebastien Deleuze 2015-06-25 13:02:33 +0000 358) @SuppressWarnings("unchecked")
b915e42c3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Juergen Hoeller 2018-07-16 17:45:35 +0000 359) protected List<MediaType> getProducibleMediaTypes(
b915e42c3 spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java (Juergen Hoeller 2018-07-16 17:45:35 +0000 360) HttpServletRequest request, Class<?> valueClass, @Nullable Type targetType) {
Expand Down

0 comments on commit 3b0ceec

Please sign in to comment.