Skip to content

Commit 2c22705

Browse files
committed
Added braces.
1 parent f3b0fed commit 2c22705

9 files changed

Lines changed: 92 additions & 29 deletions

File tree

core/src/main/kotlin/org/evomaster/core/search/gene/regex/AnyCharacterRxGene.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ class AnyCharacterRxGene(
132132
}
133133

134134
override fun absorbableCount(value: String): Int {
135-
if (value.isEmpty()) return 0
136-
return if (validRanges.contains(value[0])) 1 else 0
135+
if (value.isEmpty()) {
136+
return 0
137+
}
138+
return if (validRanges.contains(value[0])) {
139+
1
140+
} else {
141+
0
142+
}
137143
}
138144

139145
override fun tryForce(value: String): Int {

core/src/main/kotlin/org/evomaster/core/search/gene/regex/AssertionRxGene.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,23 @@ class AssertionRxGene(
7171
* inner gene to sample from.
7272
*/
7373
fun sampledInnerValue(): String? {
74-
if (innerGene == null) return null
74+
if (innerGene == null) {
75+
return null
76+
}
7577
return innerGene.getValueAsPrintableString(targetFormat = null)
7678
}
7779

7880
override fun containsSameValueAs(other: Gene): Boolean {
79-
if (other !is AssertionRxGene) return false
81+
if (other !is AssertionRxGene) {
82+
return false
83+
}
8084
return sampledInnerValue() == other.sampledInnerValue()
8185
}
8286

8387
override fun unsafeCopyValueFrom(other: Gene): Boolean {
84-
if (other !is AssertionRxGene) return false
88+
if (other !is AssertionRxGene) {
89+
return false
90+
}
8591
return if (innerGene != null && other.innerGene != null) {
8692
innerGene.unsafeCopyValueFrom(other.innerGene)
8793
} else {

core/src/main/kotlin/org/evomaster/core/search/gene/regex/CharacterClassEscapeRxGene.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ class CharacterClassEscapeRxGene(
116116
private val log = LoggerFactory.getLogger(CharacterRangeRxGene::class.java)
117117

118118
private fun Char.swapCase(): Char =
119-
if (this.isUpperCase()) this.lowercaseChar() else this.uppercaseChar()
119+
if (this.isUpperCase()) {
120+
this.lowercaseChar()
121+
} else {
122+
this.uppercaseChar()
123+
}
120124

121125
private val digitSet = listOf(CharacterRange('0', '9'))
122126
private val asciiLetterSet = listOf(CharacterRange(FIRST_LOWER_CASE_CHAR, LAST_LOWER_CASE_CHAR),
@@ -356,10 +360,16 @@ class CharacterClassEscapeRxGene(
356360
}
357361

358362
override fun absorbableCount(value: String): Int {
359-
if (value.isEmpty()) return 0
363+
if (value.isEmpty()) {
364+
return 0
365+
}
360366
val c = value[0]
361-
if (multiCharRange.contains(c)) return 1
362-
if (flags.isCaseable(c) && multiCharRange.contains(c.swapCase())) return 1
367+
if (multiCharRange.contains(c)) {
368+
return 1
369+
}
370+
if (flags.isCaseable(c) && multiCharRange.contains(c.swapCase())) {
371+
return 1
372+
}
363373
return 0
364374
}
365375

core/src/main/kotlin/org/evomaster/core/search/gene/regex/CharacterRangeRxGene.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class CharacterRangeRxGene(
3030
private val log = LoggerFactory.getLogger(CharacterRangeRxGene::class.java)
3131

3232
private fun Char.swapCase(): Char =
33-
if (this.isUpperCase()) this.lowercaseChar() else this.uppercaseChar()
33+
if (this.isUpperCase()) {
34+
this.lowercaseChar()
35+
} else {
36+
this.uppercaseChar()
37+
}
3438
}
3539

3640
// '\u0000' is a placeholder for the unsatisfiable case (empty MCR with no valid ranges).
@@ -185,10 +189,16 @@ class CharacterRangeRxGene(
185189
}
186190

187191
override fun absorbableCount(value: String): Int {
188-
if (value.isEmpty()) return 0
192+
if (value.isEmpty()) {
193+
return 0
194+
}
189195
val c = value[0]
190-
if (validRanges.contains(c)) return 1
191-
if (flags.isCaseable(c) && validRanges.contains(c.swapCase())) return 1
196+
if (validRanges.contains(c)) {
197+
return 1
198+
}
199+
if (flags.isCaseable(c) && validRanges.contains(c.swapCase())) {
200+
return 1
201+
}
192202
return 0
193203
}
194204

core/src/main/kotlin/org/evomaster/core/search/gene/regex/DisjunctionListRxGene.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,18 @@ class DisjunctionListRxGene(
213213
* anything.
214214
*/
215215
private fun rankBranches(value: String): BranchRanking? {
216-
if (value.isEmpty() || disjunctions.isEmpty()) return null
216+
if (value.isEmpty() || disjunctions.isEmpty()) {
217+
return null
218+
}
217219
var bestCount = disjunctions[activeDisjunction].absorbableCount(value)
218220
var bestIndex = activeDisjunction
219221
for (i in disjunctions.indices) {
220-
if (i == activeDisjunction) continue
221-
if (bestCount == value.length) break
222+
if (i == activeDisjunction) {
223+
continue
224+
}
225+
if (bestCount == value.length) {
226+
break
227+
}
222228
val can = disjunctions[i].absorbableCount(value)
223229
if (can > bestCount) {
224230
bestCount = can

core/src/main/kotlin/org/evomaster/core/search/gene/regex/DisjunctionRxGene.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,20 @@ class DisjunctionRxGene(
216216
* value onto the genes that follow it within [terms].
217217
*/
218218
fun attemptAssertionRepair(randomness: Randomness) {
219-
if (terms.none { it is AssertionRxGene }) return
219+
if (terms.none { it is AssertionRxGene }) {
220+
return
221+
}
220222

221223
for (idx in terms.indices) {
222224
val assertion = terms[idx] as? AssertionRxGene ?: continue
223-
if (assertion.innerGene == null) continue
225+
if (assertion.innerGene == null) {
226+
continue
227+
}
224228

225229
val genesAfter = terms.subList(idx + 1, terms.size).filter { it !is AssertionRxGene }
226-
if (genesAfter.isEmpty()) return
230+
if (genesAfter.isEmpty()) {
231+
return
232+
}
227233

228234
var satisfied = false
229235
for (attempt in 0 until MAX_LOCAL_ASSERTION_ATTEMPTS) {
@@ -234,7 +240,9 @@ class DisjunctionRxGene(
234240
break
235241
}
236242
}
237-
if (!satisfied) return
243+
if (!satisfied) {
244+
return
245+
}
238246
}
239247
}
240248
}

core/src/main/kotlin/org/evomaster/core/search/gene/regex/PatternCharacterBlockGene.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ class PatternCharacterBlockGene(
119119
var i = 0
120120
while (i < value.length && i < stringBlock.length) {
121121
val c = stringBlock[i]
122-
val matches = if (flags.isCaseable(c))
122+
val matches = if (flags.isCaseable(c)) {
123123
value[i].equals(c, ignoreCase = true)
124-
else
124+
} else {
125125
value[i] == c
126-
if (!matches) return 0
126+
}
127+
if (!matches) {
128+
return 0
129+
}
127130
i++
128131
}
129132
return i

core/src/main/kotlin/org/evomaster/core/search/gene/regex/RegexGene.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ class RegexGene(
5757
}
5858

5959
private val pattern: Pattern? =
60-
if (regexType == RegexType.JVM) compiledPattern(sourceRegex, externalRegexFlags) else null
60+
if (regexType == RegexType.JVM) {
61+
compiledPattern(sourceRegex, externalRegexFlags)
62+
} else {
63+
null
64+
}
6165

6266
override fun randomize(randomness: Randomness, tryToForceNewValue: Boolean) {
6367
usingFixedValue = if(fixedValue == null){

core/src/main/kotlin/org/evomaster/core/search/gene/utils/AssertionRepairWalk.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ object AssertionRepairWalk {
1616
* left-to-right, without mutating anything.
1717
*/
1818
fun absorbableCount(genes: List<Gene>, value: String): Int {
19-
if (value.isEmpty()) return 0
19+
if (value.isEmpty()) {
20+
return 0
21+
}
2022
var consumed = 0
2123
for (gene in genes) {
22-
if (consumed >= value.length) break
24+
if (consumed >= value.length) {
25+
break
26+
}
2327
val absorbable = gene as RxAbsorbable
2428
val canTake = absorbable.absorbableCount(value.substring(consumed))
2529
if (canTake > 0) {
2630
consumed += canTake
2731
continue
2832
}
29-
if (absorbable.canBeZeroWidth()) continue
33+
if (absorbable.canBeZeroWidth()) {
34+
continue
35+
}
3036
return 0
3137
}
3238
return consumed
@@ -37,10 +43,14 @@ object AssertionRepairWalk {
3743
* gene in place using each gene's [RxAbsorbable.tryForce]. Returns total characters placed.
3844
*/
3945
fun tryForce(genes: List<Gene>, value: String): Int {
40-
if (value.isEmpty()) return 0
46+
if (value.isEmpty()) {
47+
return 0
48+
}
4149
var consumed = 0
4250
for (gene in genes) {
43-
if (consumed >= value.length) break
51+
if (consumed >= value.length) {
52+
break
53+
}
4454
val absorbable = gene as RxAbsorbable
4555
val remaining = value.substring(consumed)
4656
val placed = absorbable.tryForce(remaining)

0 commit comments

Comments
 (0)