Skip to content

Commit

Permalink
Remove name field from BuiltinClassId (#1200)
Browse files Browse the repository at this point in the history
* Remove name field from BuiltinClassId

* Little correction

* Apply corrections

* Fix missed field
  • Loading branch information
EgorkaKulikov authored Oct 21, 2022
1 parent 3cd8e7b commit 80a962b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,11 @@ open class ClassId @JvmOverloads constructor(
* (it is important because name for nested classes contains $ as a delimiter between nested and outer classes)
*/
class BuiltinClassId(
name: String,
elementClassId: ClassId? = null,
override val canonicalName: String,
override val simpleName: String,
// set name manually only if it differs from canonical (e.g. for nested classes)
name: String = canonicalName,
// by default, we assume that the class is not a member class
override val simpleNameWithEnclosings: String = simpleName,
override val isNullable: Boolean = false,
Expand Down Expand Up @@ -906,7 +907,11 @@ class BuiltinClassId(
-1, 0 -> ""
else -> canonicalName.substring(0, index)
},
) : ClassId(name = name, isNullable = isNullable, elementClassId = elementClassId) {
) : ClassId(
name = name,
elementClassId = elementClassId,
isNullable = isNullable,
) {
init {
BUILTIN_CLASSES_BY_NAMES[name] = this
}
Expand All @@ -924,7 +929,6 @@ class BuiltinClassId(
fun getBuiltinClassByNameOrNull(name: String): BuiltinClassId? = BUILTIN_CLASSES_BY_NAMES[name]
}
}

enum class FieldIdStrategyValues {
Reflection,
Soot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,11 @@ object NoStaticMocking : StaticsMocking(
object MockitoStaticMocking : StaticsMocking(id = "Mockito static mocking", displayName = "Mockito static mocking") {

val mockedStaticClassId = BuiltinClassId(
name = "org.mockito.MockedStatic",
canonicalName = "org.mockito.MockedStatic",
simpleName = "MockedStatic"
)

val mockedConstructionClassId = BuiltinClassId(
name = "org.mockito.MockedConstruction",
canonicalName = "org.mockito.MockedConstruction",
simpleName = "MockedConstruction"
)
Expand Down Expand Up @@ -264,21 +262,18 @@ object TestNg : TestFramework(id = "TestNG",displayName = "TestNG") {
internal const val testXmlName: String = "testng.xml"

override val assertionsClass: ClassId = BuiltinClassId(
name = TEST_NG_ASSERTIONS,
canonicalName = TEST_NG_ASSERTIONS,
simpleName = "Assert"
)

override val arraysAssertionsClass: ClassId = BuiltinClassId(
name = TEST_NG_ARRAYS_ASSERTIONS,
canonicalName = TEST_NG_ARRAYS_ASSERTIONS,
simpleName = "ArrayAsserts"
)

override val assertBooleanArrayEquals by lazy { assertionId("assertEquals", booleanArrayClassId, booleanArrayClassId) }

val throwingRunnableClassId = BuiltinClassId(
name = "${assertionsClass.name}\$ThrowingRunnable",
canonicalName = "${assertionsClass.canonicalName}.ThrowingRunnable",
simpleName = "ThrowingRunnable"
)
Expand All @@ -295,19 +290,16 @@ object TestNg : TestFramework(id = "TestNG",displayName = "TestNG") {
)

override val testAnnotationId: ClassId = BuiltinClassId(
name = "$mainPackage.annotations.Test",
canonicalName = "$mainPackage.annotations.Test",
simpleName = "Test"
)

override val parameterizedTestAnnotationId: ClassId = BuiltinClassId(
name = "$mainPackage.annotations.Test",
canonicalName = "$mainPackage.annotations.Test",
simpleName = "Test"
simpleName = "Test",
)

override val methodSourceAnnotationId: ClassId = BuiltinClassId(
name = "$mainPackage.annotations.DataProvider",
canonicalName = "$mainPackage.annotations.DataProvider",
simpleName = "DataProvider"
)
Expand All @@ -318,7 +310,6 @@ object TestNg : TestFramework(id = "TestNG",displayName = "TestNG") {
get() {
val outerArrayId = Array<Array<Any?>?>::class.id
val innerArrayId = BuiltinClassId(
name = objectArrayClassId.name,
simpleName = objectArrayClassId.simpleName,
canonicalName = objectArrayClassId.canonicalName,
packageName = objectArrayClassId.packageName,
Expand All @@ -327,7 +318,6 @@ object TestNg : TestFramework(id = "TestNG",displayName = "TestNG") {
)

return BuiltinClassId(
name = outerArrayId.name,
simpleName = outerArrayId.simpleName,
canonicalName = outerArrayId.canonicalName,
packageName = outerArrayId.packageName,
Expand Down Expand Up @@ -398,7 +388,6 @@ object Junit4 : TestFramework(id = "JUnit4",displayName = "JUnit 4") {
get() = parametrizedTestsNotSupportedError

override val testAnnotationId = BuiltinClassId(
name = "$JUNIT4_PACKAGE.Test",
canonicalName = "$JUNIT4_PACKAGE.Test",
simpleName = "Test"
)
Expand All @@ -407,28 +396,24 @@ object Junit4 : TestFramework(id = "JUnit4",displayName = "JUnit 4") {
override val methodSourceAnnotationId = voidClassId

val runWithAnnotationClassId = BuiltinClassId(
name = "$JUNIT4_PACKAGE.runner.RunWith",
canonicalName = "$JUNIT4_PACKAGE.runner.RunWith",
simpleName = "RunWith"
)

override val assertionsClass = BuiltinClassId(
name = JUNIT4_ASSERTIONS,
canonicalName = JUNIT4_ASSERTIONS,
simpleName = "Assert"
)
override val arraysAssertionsClass = assertionsClass

val ignoreAnnotationClassId = with("$JUNIT4_PACKAGE.Ignore") {
BuiltinClassId(
name = this,
canonicalName = this,
simpleName = "Ignore"
)
}

val enclosedClassId = BuiltinClassId(
name = "org.junit.experimental.runners.Enclosed",
canonicalName = "org.junit.experimental.runners.Enclosed",
simpleName = "Enclosed"
)
Expand Down Expand Up @@ -463,25 +448,21 @@ object Junit5 : TestFramework(id = "JUnit5", displayName = "JUnit 5") {
override val methodSourceAnnotationFqn: String = "$JUNIT5_PARAMETERIZED_PACKAGE.provider.MethodSource"

val executableClassId = BuiltinClassId(
name = "$JUNIT5_PACKAGE.function.Executable",
canonicalName = "$JUNIT5_PACKAGE.function.Executable",
simpleName = "Executable"
)

val timeoutClassId = BuiltinClassId(
name = "$JUNIT5_PACKAGE.Timeout",
canonicalName = "$JUNIT5_PACKAGE.Timeout",
simpleName = "Timeout"
)

val timeunitClassId = BuiltinClassId(
name = "TimeUnit",
canonicalName = "java.util.concurrent.TimeUnit",
simpleName = "TimeUnit"
)

val durationClassId = BuiltinClassId(
name = "Duration",
canonicalName = "java.time.Duration",
simpleName = "Duration"
)
Expand All @@ -494,31 +475,26 @@ object Junit5 : TestFramework(id = "JUnit5", displayName = "JUnit 5") {
)

val nestedTestClassAnnotationId = BuiltinClassId(
name = "$JUNIT5_PACKAGE.Nested",
canonicalName = "$JUNIT5_PACKAGE.Nested",
simpleName = "Nested"
)

override val testAnnotationId = BuiltinClassId(
name = "$JUNIT5_PACKAGE.Test",
canonicalName = "$JUNIT5_PACKAGE.Test",
simpleName = "Test"
)

override val parameterizedTestAnnotationId = BuiltinClassId(
name = "$JUNIT5_PARAMETERIZED_PACKAGE.ParameterizedTest",
canonicalName = "$JUNIT5_PARAMETERIZED_PACKAGE.ParameterizedTest",
simpleName = "ParameterizedTest"
)

override val methodSourceAnnotationId: ClassId = BuiltinClassId(
name = "$JUNIT5_PARAMETERIZED_PACKAGE.provider.MethodSource",
canonicalName = "$JUNIT5_PARAMETERIZED_PACKAGE.provider.MethodSource",
simpleName = "MethodSource"
)

override val assertionsClass = BuiltinClassId(
name = JUNIT5_ASSERTIONS,
canonicalName = JUNIT5_ASSERTIONS,
simpleName = "Assertions"
)
Expand Down Expand Up @@ -547,14 +523,12 @@ object Junit5 : TestFramework(id = "JUnit5", displayName = "JUnit 5") {
)

val displayNameClassId = BuiltinClassId(
name = "$JUNIT5_PACKAGE.DisplayName",
canonicalName = "$JUNIT5_PACKAGE.DisplayName",
simpleName = "DisplayName"
)

val disabledAnnotationClassId = with("$JUNIT5_PACKAGE.Disabled") {
BuiltinClassId(
name = this,
canonicalName = this,
simpleName = "Disabled"
)
Expand All @@ -566,7 +540,6 @@ object Junit5 : TestFramework(id = "JUnit5", displayName = "JUnit 5") {
get() {
val arrayListId = java.util.ArrayList::class.id
return BuiltinClassId(
name = arrayListId.name,
simpleName = arrayListId.simpleName,
canonicalName = arrayListId.canonicalName,
packageName = arrayListId.packageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,31 @@ import org.utbot.framework.plugin.api.util.objectClassId
import org.utbot.framework.plugin.api.util.shortClassId
import org.utbot.framework.plugin.api.util.stringClassId

internal val mockitoBuiltins: Set<MethodId>
get() = setOf(
mockMethodId, whenMethodId, thenMethodId, thenReturnMethodId,
any, anyOfClass, anyByte, anyChar, anyShort, anyInt, anyLong,
anyFloat, anyDouble, anyBoolean, anyString
)

internal val mockitoClassId = BuiltinClassId(
name = "org.mockito.Mockito",
canonicalName = "org.mockito.Mockito",
simpleName = "Mockito",
)

internal val ongoingStubbingClassId = BuiltinClassId(
name = "org.mockito.stubbing.OngoingStubbing",
canonicalName = "org.mockito.stubbing.OngoingStubbing",
simpleName = "OngoingStubbing",
)

internal val answerClassId = BuiltinClassId(
name = "org.mockito.stubbing.Answer",
canonicalName = "org.mockito.stubbing.Answer",
simpleName = "Answer",
)

internal val argumentMatchersClassId = BuiltinClassId(
name = "org.mockito.ArgumentMatchers",
canonicalName = "org.mockito.ArgumentMatchers",
simpleName = "ArgumentMatchers",
)

internal val mockedConstructionContextClassId = BuiltinClassId(
name = "org.mockito.MockedConstruction.Context",
canonicalName = "org.mockito.MockedConstruction.Context", // TODO use $ as a delimiter of outer and nested classes?
canonicalName = "org.mockito.MockedConstruction.Context",
simpleName = "Context",
isNested = true
name = "org.mockito.MockedConstruction\$Context",
isNested = true,
)

internal val mockMethodId = builtinStaticMethodId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ internal abstract class UtilMethodProvider(val utilClassId: ClassId) {

val capturedArgumentClassId: BuiltinClassId
get() = BuiltinClassId(
name = "${utilClassId.name}\$CapturedArgument",
canonicalName = "${utilClassId.name}.CapturedArgument",
simpleName = "CapturedArgument"
)
Expand Down Expand Up @@ -269,10 +268,9 @@ internal class TestClassUtilMethodProvider(testClassId: ClassId) : UtilMethodPro

internal val utUtilsClassId: ClassId
get() = BuiltinClassId(
name = "org.utbot.runtime.utils.UtUtils",
canonicalName = "org.utbot.runtime.utils.UtUtils",
simpleName = "UtUtils",
isFinal = true
isFinal = true,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ internal data class CgContext(
val simpleName = testClassCustomName ?: "${classUnderTest.simpleName}Test"
val name = "$packagePrefix$simpleName"
BuiltinClassId(
name = name,
canonicalName = name,
simpleName = simpleName
)
Expand Down Expand Up @@ -548,7 +547,6 @@ internal data class CgContext(
private fun createClassIdForNestedClass(testClassModel: TestClassModel): ClassId {
val simpleName = "${testClassModel.classUnderTest.simpleName}Test"
return BuiltinClassId(
name = currentTestClass.name + "$" + simpleName,
canonicalName = currentTestClass.canonicalName + "." + simpleName,
simpleName = simpleName
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,6 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
val expectedException = CgParameterDeclaration(
parameter = declareParameter(
type = BuiltinClassId(
name = classClassId.name,
simpleName = classClassId.simpleName,
canonicalName = classClassId.canonicalName,
packageName = classClassId.packageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ internal val addToListMethodId: MethodId
*/
internal val argumentsClassId: BuiltinClassId
get() = BuiltinClassId(
name = "org.junit.jupiter.params.provider.Arguments",
simpleName = "Arguments",
canonicalName = "org.junit.jupiter.params.provider.Arguments",
packageName = "org.junit.jupiter.params.provider"
Expand Down Expand Up @@ -314,7 +313,6 @@ fun arrayTypeOf(elementType: ClassId, isNullable: Boolean = false): ClassId {
val arrayIdName = "[${elementType.arrayLikeName}"
return when (elementType) {
is BuiltinClassId -> BuiltinClassId(
name = arrayIdName,
canonicalName = "${elementType.canonicalName}[]",
simpleName = "${elementType.simpleName}[]",
elementClassId = elementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ class CgNotNullAssertion(val expression: CgExpression) : CgValue {
override val type: ClassId
get() = when (val expressionType = expression.type) {
is BuiltinClassId -> BuiltinClassId(
name = expressionType.name,
canonicalName = expressionType.canonicalName,
simpleName = expressionType.simpleName,
isNullable = false,
Expand Down

0 comments on commit 80a962b

Please sign in to comment.