From bfa0559e412d06f6f952bdb23b2e651b1abf0cb8 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Tue, 2 Jul 2024 17:54:57 -0400 Subject: [PATCH] Extracted method for future extension --- .../org/codetracker/BlockTrackerImpl.java | 2 +- .../util/AbstractCodeElementLocator.java | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/codetracker/BlockTrackerImpl.java b/src/main/java/org/codetracker/BlockTrackerImpl.java index 1aa9d16451c..81b70430cb7 100644 --- a/src/main/java/org/codetracker/BlockTrackerImpl.java +++ b/src/main/java/org/codetracker/BlockTrackerImpl.java @@ -616,7 +616,7 @@ private History.HistoryInfo blameReturn(Block startBlock) { Collections.reverse(history); for (History.HistoryInfo historyInfo : history) { for (Change change : historyInfo.getChangeList()) { - if (startBlock.isClosingCurlyBracket() && startBlock.getComposite() instanceof CompositeStatementObject) { + if (startBlock.isClosingCurlyBracket()) { if (change instanceof Introduced) { return historyInfo; } diff --git a/src/main/java/org/codetracker/util/AbstractCodeElementLocator.java b/src/main/java/org/codetracker/util/AbstractCodeElementLocator.java index 2fddbc7068c..7d6676ad6d6 100644 --- a/src/main/java/org/codetracker/util/AbstractCodeElementLocator.java +++ b/src/main/java/org/codetracker/util/AbstractCodeElementLocator.java @@ -17,6 +17,7 @@ import gr.uom.java.xmi.UMLClass; import gr.uom.java.xmi.UMLModel; import gr.uom.java.xmi.UMLOperation; +import gr.uom.java.xmi.decomposition.CompositeStatementObject; public abstract class AbstractCodeElementLocator { protected final String commitId; @@ -165,9 +166,7 @@ protected CodeElement locateWithName(Version version, UMLModel umlModel) throws } Block block = method.findBlock(this::blockPredicate); if (block != null) { - if (block.getLocation().getEndLine() == lineNumber) { - block.setClosingCurlyBracket(true); - } + checkClosingBracket(block); return block; } } @@ -180,9 +179,7 @@ protected CodeElement locateWithoutName(Version version, UMLModel umlModel) thro if (method != null) { Block block = method.findBlockWithoutName(this::blockPredicate); if (block != null) { - if (block.getLocation().getEndLine() == lineNumber) { - block.setClosingCurlyBracket(true); - } + checkClosingBracket(block); return block; } Attribute attribute = getAttribute(umlModel, version, filePath, this::attributePredicateWithoutName); @@ -195,9 +192,7 @@ protected CodeElement locateWithoutName(Version version, UMLModel umlModel) thro if (attribute != null) { Block block = attribute.findBlockWithoutName(this::blockPredicate); if (block != null) { - if (block.getLocation().getEndLine() == lineNumber) { - block.setClosingCurlyBracket(true); - } + checkClosingBracket(block); return block; } return attribute; @@ -208,4 +203,10 @@ protected CodeElement locateWithoutName(Version version, UMLModel umlModel) thro } throw new CodeElementNotFoundException(filePath, name, lineNumber); } + + private void checkClosingBracket(Block block) { + if (block.getLocation().getEndLine() == lineNumber && block.getComposite() instanceof CompositeStatementObject) { + block.setClosingCurlyBracket(true); + } + } } \ No newline at end of file