Skip to content

Commit

Permalink
Fix for issue #197
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Nov 24, 2024
1 parent b09ca3d commit cf0898d
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ public CodeElement locateWithoutName(Version version, UMLModel umlModel) throws
}
Comment comment = attribute.findComment(this::commentPredicate);
if (comment != null) {
if (comment.getLocation().getStartLine() == attribute.getLocation().getStartLine()) {
return attribute;
}
return comment;
}
Annotation annotation = attribute.findAnnotation(this::annotationPredicate);
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/codetracker/blame/CodeTrackerBlameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private static Stream<Arguments> testBlamerInputProvider(){
"https://github.com/hibernate/hibernate-search/commit/5b778035965d7588ad1d1ae522c4bafebd3a0e16, engine/src/main/java/org/hibernate/search/backend/impl/StreamingOperationDispatcher.java, /src/test/resources/blame/blameTestWithLocalRepo19.txt",
"https://github.com/eclipse/jetty.project/commit/fc5dd874f3deda71e6cd42af994a5af5cb6be4af, jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java, /src/test/resources/blame/blameTestWithLocalRepo20.txt",
"https://github.com/pmd/pmd/commit/d528dcd5d45582229ab3410deb7c40b2143d015d, pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java, /src/test/resources/blame/blameTestWithLocalRepo21.txt",
"https://github.com/apache/tomcat/commit/dbc805e237b98834a7b7afb6da7be44da428c399, java/org/apache/coyote/http2/ConnectionSettings.java, /src/test/resources/blame/blameTestWithLocalRepo22.txt",
"https://github.com/eclipse/jgit/commit/bd1a82502680b5de5bf86f6c4470185fd1602386, org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java, /src/test/resources/blame/blameTestUntilCommitZero.txt",
"https://github.com/JetBrains/intellij-community/commit/ecb1bb9d4d484ae63ee77f8ad45bdce154db9356, java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java, /src/test/resources/blame/blameTestUntilCommitZero2.txt",
"https://github.com/JetBrains/intellij-community/commit/ecb1bb9d4d484ae63ee77f8ad45bdce154db9356, java/compiler/impl/src/com/intellij/compiler/actions/CompileDirtyAction.java, /src/test/resources/blame/blameTestUntilCommitZero3.txt"
Expand Down Expand Up @@ -121,6 +122,20 @@ public void blameTestAttributeComment() throws Exception {
Assertions.assertEquals(expected, lineBlameResult.toString());
}

@Test
public void blameTestAttributeTDComment() throws Exception {
String url = "https://github.com/apache/tomcat/commit/dbc805e237b98834a7b7afb6da7be44da428c399";
String filePath = "java/org/apache/coyote/http2/ConnectionSettings.java";
int lineNumber = 31;
String expected = "LineBlameResult{commitId='a883a6b3dd2c096220e0e0ab2c0614773bb60787', filePath='java/org/apache/coyote/http2/ConnectionSettings.java', shortCommitId='a883a6b3d', beforeFilePath='java/org/apache/coyote/http2/ConnectionSettings.java', committer='Mark Thomas', commitDate='1432114403', lineNumber=31}";
String commitId = URLHelper.getCommit(url);
Repository repository = gitService.cloneIfNotExists(REPOS_PATH + "/" + getOwner(url) + "/" + getProject(url), URLHelper.getRepo(url));
History.HistoryInfo<? extends CodeElement> lineBlame =
new CodeTrackerBlame().getLineBlame(repository, commitId, filePath, lineNumber);
LineBlameResult lineBlameResult = LineBlameResult.of(lineBlame, lineNumber);
Assertions.assertEquals(expected, lineBlameResult.toString());
}

@Test
public void testBlameLineRangeWithLocalRepo() throws Exception {
String url = "https://github.com/checkstyle/checkstyle/commit/119fd4fb33bef9f5c66fc950396669af842c21a3";
Expand Down
Loading

0 comments on commit cf0898d

Please sign in to comment.