From 3b0ceec7013a9219ae5aef0d9d1772fc28050e6d Mon Sep 17 00:00:00 2001 From: tsantalis Date: Wed, 13 Nov 2024 10:24:03 -0500 Subject: [PATCH] Fix for issue #194 --- .../CommentTrackerChangeHistory.java | 89 +++++++++++++------ .../blame/blameTestWithLocalRepo6.txt | 14 +-- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/codetracker/CommentTrackerChangeHistory.java b/src/main/java/org/codetracker/CommentTrackerChangeHistory.java index e7603d5181b..908fb6a3873 100644 --- a/src/main/java/org/codetracker/CommentTrackerChangeHistory.java +++ b/src/main/java/org/codetracker/CommentTrackerChangeHistory.java @@ -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 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 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++; diff --git a/src/test/resources/blame/blameTestWithLocalRepo6.txt b/src/test/resources/blame/blameTestWithLocalRepo6.txt index fd291c0b6ee..3c272fba782 100644 --- a/src/test/resources/blame/blameTestWithLocalRepo6.txt +++ b/src/test/resources/blame/blameTestWithLocalRepo6.txt @@ -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) *
    -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) *
  • 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) *
  • 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) *
  • {@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) *
+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) *
    +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) *
  • 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) *
  • 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) *
  • {@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) *
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 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) {