Skip to content

Commit f7bd043

Browse files
committed
Add documentation for DiffNode.getID
1 parent b3e3b00 commit f7bd043

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • src/main/java/org/variantsync/diffdetective/diff/difftree

src/main/java/org/variantsync/diffdetective/diff/difftree/DiffNode.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,19 @@ public boolean isMacro() {
693693

694694
/**
695695
* @return An integer that uniquely identifiers this DiffNode within its patch.
696+
*
697+
* From the returned id a new node with all essential attributes reconstructed can be obtained
698+
* by using {@code fromID}.
699+
*
700+
* Note that only {@code 26} bits of the line number are encoded, so if the line number is bigger than
701+
* {@code 2^26} this id will no longer be unique.
696702
*/
697703
public int getID() {
704+
int lineNumber = 1 + from.inDiff;
705+
Assert.assertTrue((lineNumber << 2*ID_OFFSET) >> 2*ID_OFFSET == lineNumber);
706+
698707
int id;
699-
id = 1 + from.inDiff;
708+
id = lineNumber;
700709
id <<= ID_OFFSET;
701710
id += diffType.ordinal();
702711
id <<= ID_OFFSET;
@@ -705,7 +714,6 @@ public int getID() {
705714
}
706715

707716
public static DiffNode fromID(final int id, String label) {
708-
// lowest 8 bits
709717
final int lowestBitsMask = (1 << ID_OFFSET) - 1;
710718

711719
final int codeTypeOrdinal = id & lowestBitsMask;

0 commit comments

Comments
 (0)