gintool / gin

GI in No Time - a Simple Microframework for Genetic Improvement
MIT License
43 stars 20 forks source link

Line edits target empty and comment lines #35

Closed sandybrownlee closed 4 years ago

sandybrownlee commented 4 years ago

Line edits can target any lines in a source file, including empty and comment-only lines. The constructors currently target one or two of these lines chosen uniformly at random. It might make more sense that comment/empty lines are excluded from the edit source and destination lines.

It is already possible to get a list of lines excluding those that are empty/comments by calling SourceFileLine.getLineIDsNonEmptyOrComments(). The samplers and enumerators do this, choose a pair of line numbers from that list, and call the Line edit constructors with specific line numbers rather than just an RNG and a source file. Something like this:

[code] List allLines = sourceFile.getLineIDsNonEmptyOrComments(false); List targetMethodLines = sourceFile.getLineIDsNonEmptyOrComments(true); CopyLine cl = new CopyLine(sourceFile,targetMethodLines.get(rng.nextInt(targetMethodLines.size())), sourceFile, allLines.get(rng.nextInt(allLines.size()))); [/code]

We could either change the standard (SourceFile, RNG) constructors for Line edits to do this; or make an extended version of Line edits that only target non-empty/comment lines. My preference is for the latter; anyone have any thoughts either way?

sandybrownlee commented 4 years ago

Changed default behaviour to exclude empty and comment lines. This is now consistent with the way the statement edits work and with the results in the paper.