Skip to content

Commit

Permalink
Exclude block body changes from oracle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Nov 2, 2024
1 parent 3fd666a commit 8d6d0f9
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/codetracker/BlockTrackerChangeHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.codetracker.change.block.BlockBodyRemoved;
import org.codetracker.change.block.BlockSignatureFormatChange;
import org.codetracker.change.block.ElseBlockAdded;
import org.codetracker.change.block.ElseBodyBlockAdded;
import org.codetracker.change.block.ElseBlockBodyAdded;
import org.codetracker.change.block.ExpressionChange;
import org.codetracker.change.block.MergeBlock;
import org.codetracker.change.block.ReplaceConditionalWithTernary;
Expand Down Expand Up @@ -846,13 +846,13 @@ else if (ifBefore.getStatements().size() == 2 && ifAfter.getStatements().size()
if(ifBefore.getStatements().get(1).getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK) &&
!ifAfter.getStatements().get(1).getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK) &&
!ifAfter.getStatements().get(1).getLocationInfo().getCodeElementType().equals(CodeElementType.IF_STATEMENT)) {
blockChangeHistory.addChange(blockBefore, blockAfter, ChangeFactory.forBlock(Change.Type.ELSE_BODY_BLOCK_REMOVED));
blockChangeHistory.addChange(blockBefore, blockAfter, ChangeFactory.forBlock(Change.Type.ELSE_BLOCK_BODY_REMOVED));
elseChange = true;
}
else if(!ifBefore.getStatements().get(1).getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK) &&
!ifBefore.getStatements().get(1).getLocationInfo().getCodeElementType().equals(CodeElementType.IF_STATEMENT) &&
ifAfter.getStatements().get(1).getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK)) {
blockChangeHistory.addChange(blockBefore, blockAfter, ChangeFactory.forBlock(Change.Type.ELSE_BODY_BLOCK_ADDED));
blockChangeHistory.addChange(blockBefore, blockAfter, ChangeFactory.forBlock(Change.Type.ELSE_BLOCK_BODY_ADDED));
elseChange = true;
}
}
Expand Down Expand Up @@ -1246,7 +1246,7 @@ public HistoryInfo<Block> blameReturn(Block startBlock, int exactLineNumber) {
boolean multiLine = startBlock.isMultiLine();
for (Change change : historyInfo.getChangeList()) {
if (startBlock.isElseBlockStart() || startBlock.isElseBlockEnd()) {
if (change instanceof ElseBodyBlockAdded || change instanceof Introduced || change instanceof ElseBlockAdded) {
if (change instanceof ElseBlockBodyAdded || change instanceof Introduced || change instanceof ElseBlockAdded) {
return historyInfo;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/codetracker/change/Change.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ enum Type {
FINALLY_BLOCK_REMOVED("finally block removed"),
ELSE_BLOCK_ADDED("else block added"),
ELSE_BLOCK_REMOVED("else block removed"),
ELSE_BODY_BLOCK_ADDED("else body block added"),
ELSE_BODY_BLOCK_REMOVED("else body block removed"),
ELSE_BLOCK_BODY_ADDED("else block body added"),
ELSE_BLOCK_BODY_REMOVED("else block body removed"),
BLOCK_BODY_ADDED("block body added"),
BLOCK_BODY_REMOVED("block body removed"),
BLOCK_SPLIT("block split"),
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/codetracker/change/ChangeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ public AbstractChange build() {
change = new ElseBlockRemoved();
break;
}
case ELSE_BODY_BLOCK_ADDED: {
change = new ElseBodyBlockAdded();
case ELSE_BLOCK_BODY_ADDED: {
change = new ElseBlockBodyAdded();
break;
}
case ELSE_BODY_BLOCK_REMOVED: {
change = new ElseBodyBlockRemoved();
case ELSE_BLOCK_BODY_REMOVED: {
change = new ElseBlockBodyRemoved();
break;
}
case INTERFACE_LIST_CHANGE: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.codetracker.change.Change;

public class BlockBodyAdded extends BlockChange {
public class BlockBodyAdded extends BlockBodyChange {

public BlockBodyAdded() {
super(Change.Type.BLOCK_BODY_ADDED);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.codetracker.change.block;

public class BlockBodyChange extends BlockChange {

public BlockBodyChange(Type type) {
super(type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.codetracker.change.Change;

public class BlockBodyRemoved extends BlockChange {
public class BlockBodyRemoved extends BlockBodyChange {

public BlockBodyRemoved() {
super(Change.Type.BLOCK_BODY_REMOVED);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/codetracker/change/block/ElseBlockBodyAdded.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.codetracker.change.block;

import org.codetracker.change.Change;

public class ElseBlockBodyAdded extends BlockBodyChange {
public ElseBlockBodyAdded() {
super(Change.Type.ELSE_BLOCK_BODY_ADDED);
}

@Override
public String toString() {
return "Else Block Body Added";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.codetracker.change.block;

import org.codetracker.change.Change;

public class ElseBlockBodyRemoved extends BlockBodyChange {
public ElseBlockBodyRemoved() {
super(Change.Type.ELSE_BLOCK_BODY_REMOVED);
}

@Override
public String toString() {
return "Else Block Body Removed";
}
}
14 changes: 0 additions & 14 deletions src/main/java/org/codetracker/change/block/ElseBodyBlockAdded.java

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion src/test/java/org/codetracker/util/OracleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.codetracker.api.Edge;
import org.codetracker.api.History;
import org.codetracker.change.Change;
import org.codetracker.change.block.BlockBodyChange;
import org.codetracker.experiment.oracle.AbstractOracle;
import org.codetracker.experiment.oracle.history.AbstractHistoryInfo;
import org.codetracker.experiment.oracle.history.ChangeHistory;
Expand Down Expand Up @@ -115,7 +116,8 @@ protected static <T extends CodeElement> HashMap<String, ChangeHistory> processH
Edge edgeValue = historyImpl.getGraph().getEdgeValue(edge).get();
Set<Change> changeList = edgeValue.getChangeList();
for (Change change : changeList) {
if (Change.Type.NO_CHANGE.equals(change.getType()) || Change.Type.SIGNATURE_FORMAT_CHANGE.equals(change.getType()))
if (Change.Type.NO_CHANGE.equals(change.getType()) || Change.Type.SIGNATURE_FORMAT_CHANGE.equals(change.getType()) ||
change instanceof BlockBodyChange)
continue;
ChangeHistory changeHistory = new ChangeHistory();

Expand Down

0 comments on commit 8d6d0f9

Please sign in to comment.