From ffbb8fd24def088ba9b95c8e1e59328c2104e314 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Mon, 4 Nov 2024 04:10:06 -0500 Subject: [PATCH] Fix for issue #193 --- .../BlockTrackerChangeHistory.java | 47 ++++++++++++------- .../blame/blameTestWithLocalRepo3.txt | 4 +- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/codetracker/BlockTrackerChangeHistory.java b/src/main/java/org/codetracker/BlockTrackerChangeHistory.java index b8be75745d1..cf56d3e13b5 100644 --- a/src/main/java/org/codetracker/BlockTrackerChangeHistory.java +++ b/src/main/java/org/codetracker/BlockTrackerChangeHistory.java @@ -238,11 +238,16 @@ else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof Sta if (matchedBlockInsideExtractedMethodBody.equalIdentifierIgnoringVersion(rightBlock)) { matchedBlockFromSourceMethod = mapping.getFragment1(); Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), bodyMapper.getContainer1(), parentVersion); - List stringRepresentationBefore = blockBefore.getComposite().stringRepresentation(); - List stringRepresentationAfter = matchedBlockInsideExtractedMethodBody.getComposite().stringRepresentation(); - if (!stringRepresentationBefore.equals(stringRepresentationAfter)) { - //blockChangeHistory.addChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); - addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); + if (!blockBefore.getComposite().getString().equals(matchedBlockInsideExtractedMethodBody.getComposite().getString())) { + addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); + } + else { + if(blockBefore.differInFormatting(matchedBlockInsideExtractedMethodBody)) { + addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.SIGNATURE_FORMAT_CHANGE)); + } + else { + blockChangeHistory.addChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.of(AbstractChange.Type.NO_CHANGE)); + } } break; } @@ -299,11 +304,16 @@ else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof Sta if (matchedBlockInsideExtractedMethodBody.equalIdentifierIgnoringVersion(rightBlock)) { matchedBlockFromSourceMethod = mapping.getFragment1(); Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), anonymousMapper.getContainer1(), parentVersion); - List stringRepresentationBefore = blockBefore.getComposite().stringRepresentation(); - List stringRepresentationAfter = matchedBlockInsideExtractedMethodBody.getComposite().stringRepresentation(); - if (!stringRepresentationBefore.equals(stringRepresentationAfter)) { - //blockChangeHistory.addChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); - addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); + if (!blockBefore.getComposite().getString().equals(matchedBlockInsideExtractedMethodBody.getComposite().getString())) { + addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); + } + else { + if(blockBefore.differInFormatting(matchedBlockInsideExtractedMethodBody)) { + addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.SIGNATURE_FORMAT_CHANGE)); + } + else { + blockChangeHistory.addChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.of(AbstractChange.Type.NO_CHANGE)); + } } break; } @@ -363,11 +373,16 @@ else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof Sta if (matchedBlockInsideExtractedMethodBody.equalIdentifierIgnoringVersion(rightBlock)) { matchedBlockFromSourceMethod = mapping.getFragment1(); Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), bodyMapper.getContainer1(), parentVersion); - List stringRepresentationBefore = blockBefore.getComposite().stringRepresentation(); - List stringRepresentationAfter = matchedBlockInsideExtractedMethodBody.getComposite().stringRepresentation(); - if (!stringRepresentationBefore.equals(stringRepresentationAfter)) { - //blockChangeHistory.addChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); - addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); + if (!blockBefore.getComposite().getString().equals(matchedBlockInsideExtractedMethodBody.getComposite().getString())) { + addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); + } + else { + if(blockBefore.differInFormatting(matchedBlockInsideExtractedMethodBody)) { + addStatementChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.SIGNATURE_FORMAT_CHANGE)); + } + else { + blockChangeHistory.addChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.of(AbstractChange.Type.NO_CHANGE)); + } } break; } @@ -876,7 +891,7 @@ else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof Sta Block blockAfter = Block.of((StatementObject) mapping.getFragment2(), umlOperationBodyMapper.getContainer2(), currentVersion); if (blockAfter != null && equalOperator.test(blockAfter)) { Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), umlOperationBodyMapper.getContainer1(), parentVersion); - if (!blockBefore.getComposite().toString().equals(blockAfter.getComposite().toString())) { + if (!blockBefore.getComposite().getString().equals(blockAfter.getComposite().getString())) { addStatementChange(blockBefore, blockAfter, ChangeFactory.forBlock(Change.Type.BODY_CHANGE)); } else { diff --git a/src/test/resources/blame/blameTestWithLocalRepo3.txt b/src/test/resources/blame/blameTestWithLocalRepo3.txt index d53a9398f52..5039ddebd86 100644 --- a/src/test/resources/blame/blameTestWithLocalRepo3.txt +++ b/src/test/resources/blame/blameTestWithLocalRepo3.txt @@ -315,7 +315,7 @@ ec2834e43 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Roman Iva 77acd41cf src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Andrei Selkin 2016-02-16 19:22:01 +0000 315) private SortedSet processFile(File file) throws CheckstyleException { fbf3f95c2 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Andrei Selkin 2016-09-21 02:52:06 +0000 316) final SortedSet fileMessages = new TreeSet<>(); 13b7c6343 src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java (Oliver Burn 2008-11-09 09:37:27 +0000 317) try { -f1e80e4ec src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Michal Kordas 2015-08-08 04:38:41 +0000 318) final FileText theText = new FileText(file.getAbsoluteFile(), charset); +d46c2cf0e src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Andrei Selkin 2016-02-09 17:50:02 +0000 318) final FileText theText = new FileText(file.getAbsoluteFile(), charset); b8ca6a585 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (alexkravin 2015-01-19 14:38:32 +0000 319) for (final FileSetCheck fsc : fileSetChecks) { f1e80e4ec src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Michal Kordas 2015-08-08 04:38:41 +0000 320) fileMessages.addAll(fsc.process(file, theText)); 13b7c6343 src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java (Oliver Burn 2008-11-09 09:37:27 +0000 321) } @@ -324,7 +324,7 @@ f1e80e4ec src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Michal Ko 127f72994 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (crude 2017-10-20 17:46:57 +0000 324) log.debug("IOException occurred.", ioe); 13b7c6343 src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java (Oliver Burn 2008-11-09 09:37:27 +0000 325) fileMessages.add(new LocalizedMessage(0, b61daf7f4 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (rnveach 2016-12-07 23:21:03 +0000 326) Definitions.CHECKSTYLE_BUNDLE, EXCEPTION_MSG, -6d5c0da42 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Michal Kordas 2015-08-09 14:41:42 +0000 327) new String[] {ioe.getMessage()}, null, getClass(), null)); +d46c2cf0e src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (Andrei Selkin 2016-02-09 17:50:02 +0000 327) new String[] {ioe.getMessage()}, null, getClass(), null)); 13b7c6343 src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java (Oliver Burn 2008-11-09 09:37:27 +0000 328) } b61daf7f4 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (rnveach 2016-12-07 23:21:03 +0000 329) // -@cs[IllegalCatch] There is no other way to obey haltOnException field b61daf7f4 src/main/java/com/puppycrawl/tools/checkstyle/Checker.java (rnveach 2016-12-07 23:21:03 +0000 330) catch (Exception ex) {