Skip to content

Commit

Permalink
Fix for issue #196
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Nov 20, 2024
1 parent 8e13ab9 commit 199dff7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/codetracker/BlockTrackerChangeHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,16 @@ else if (startBlock.isClosingCurlyBracket()) {
return historyInfo;
}
}
else if (startBlock.isAnonymousClosingBracket()) {
if (change instanceof Introduced) {
return historyInfo;
}
}
else if (startBlock.isLambdaClosingBracket()) {
if (change instanceof Introduced || change instanceof ReplaceLoopWithPipeline) {
return historyInfo;
}
}
else if (startBlock.isDoWhileConditional()) {
if (change instanceof ExpressionChange) {
return historyInfo;
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public void blame() throws Exception {
if (analysedCommits.contains(commitId))
continue;
analysedCommits.add(commitId);
long start = System.nanoTime();

Version currentVersion = gitRepository.getVersion(commitId);
String parentCommitId = gitRepository.getParentId(commitId);
Expand Down Expand Up @@ -339,6 +340,10 @@ else if (leftSuperclass == null && rightSuperclass != null) {
programElementMap.putAll(nestedProgramElementMap);
nestedProgramElementMap.clear();
}
long end = System.nanoTime();
long elapsedTime = end - start;
double elapsedTimeInSecond = (double) elapsedTime / 1_000_000_000;
System.out.println(commitId + "\t" + elapsedTimeInSecond);
continue;
}
else if (leftClass != null && (annotationChanged || modifiersChanged)) {
Expand Down Expand Up @@ -386,6 +391,10 @@ else if (leftSuperclass == null && rightSuperclass != null) {
}
Set<Class> leftSideClasses = new HashSet<>(classRefactored);
leftSideClasses.forEach(startClassChangeHistory::addFirst);
long end = System.nanoTime();
long elapsedTime = end - start;
double elapsedTimeInSecond = (double) elapsedTime / 1_000_000_000;
System.out.println(commitId + "\t" + elapsedTimeInSecond);
break;
}
}
Expand Down Expand Up @@ -416,6 +425,10 @@ else if (leftSuperclass == null && rightSuperclass != null) {
}
Set<Class> leftSideClasses = new HashSet<>(classRefactored);
leftSideClasses.forEach(startClassChangeHistory::addFirst);
long end = System.nanoTime();
long elapsedTime = end - start;
double elapsedTimeInSecond = (double) elapsedTime / 1_000_000_000;
System.out.println(commitId + "\t" + elapsedTimeInSecond);
break;
}
}
Expand Down Expand Up @@ -448,6 +461,10 @@ else if (leftSuperclass == null && rightSuperclass != null) {
}
Set<Class> leftSideClasses = new HashSet<>(classRefactored);
leftSideClasses.forEach(startClassChangeHistory::addFirst);
long end = System.nanoTime();
long elapsedTime = end - start;
double elapsedTimeInSecond = (double) elapsedTime / 1_000_000_000;
System.out.println(commitId + "\t" + elapsedTimeInSecond);
break;
}

Expand All @@ -456,6 +473,10 @@ else if (leftSuperclass == null && rightSuperclass != null) {
processAddedAttributes(umlModelPairAll.getRight(), umlModelDiffAll, currentVersion, parentVersion);
processAddedInnerClasses(umlModelPairAll.getRight(), umlModelDiffAll, currentVersion, parentVersion, startClass);
processAddedImportsAndClassComments(rightClass, parentVersion);
long end = System.nanoTime();
long elapsedTime = end - start;
double elapsedTimeInSecond = (double) elapsedTime / 1_000_000_000;
System.out.println(commitId + "\t" + elapsedTimeInSecond);
break;
}
}
Expand All @@ -478,6 +499,7 @@ else if (startElement instanceof Block) {
startBlock.checkElseBlockStart(lineNumber);
startBlock.checkElseBlockEnd(lineNumber);
startBlock.checkClosingBracketOfAnonymousClassDeclaration(lineNumber);
startBlock.checkClosingBracketOfLambda(lineNumber);
startBlock.checkDoWhileConditional(lineNumber);
HistoryInfo<Block> historyInfo = startBlockChangeHistory.blameReturn(startBlock, lineNumber);
blameInfo.put(lineNumber, historyInfo);
Expand All @@ -489,6 +511,7 @@ else if (startElement instanceof Block) {
nestedBlock.checkElseBlockStart(lineNumber);
nestedBlock.checkElseBlockEnd(lineNumber);
nestedBlock.checkClosingBracketOfAnonymousClassDeclaration(lineNumber);
nestedBlock.checkClosingBracketOfLambda(lineNumber);
nestedBlock.checkDoWhileConditional(lineNumber);
HistoryInfo<Block> nestedHistoryInfo = nestedHistory.blameReturn(nestedBlock, lineNumber);
blameInfo.put(lineNumber, nestedHistoryInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ else if (startElement instanceof Block) {
startBlock.checkElseBlockStart(lineNumber);
startBlock.checkElseBlockEnd(lineNumber);
startBlock.checkClosingBracketOfAnonymousClassDeclaration(lineNumber);
startBlock.checkClosingBracketOfLambda(lineNumber);
startBlock.checkDoWhileConditional(lineNumber);
HistoryInfo<Block> historyInfo = startBlockChangeHistory.blameReturn(startBlock, lineNumber);
blameInfo.put(lineNumber, historyInfo);
Expand All @@ -497,6 +498,7 @@ else if (startElement instanceof Block) {
nestedBlock.checkElseBlockStart(lineNumber);
nestedBlock.checkElseBlockEnd(lineNumber);
nestedBlock.checkClosingBracketOfAnonymousClassDeclaration(lineNumber);
nestedBlock.checkClosingBracketOfLambda(lineNumber);
nestedBlock.checkDoWhileConditional(lineNumber);
HistoryInfo<Block> nestedHistoryInfo = nestedHistory.blameReturn(nestedBlock, lineNumber);
blameInfo.put(lineNumber, nestedHistoryInfo);
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/codetracker/element/BaseCodeElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public abstract class BaseCodeElement implements CodeElement {
private boolean elseBlockStart;
private boolean elseBlockEnd;
private boolean doWhileConditional;
private boolean anonymousClosingBracket;
private boolean lambdaClosingBracket;

public BaseCodeElement(String identifierIgnoringVersion, String name, String filePath, Version version) {
this.identifier = version != null ? identifierIgnoringVersion + version : identifierIgnoringVersion;
Expand Down Expand Up @@ -62,6 +64,22 @@ public void setElseBlockEnd(boolean elseBlockEnd) {
this.elseBlockEnd = elseBlockEnd;
}

public boolean isAnonymousClosingBracket() {
return anonymousClosingBracket;
}

public void setAnonymousClosingBracket(boolean anonymousClosingBracket) {
this.anonymousClosingBracket = anonymousClosingBracket;
}

public boolean isLambdaClosingBracket() {
return lambdaClosingBracket;
}

public void setLambdaClosingBracket(boolean lambdaClosingBracket) {
this.lambdaClosingBracket = lambdaClosingBracket;
}

@Override
public final int compareTo(CodeElement o) {
return this.name.compareTo(o.getName());
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/codetracker/element/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,18 @@ public boolean isMultiLine() {

public void checkClosingBracketOfAnonymousClassDeclaration(int lineNumber) {
if (getComposite() instanceof StatementObject && getComposite().getAnonymousClassDeclarations().size() > 0 && getLocation().getEndLine() == lineNumber) {
setClosingCurlyBracket(true);
setAnonymousClosingBracket(true);
}
}

public void checkClosingBracketOfLambda(int lineNumber) {
if (getComposite() instanceof StatementObject && getComposite().getLambdas().size() > 0) {
for (LambdaExpressionObject lambda : getComposite().getLambdas()) {
if (lambda.getBody() != null && getLocation().getEndLine() == lineNumber) {
setLambdaClosingBracket(true);
break;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/blame/blameTestUntilCommitZero2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ d65d57207 java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java
32d665de0 java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java (Maxim.Mossienko 2012-07-10 20:57:34 +0000 101) if (ApplicationManager.getApplication().isUnitTestMode()) { // force cleanup for created compiler system directory with generated sources
32d665de0 java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java (Maxim.Mossienko 2012-07-10 20:57:34 +0000 102) FileUtil.delete(CompilerPaths.getCompilerSystemDirectory(project));
32d665de0 java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java (Maxim.Mossienko 2012-07-10 20:57:34 +0000 103) }
06156396f java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java (Alexey Kudravtsev 2017-04-25 14:19:19 +0000 104) });
5091777cf java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java (Eugene Zhuravlev 2012-05-21 12:19:11 +0000 104) });
7460e5ada source/com/intellij/compiler/CompilerManagerImpl.java (Maxim Shafirov 2005-01-13 20:44:30 +0000 105) }
106)
c7998e175 java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java (Alexey Kudravtsev 2017-08-10 12:14:57 +0000 107) // returns true if all javacs terminated
Expand Down

0 comments on commit 199dff7

Please sign in to comment.