@@ -30,6 +30,7 @@ import org.utbot.framework.plugin.api.util.intClassId
30
30
import org.utbot.framework.plugin.api.util.objectArrayClassId
31
31
import org.utbot.framework.plugin.api.util.objectClassId
32
32
import org.utbot.framework.plugin.api.util.voidClassId
33
+ import java.util.Objects
33
34
34
35
interface CgElement {
35
36
// TODO: order of cases is important here due to inheritance between some of the element types
@@ -343,7 +344,7 @@ class CgMultipleArgsAnnotation(
343
344
val arguments : MutableList <CgNamedAnnotationArgument >
344
345
) : CgAnnotation()
345
346
346
- class CgArrayAnnotationArgument (
347
+ data class CgArrayAnnotationArgument (
347
348
val values : List <CgExpression >
348
349
) : CgExpression {
349
350
override val type: ClassId = objectArrayClassId // TODO: is this type correct?
@@ -475,7 +476,7 @@ fun convertDocToCg(stmt: DocStatement): CgDocStatement {
475
476
476
477
// Anonymous function (lambda)
477
478
478
- class CgAnonymousFunction (
479
+ data class CgAnonymousFunction (
479
480
override val type : ClassId ,
480
481
val parameters : List <CgParameterDeclaration >,
481
482
val body : List <CgStatement >
@@ -489,7 +490,7 @@ class CgReturnStatement(val expression: CgExpression) : CgStatement
489
490
490
491
// TODO: check nested array element access expressions e.g. a[0][1][2]
491
492
// TODO in general it is not CgReferenceExpression because array element can have a primitive type
492
- class CgArrayElementAccess (val array : CgExpression , val index : CgExpression ) : CgReferenceExpression {
493
+ data class CgArrayElementAccess (val array : CgExpression , val index : CgExpression ) : CgReferenceExpression {
493
494
override val type: ClassId = array.type.elementClassId ? : objectClassId
494
495
}
495
496
@@ -501,17 +502,17 @@ sealed class CgComparison : CgExpression {
501
502
override val type: ClassId = booleanClassId
502
503
}
503
504
504
- class CgLessThan (
505
+ data class CgLessThan (
505
506
override val left : CgExpression ,
506
507
override val right : CgExpression
507
508
) : CgComparison()
508
509
509
- class CgGreaterThan (
510
+ data class CgGreaterThan (
510
511
override val left : CgExpression ,
511
512
override val right : CgExpression
512
513
) : CgComparison()
513
514
514
- class CgEqualTo (
515
+ data class CgEqualTo (
515
516
override val left : CgExpression ,
516
517
override val right : CgExpression
517
518
) : CgComparison()
@@ -620,7 +621,7 @@ interface CgReferenceExpression : CgExpression
620
621
*
621
622
* @property isSafetyCast shows if we should use "as?" instead of "as" in Kotlin code
622
623
*/
623
- class CgTypeCast (
624
+ data class CgTypeCast (
624
625
val targetType : ClassId ,
625
626
val expression : CgExpression ,
626
627
val isSafetyCast : Boolean = false ,
@@ -631,7 +632,7 @@ class CgTypeCast(
631
632
/* *
632
633
* Represents [java.lang.Class.isInstance] method.
633
634
*/
634
- class CgIsInstance (
635
+ data class CgIsInstance (
635
636
val classExpression : CgExpression ,
636
637
val value : CgExpression ,
637
638
): CgExpression {
@@ -645,7 +646,7 @@ interface CgValue : CgReferenceExpression
645
646
646
647
// This instance
647
648
648
- class CgThisInstance (override val type : ClassId ) : CgValue
649
+ data class CgThisInstance (override val type : ClassId ) : CgValue
649
650
650
651
// Variables
651
652
@@ -683,7 +684,7 @@ open class CgVariable(
683
684
* - in Java it is an equivalent of [CgVariable]
684
685
* - in Kotlin the difference is in addition of "!!" to the name
685
686
*/
686
- class CgNotNullAssertion (val expression : CgExpression ) : CgValue {
687
+ data class CgNotNullAssertion (val expression : CgExpression ) : CgValue {
687
688
override val type: ClassId
688
689
get() = when (val expressionType = expression.type) {
689
690
is BuiltinClassId -> BuiltinClassId (
@@ -740,7 +741,7 @@ sealed class CgParameterKind {
740
741
741
742
// Primitive and String literals
742
743
743
- class CgLiteral (override val type : ClassId , val value : Any? ) : CgValue {
744
+ data class CgLiteral (override val type : ClassId , val value : Any? ) : CgValue {
744
745
override fun equals (other : Any? ): Boolean {
745
746
if (this == = other) return true
746
747
if (javaClass != other?.javaClass) return false
@@ -770,12 +771,42 @@ class CgNonStaticRunnable(
770
771
type : ClassId ,
771
772
val referenceExpression : CgReferenceExpression ,
772
773
methodId : MethodId
773
- ) : CgRunnable(type, methodId)
774
+ ) : CgRunnable(type, methodId) {
775
+ override fun equals (other : Any? ): Boolean {
776
+ if (this == = other) return true
777
+ if (javaClass != other?.javaClass) return false
778
+
779
+ other as CgNonStaticRunnable
780
+
781
+ if (type != other.type) return false
782
+ if (referenceExpression != other.referenceExpression) return false
783
+ if (methodId != other.methodId) return false
784
+
785
+ return true
786
+ }
787
+
788
+ override fun hashCode (): Int = Objects .hash(type, referenceExpression, methodId)
789
+ }
774
790
775
791
/* *
776
792
* [classId] is Random is Random::nextRandomInt (static) etc
777
793
*/
778
- class CgStaticRunnable (type : ClassId , val classId : ClassId , methodId : MethodId ) : CgRunnable(type, methodId)
794
+ class CgStaticRunnable (type : ClassId , val classId : ClassId , methodId : MethodId ) : CgRunnable(type, methodId) {
795
+ override fun equals (other : Any? ): Boolean {
796
+ if (this == = other) return true
797
+ if (javaClass != other?.javaClass) return false
798
+
799
+ other as CgStaticRunnable
800
+
801
+ if (type != other.type) return false
802
+ if (classId != other.classId) return false
803
+ if (methodId != other.methodId) return false
804
+
805
+ return true
806
+ }
807
+
808
+ override fun hashCode (): Int = Objects .hash(type, classId, methodId)
809
+ }
779
810
780
811
// Array allocation
781
812
@@ -805,10 +836,10 @@ open class CgAllocateArray(type: ClassId, elementType: ClassId, val size: Int) :
805
836
/* *
806
837
* Allocation of an array with initialization. For example: `new String[] {"a", "b", null}`.
807
838
*/
808
- class CgAllocateInitializedArray (val initializer : CgArrayInitializer ) :
839
+ data class CgAllocateInitializedArray (val initializer : CgArrayInitializer ) :
809
840
CgAllocateArray (initializer.arrayType, initializer.elementType, initializer.size)
810
841
811
- class CgArrayInitializer (val arrayType : ClassId , val elementType : ClassId , val values : List <CgExpression >) : CgExpression {
842
+ data class CgArrayInitializer (val arrayType : ClassId , val elementType : ClassId , val values : List <CgExpression >) : CgExpression {
812
843
val size: Int
813
844
get() = values.size
814
845
@@ -819,7 +850,7 @@ class CgArrayInitializer(val arrayType: ClassId, val elementType: ClassId, val v
819
850
820
851
// Spread operator (for Kotlin, empty for Java)
821
852
822
- class CgSpread (override val type : ClassId , val array : CgExpression ) : CgExpression
853
+ data class CgSpread (override val type : ClassId , val array : CgExpression ) : CgExpression
823
854
824
855
// Enum constant
825
856
@@ -840,12 +871,12 @@ abstract class CgAbstractFieldAccess : CgReferenceExpression {
840
871
get() = fieldId.type
841
872
}
842
873
843
- class CgFieldAccess (
874
+ data class CgFieldAccess (
844
875
val caller : CgExpression ,
845
876
override val fieldId : FieldId
846
877
) : CgAbstractFieldAccess()
847
878
848
- class CgStaticFieldAccess (
879
+ data class CgStaticFieldAccess (
849
880
override val fieldId : FieldId
850
881
) : CgAbstractFieldAccess() {
851
882
val declaringClass: ClassId = fieldId.declaringClass
@@ -854,7 +885,7 @@ class CgStaticFieldAccess(
854
885
855
886
// Conditional statements
856
887
857
- class CgIfStatement (
888
+ data class CgIfStatement (
858
889
val condition : CgExpression ,
859
890
val trueBranch : List <CgStatement >,
860
891
val falseBranch : List <CgStatement >? = null // false branch may be absent
@@ -880,7 +911,7 @@ class CgLogicalAnd(
880
911
override val type: ClassId = booleanClassId
881
912
}
882
913
883
- class CgLogicalOr (
914
+ data class CgLogicalOr (
884
915
val left : CgExpression ,
885
916
val right : CgExpression
886
917
) : CgExpression {
@@ -892,7 +923,7 @@ class CgLogicalOr(
892
923
/* *
893
924
* @param variable represents an array variable
894
925
*/
895
- class CgGetLength (val variable : CgVariable ) : CgExpression {
926
+ data class CgGetLength (val variable : CgVariable ) : CgExpression {
896
927
override val type: ClassId = intClassId
897
928
}
898
929
@@ -902,9 +933,29 @@ sealed class CgGetClass(val classId: ClassId) : CgReferenceExpression {
902
933
override val type: ClassId = Class ::class .id
903
934
}
904
935
905
- class CgGetJavaClass (classId : ClassId ) : CgGetClass(classId)
936
+ class CgGetJavaClass (classId : ClassId ) : CgGetClass(classId) {
937
+ override fun equals (other : Any? ): Boolean {
938
+ if (this == = other) return true
939
+ if (javaClass != other?.javaClass) return false
940
+ return classId == (other as CgGetClass ).classId
941
+ }
906
942
907
- class CgGetKotlinClass (classId : ClassId ) : CgGetClass(classId)
943
+ override fun hashCode (): Int {
944
+ return javaClass.hashCode()
945
+ }
946
+ }
947
+
948
+ class CgGetKotlinClass (classId : ClassId ) : CgGetClass(classId) {
949
+ override fun equals (other : Any? ): Boolean {
950
+ if (this == = other) return true
951
+ if (javaClass != other?.javaClass) return false
952
+ return classId == (other as CgGetClass ).classId
953
+ }
954
+
955
+ override fun hashCode (): Int {
956
+ return javaClass.hashCode()
957
+ }
958
+ }
908
959
909
960
// Executable calls
910
961
@@ -918,15 +969,15 @@ abstract class CgExecutableCall : CgReferenceExpression {
918
969
abstract val typeParameters: TypeParameters
919
970
}
920
971
921
- class CgConstructorCall (
972
+ data class CgConstructorCall (
922
973
override val executableId : ConstructorId ,
923
974
override val arguments : List <CgExpression >,
924
975
override val typeParameters : TypeParameters = TypeParameters ()
925
976
) : CgExecutableCall() {
926
977
override val type: ClassId = executableId.classId
927
978
}
928
979
929
- class CgMethodCall (
980
+ data class CgMethodCall (
930
981
val caller : CgExpression ? ,
931
982
override val executableId : MethodId ,
932
983
override val arguments : List <CgExpression >,
0 commit comments