Skip to content

Commit 1976f81

Browse files
committed
renamed functions
1 parent 7aaa230 commit 1976f81

97 files changed

Lines changed: 432 additions & 443 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/service/HarvestActualHttpWsResponseHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class HarvestActualHttpWsResponseHandler {
535535
val v = ParamUtil.getValueGene(geneToMutate)
536536
val t = ParamUtil.getValueGene(template)
537537
if (v::class.java == t::class.java) {
538-
v.copyValueFrom(t)
538+
v.unsafeCopyValueFrom(t)
539539
return true
540540
} else if (v is StringGene) {
541541
// add template as part of specialization

core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestCallAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class RestCallAction(
191191
For example, they could be a ChoiceGene when dealing with "examples" or Regex when having patterns
192192
only defined on some endpoints
193193
*/
194-
parameters[i].primaryGene().copyValueFrom(k.primaryGene())
194+
parameters[i].primaryGene().unsafeCopyValueFrom(k.primaryGene())
195195
}
196196
}
197197
}

core/src/main/kotlin/org/evomaster/core/problem/util/BindingBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ object BindingBuilder {
109109
}
110110

111111
private fun bindValues(p: Pair<Gene,Gene>, doBuildBindingGene: Boolean){
112-
val ok = p.first.setFromDifferentGene(p.second)
112+
val ok = p.first.copyValueFrom(p.second)
113113
if (ok && doBuildBindingGene){
114114
p.first.addBindingGene(p.second)
115115
p.second.addBindingGene(p.first)

core/src/main/kotlin/org/evomaster/core/problem/util/ParamUtil.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import org.evomaster.core.search.gene.numeric.LongGene
1616
import org.evomaster.core.search.gene.wrapper.CustomMutationRateGene
1717
import org.evomaster.core.search.gene.wrapper.OptionalGene
1818
import org.evomaster.core.search.gene.string.StringGene
19-
import org.evomaster.core.search.gene.utils.GeneUtils
2019

2120
/**
2221
* this class used to handle binding values among params
@@ -100,7 +99,7 @@ class ParamUtil {
10099
*/
101100
fun compareGenesWithValue(geneA: Gene, geneB: Gene): Boolean {
102101
val geneAWithGeneBType = geneB.copy()
103-
geneAWithGeneBType.setFromDifferentGene(geneA)
102+
geneAWithGeneBType.copyValueFrom(geneA)
104103
return when (geneB) {
105104
is StringGene -> geneB.value == (geneAWithGeneBType as StringGene).value
106105
is IntegerGene -> geneB.value == (geneAWithGeneBType as IntegerGene).value

core/src/main/kotlin/org/evomaster/core/search/gene/BooleanGene.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BooleanGene(
3333
this.value = value.toBoolean()
3434
}
3535

36-
override fun setValueBasedOn(value: String) : Boolean{
36+
override fun unsafeSetFromStringValue(value: String) : Boolean{
3737
try{
3838
this.value = value.toBoolean()
3939
return true
@@ -70,7 +70,7 @@ class BooleanGene(
7070
}
7171

7272

73-
override fun copyValueFrom(other: Gene): Boolean {
73+
override fun unsafeCopyValueFrom(other: Gene): Boolean {
7474
if (other !is BooleanGene) {
7575
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
7676
}
@@ -84,9 +84,9 @@ class BooleanGene(
8484
return true
8585
}
8686

87-
override fun setValueBasedOn(gene: Gene): Boolean {
87+
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
8888
if (gene is SeededGene<*>){
89-
return this.setValueBasedOn(gene.getPhenotype()as Gene)
89+
return this.unsafeSetFromStringValue(gene.getPhenotype()as Gene)
9090
}
9191
if (gene !is BooleanGene){
9292
LoggingUtil.uniqueWarn(log, "Do not support to bind boolean gene with the type: ${gene::class.java.simpleName}")

core/src/main/kotlin/org/evomaster/core/search/gene/Gene.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ import org.evomaster.core.Lazy
1515
import org.evomaster.core.problem.enterprise.EnterpriseIndividual
1616
import org.evomaster.core.problem.enterprise.SampleType
1717
import org.evomaster.core.search.RootElement
18-
import org.evomaster.core.search.gene.sql.SqlAutoIncrementGene
19-
import org.evomaster.core.search.gene.sql.SqlPrimaryKeyGene
2018
import org.evomaster.core.search.gene.utils.GeneUtils
21-
import org.evomaster.core.search.gene.wrapper.CustomMutationRateGene
22-
import org.evomaster.core.search.gene.wrapper.FlexibleGene
23-
import org.evomaster.core.search.gene.wrapper.NullableGene
24-
import org.evomaster.core.search.gene.wrapper.OptionalGene
25-
import org.evomaster.core.search.gene.wrapper.SelectableWrapperGene
2619
import org.evomaster.core.search.gene.wrapper.WrapperGene
2720
import org.evomaster.core.search.service.SearchGlobalState
2821
import org.evomaster.core.search.service.monitor.ProcessMonitorExcludeField
@@ -910,7 +903,7 @@ abstract class Gene(
910903
all.add(this)
911904
bindingGenes.filterNot { all.contains(it) }.forEach { b ->
912905
all.add(b)
913-
if (!b.setValueBasedOn(this))
906+
if (!b.unsafeSetFromStringValue(this))
914907
LoggingUtil.uniqueWarn(
915908
log,
916909
"fail to bind the gene (${b.name} with the type ${b::class.java.simpleName}) based on this gene (${this.name} with ${this::class.java.simpleName})"
@@ -1110,7 +1103,7 @@ abstract class Gene(
11101103
* The type of genes can be different.
11111104
* However, there is no check if constraints are kept satisfied.
11121105
* So, this method should not be called directly.
1113-
* Rather use [setFromDifferentGene], which internally it calls this method,
1106+
* Rather use [copyValueFrom], which internally it calls this method,
11141107
* and then revert in case of constraint violations.
11151108
*
11161109
* @return whether the binding performs successfully.
@@ -1122,7 +1115,7 @@ abstract class Gene(
11221115
*/
11231116
@Deprecated("Do not call directly outside this package. Call setFromDifferentGene")
11241117
//TODO remove deprecated once we integrate @PackagePrivate
1125-
internal abstract fun setValueBasedOn(gene: Gene): Boolean
1118+
internal abstract fun unsafeSetFromStringValue(gene: Gene): Boolean
11261119

11271120

11281121
/**
@@ -1134,23 +1127,23 @@ abstract class Gene(
11341127
*
11351128
* @return whether the value is copied based on [other] successfully
11361129
*/
1137-
abstract fun copyValueFrom(other: Gene): Boolean
1130+
abstract fun unsafeCopyValueFrom(other: Gene): Boolean
11381131

11391132

11401133
/**
11411134
* Update current value of this gene, base on other gene.
1142-
* This is not [copyValueFrom], as the gene could be different.
1135+
* This is not [unsafeCopyValueFrom], as the gene could be different.
11431136
* FIXME that comment seems wrong
11441137
* If for any reason the update fails, there is not going to be any side-effects.
11451138
*
11461139
* @return if the update was successful
11471140
*/
1148-
fun setFromDifferentGene(gene: Gene, undoIfUpdateFails: Boolean = true): Boolean {
1141+
fun copyValueFrom(gene: Gene, undoIfUpdateFails: Boolean = true): Boolean {
11491142

11501143
//FIXME current implementation leads to infinite loops. must fix copyValueFrom
11511144
//return updateValueOnlyIfValid( { setValueBasedOn(gene) } , undoIfUpdateFails)
11521145
//TODO update once fixed
1153-
return setValueBasedOn(gene)
1146+
return unsafeSetFromStringValue(gene)
11541147
}
11551148

11561149
/*
@@ -1165,7 +1158,7 @@ abstract class Gene(
11651158
* is violated.
11661159
*/
11671160
fun setFromStringValue(value: String, undoIfUpdateFails: Boolean = true): Boolean {
1168-
return updateValueOnlyIfValid({ setValueBasedOn(value) }, undoIfUpdateFails)
1161+
return updateValueOnlyIfValid({ unsafeSetFromStringValue(value) }, undoIfUpdateFails)
11691162
}
11701163

11711164
/**
@@ -1181,7 +1174,7 @@ abstract class Gene(
11811174
* TODO @PackagePrivate
11821175
*/
11831176
@Deprecated("Do not call directly outside this package. Call setFromStringValue")
1184-
internal open fun setValueBasedOn(value: String): Boolean {
1177+
internal open fun unsafeSetFromStringValue(value: String): Boolean {
11851178
//TODO in future this should be abstract, to force each gene to handle it.
11861179
//few implementations can be based on AbstractParser class for Postman
11871180
throw IllegalStateException("setValueBasedOn() is not implemented for gene ${this::class.simpleName}")
@@ -1202,7 +1195,7 @@ abstract class Gene(
12021195
if (!ok && !undoIfUpdateFails) return false
12031196

12041197
if (!ok || !isLocallyValid()) {
1205-
val success = copyValueFrom(current)
1198+
val success = unsafeCopyValueFrom(current)
12061199
assert(success)
12071200
return false
12081201
}

core/src/main/kotlin/org/evomaster/core/search/gene/ObjectGene.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class ObjectGene(
244244
)
245245
}
246246

247-
override fun copyValueFrom(other: Gene): Boolean {
247+
override fun unsafeCopyValueFrom(other: Gene): Boolean {
248248
if (other !is ObjectGene) {
249249
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
250250
}
@@ -263,13 +263,13 @@ class ObjectGene(
263263
var ok = true
264264

265265
for (i in fixedFields.indices) {
266-
ok = ok && this.fixedFields[i].copyValueFrom(other.fixedFields[i])
266+
ok = ok && this.fixedFields[i].unsafeCopyValueFrom(other.fixedFields[i])
267267
}
268268

269269
if(!isFixed){
270270
//TODO what if there is a mismatch here? semantic of this function is unclear
271271
for (i in additionalFields!!.indices){
272-
ok = ok && this.additionalFields!![i].copyValueFrom(other.additionalFields!![i])
272+
ok = ok && this.additionalFields!![i].unsafeCopyValueFrom(other.additionalFields!![i])
273273
}
274274
}
275275

@@ -280,22 +280,22 @@ class ObjectGene(
280280
return updateOk
281281
}
282282

283-
override fun setValueBasedOn(gene: Gene): Boolean {
283+
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
284284
if (gene is ObjectGene
285285
&& (fixedFields.indices).all { fixedFields[it].possiblySame(gene.fixedFields[it]) }
286286
&& isFixed == gene.isFixed
287287
&& (isFixed || template!!.possiblySame(gene.template!!))) {
288288

289289
var result = true
290290
(fixedFields.indices).forEach {
291-
val r = fixedFields[it].setValueBasedOn(gene.fixedFields[it])
291+
val r = fixedFields[it].unsafeSetFromStringValue(gene.fixedFields[it])
292292
if (!r)
293293
LoggingUtil.uniqueWarn(log, "cannot bind the field ${fixedFields[it].name}")
294294
result = result && r
295295
}
296296
if(!isFixed){
297297
(additionalFields!!.indices).forEach {
298-
val r = additionalFields!![it].setValueBasedOn(gene.additionalFields!![it])
298+
val r = additionalFields!![it].unsafeSetFromStringValue(gene.additionalFields!![it])
299299
if (!r)
300300
LoggingUtil.uniqueWarn(log, "cannot bind the field ${additionalFields!![it].name}")
301301
result = result && r
@@ -626,7 +626,7 @@ class ObjectGene(
626626

627627

628628
@Deprecated("Do not call directly outside this package. Call setFromStringValue")
629-
override fun setValueBasedOn(value: String): Boolean {
629+
override fun unsafeSetFromStringValue(value: String): Boolean {
630630

631631
val tree = mapper.readTree(value)
632632

@@ -654,7 +654,7 @@ class ObjectGene(
654654
but, in this latter case, it would need quite a bit of refactoring
655655
*/
656656
val input = GeneUtils.removeEnclosedQuotationMarks(text)
657-
ok = ok && it.setValueBasedOn(input)
657+
ok = ok && it.unsafeSetFromStringValue(input)
658658
}
659659
}
660660

@@ -687,8 +687,8 @@ class ObjectGene(
687687
if(this.initialized){
688688
x.markAllAsInitialized()
689689
}
690-
x.first.setValueBasedOn(it.key)
691-
x.second.setValueBasedOn(GeneUtils.removeEnclosedQuotationMarks(it.value.toString()))
690+
x.first.unsafeSetFromStringValue(it.key)
691+
x.second.unsafeSetFromStringValue(GeneUtils.removeEnclosedQuotationMarks(it.value.toString()))
692692
addChild(x)
693693
}
694694
}

core/src/main/kotlin/org/evomaster/core/search/gene/SeededGene.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ class SeededGene<T>(
110110
override fun possiblySame(gene : Gene) : Boolean =
111111
super.possiblySame(gene) && this.gene.possiblySame((gene as SeededGene<*>).gene as Gene)
112112

113-
override fun copyValueFrom(other: Gene): Boolean {
113+
override fun unsafeCopyValueFrom(other: Gene): Boolean {
114114
if (other !is SeededGene<*>)
115115
throw IllegalArgumentException("Invalid gene ${other::class.java}")
116116

117117
return updateValueOnlyIfValid(
118118
{
119119
val ok = if (employSeeded)
120-
this.seeded.copyValueFrom(other.seeded)
120+
this.seeded.unsafeCopyValueFrom(other.seeded)
121121
else
122-
this.gene.copyValueFrom(other.gene as Gene)
122+
this.gene.unsafeCopyValueFrom(other.gene as Gene)
123123

124124
if (ok){
125125
this.employSeeded = other.employSeeded
@@ -130,18 +130,18 @@ class SeededGene<T>(
130130
)
131131
}
132132

133-
override fun setValueBasedOn(gene: Gene): Boolean {
133+
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
134134
// only allow bind value for gene
135135
if (gene is SeededGene<*> && isEmploySeededMutable){
136136
employSeeded = gene.employSeeded
137137
if (!employSeeded)
138-
return ParamUtil.getValueGene(this.gene).setValueBasedOn(ParamUtil.getValueGene(gene.gene as Gene))
138+
return ParamUtil.getValueGene(this.gene).unsafeSetFromStringValue(ParamUtil.getValueGene(gene.gene as Gene))
139139
else
140-
return seeded.setValueBasedOn(gene.seeded)
140+
return seeded.unsafeSetFromStringValue(gene.seeded)
141141
}
142142

143143
if (gene !is SeededGene<*> && !employSeeded){
144-
return ParamUtil.getValueGene(this.gene).setValueBasedOn(ParamUtil.getValueGene(gene))
144+
return ParamUtil.getValueGene(this.gene).unsafeSetFromStringValue(ParamUtil.getValueGene(gene))
145145
}
146146

147147
return false

core/src/main/kotlin/org/evomaster/core/search/gene/UUIDGene.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,22 @@ class UUIDGene(
8787
&& this.leastSigBits.containsSameValueAs(other.leastSigBits)
8888
}
8989

90-
override fun copyValueFrom(other: Gene): Boolean {
90+
override fun unsafeCopyValueFrom(other: Gene): Boolean {
9191
if (other !is UUIDGene) {
9292
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
9393
}
9494
return updateValueOnlyIfValid(
95-
{this.mostSigBits.copyValueFrom(other.mostSigBits) && this.leastSigBits.copyValueFrom(other.leastSigBits)}, true
95+
{this.mostSigBits.unsafeCopyValueFrom(other.mostSigBits) && this.leastSigBits.unsafeCopyValueFrom(other.leastSigBits)}, true
9696
)
9797
}
9898

99-
override fun setValueBasedOn(gene: Gene): Boolean {
99+
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
100100
return when{
101101
gene is UUIDGene ->{
102-
mostSigBits.setValueBasedOn(gene.mostSigBits) && leastSigBits.setValueBasedOn(gene.leastSigBits)
102+
mostSigBits.unsafeSetFromStringValue(gene.mostSigBits) && leastSigBits.unsafeSetFromStringValue(gene.leastSigBits)
103103
}
104104
gene is StringGene && gene.getSpecializationGene() != null ->{
105-
setValueBasedOn(gene.getSpecializationGene()!!)
105+
unsafeSetFromStringValue(gene.getSpecializationGene()!!)
106106
}
107107
else->{
108108
LoggingUtil.uniqueWarn(log, "cannot bind UUIDGene with ${gene::class.java.simpleName}")

core/src/main/kotlin/org/evomaster/core/search/gene/collection/ArrayGene.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class ArrayGene<T>(
252252
253253
TODO might bind based on value instead of replacing them
254254
*/
255-
override fun setValueBasedOn(gene: Gene): Boolean {
255+
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
256256
if(gene is ArrayGene<*> && gene.template::class.java.simpleName == template::class.java.simpleName){
257257
killAllChildren()
258258
val elements = gene.elements.mapNotNull { it.copy() as? T}.toMutableList()
@@ -277,7 +277,7 @@ class ArrayGene<T>(
277277
return false
278278
}
279279

280-
override fun copyValueFrom(other: Gene): Boolean {
280+
override fun unsafeCopyValueFrom(other: Gene): Boolean {
281281
if (other !is ArrayGene<*>) {
282282
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
283283
}
@@ -304,7 +304,7 @@ class ArrayGene<T>(
304304
* Use [template] to create child [Gene].
305305
* Use comma (,) separated elements with a space in front of the values as String.
306306
*/
307-
override fun setValueBasedOn(value: String): Boolean {
307+
override fun unsafeSetFromStringValue(value: String): Boolean {
308308
val elements = value
309309
.trim()
310310
.removePrefix(openingTag)

0 commit comments

Comments
 (0)