Provides utility functions to condense EditOperations into CompoundEditOperations.

getCondensedBasic[source]

getCondensedBasic(operations:List[Union[InsertOperation, DeleteOperation, ReplaceOperation, CompoundOperation]])

Returns a list of CompoundOperations from the given list of operations such that the lengths of the input and output lists are equal. I.e. each CompoundOperation in the returned list represents just one EditOperation.

compoundOps = getCondensedBasic([
    ReplaceOperation( 0, "private"),
    DeleteOperation ( 1           ),
    ReplaceOperation( 2, "add2"   ),
    InsertOperation ( 4, "int"    ),
    InsertOperation ( 5, "x"      ),
    DeleteOperation ( 8           ),
    DeleteOperation ( 8           ),
    DeleteOperation ( 8           ),
    InsertOperation ( 8, "return" ),
    InsertOperation ( 9, "x"      ),
    InsertOperation (10, "+"      ),
    InsertOperation (11, "2"      ),
    InsertOperation (12, ";"      )
])

compoundOps
[COMPOUND_REPLACE 0:1 -> ['private'],
 COMPOUND_DELETE 1:2,
 COMPOUND_REPLACE 2:3 -> ['add2'],
 COMPOUND_INSERT 4 -> ['int'],
 COMPOUND_INSERT 5 -> ['x'],
 COMPOUND_DELETE 8:9,
 COMPOUND_DELETE 8:9,
 COMPOUND_DELETE 8:9,
 COMPOUND_INSERT 8 -> ['return'],
 COMPOUND_INSERT 9 -> ['x'],
 COMPOUND_INSERT 10 -> ['+'],
 COMPOUND_INSERT 11 -> ['2'],
 COMPOUND_INSERT 12 -> [';']]
method = AbstractMethod("public static int foo ( ) { return 0 ; }")
method
public static int foo ( ) { return 0 ; }
method.applyEditOperations(compoundOps)
method
private int add2 ( int x ) { return x + 2 ; }

getCondensedLoose[source]

getCondensedLoose(operations:List[Union[InsertOperation, DeleteOperation, ReplaceOperation, CompoundOperation]])

Returns a list of CompoundOperations from the given list of operations such that each CompoundOperation in the returned list repesents EditOperations that are loosely compatible. This effectively "condenses" the given list according to loose compatibility. The length of the returned list is minimized such that it is as condensed as possible.

compoundOps = getCondensedLoose([
    ReplaceOperation( 0, "private"),
    DeleteOperation ( 1           ),
    ReplaceOperation( 2, "add2"   ),
    InsertOperation ( 4, "int"    ),
    InsertOperation ( 5, "x"      ),
    DeleteOperation ( 8           ),
    DeleteOperation ( 8           ),
    DeleteOperation ( 8           ),
    InsertOperation ( 8, "return" ),
    InsertOperation ( 9, "x"      ),
    InsertOperation (10, "+"      ),
    InsertOperation (11, "2"      ),
    InsertOperation (12, ";"      )
])

compoundOps
[COMPOUND_REPLACE 0:2 -> ['private'],
 COMPOUND_REPLACE 2:3 -> ['add2'],
 COMPOUND_INSERT 4 -> ['int', 'x'],
 COMPOUND_REPLACE 8:11 -> ['return', 'x', '+', '2', ';']]
method = AbstractMethod("public static int foo ( ) { return 0 ; }")
method
public static int foo ( ) { return 0 ; }
method.applyEditOperations(compoundOps)
method
private int add2 ( int x ) { return x + 2 ; }

getCondensedStrict[source]

getCondensedStrict(operations:List[Union[InsertOperation, DeleteOperation, ReplaceOperation, CompoundOperation]])

Returns a list of CompoundOperations from the given list of operations such that each CompoundOperation in the returned list repesents EditOperations that are strictly compatible. This effectively "condenses" the given list according to strict compatibility. The length of the returned list is minimized such that it is as condensed as possible.

compoundOps = getCondensedStrict([
    ReplaceOperation( 0, "private"),
    DeleteOperation ( 1           ),
    ReplaceOperation( 2, "add2"   ),
    InsertOperation ( 4, "int"    ),
    InsertOperation ( 5, "x"      ),
    DeleteOperation ( 8           ),
    DeleteOperation ( 8           ),
    DeleteOperation ( 8           ),
    InsertOperation ( 8, "return" ),
    InsertOperation ( 9, "x"      ),
    InsertOperation (10, "+"      ),
    InsertOperation (11, "2"      ),
    InsertOperation (12, ";"      )
])

compoundOps
[COMPOUND_REPLACE 0:1 -> ['private'],
 COMPOUND_DELETE 1:2,
 COMPOUND_REPLACE 2:3 -> ['add2'],
 COMPOUND_INSERT 4 -> ['int', 'x'],
 COMPOUND_DELETE 8:11,
 COMPOUND_INSERT 8 -> ['return', 'x', '+', '2', ';']]
method = AbstractMethod("public static int foo ( ) { return 0 ; }")
method
public static int foo ( ) { return 0 ; }
method.applyEditOperations(compoundOps)
method
private int add2 ( int x ) { return x + 2 ; }

compoundOps
[COMPOUND_REPLACE 0:1 -> ['private'],
 COMPOUND_DELETE 1:2,
 COMPOUND_REPLACE 2:3 -> ['add2'],
 COMPOUND_INSERT 4 -> ['int', 'x'],
 COMPOUND_DELETE 8:11,
 COMPOUND_INSERT 8 -> ['return', 'x', '+', '2', ';']]
getCondensedLoose(compoundOps)
[COMPOUND_REPLACE 0:2 -> ['private'],
 COMPOUND_REPLACE 2:3 -> ['add2'],
 COMPOUND_INSERT 4 -> ['int', 'x'],
 COMPOUND_REPLACE 8:11 -> ['return', 'x', '+', '2', ';']]