Skip to content

Commit 23a106b

Browse files
authored
Add class category (#311)
1 parent b4d4f21 commit 23a106b

File tree

8 files changed

+65
-5
lines changed

8 files changed

+65
-5
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
DEST_DIR="arkanalyzer"
6565
MAX_RETRIES=10
6666
RETRY_DELAY=3 # Delay between retries in seconds
67-
BRANCH="neo/2025-03-20"
67+
BRANCH="neo/2025-03-21"
6868
6969
for ((i=1; i<=MAX_RETRIES; i++)); do
7070
git clone --depth=1 --branch $BRANCH $REPO_URL $DEST_DIR && break

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ import org.jacodb.ets.base.EtsVoidType
111111
import org.jacodb.ets.base.EtsYieldExpr
112112
import org.jacodb.ets.graph.EtsCfg
113113
import org.jacodb.ets.model.EtsClass
114+
import org.jacodb.ets.model.EtsClassCategory
114115
import org.jacodb.ets.model.EtsClassImpl
115116
import org.jacodb.ets.model.EtsClassSignature
116117
import org.jacodb.ets.model.EtsDecorator
@@ -534,6 +535,7 @@ fun ClassDto.toEtsClass(): EtsClass {
534535
val methods = methodDtos.map { it.toEtsMethod() }
535536
val ctor = ctorDto.toEtsMethod()
536537

538+
val category = category.toEtsClassCategory()
537539
val typeParameters = typeParameters?.map { it.toEtsType() } ?: emptyList()
538540

539541
val modifiers = EtsModifiers(modifiers)
@@ -544,6 +546,7 @@ fun ClassDto.toEtsClass(): EtsClass {
544546
fields = fields,
545547
methods = methods,
546548
ctor = ctor,
549+
category = category,
547550
superClass = superClassSignature,
548551
implementedInterfaces = implementedInterfaces,
549552
typeParameters = typeParameters,
@@ -788,3 +791,15 @@ fun LocalDto.toEtsLocal(): EtsLocal {
788791
type = type.toEtsType(),
789792
)
790793
}
794+
795+
private fun Int.toEtsClassCategory() : EtsClassCategory {
796+
return when (this) {
797+
0 -> EtsClassCategory.CLASS
798+
1 -> EtsClassCategory.STRUCT
799+
2 -> EtsClassCategory.INTERFACE
800+
3 -> EtsClassCategory.ENUM
801+
4 -> EtsClassCategory.TYPE_LITERAL
802+
5 -> EtsClassCategory.OBJECT
803+
else -> error("Unknown class category: $this")
804+
}
805+
}

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Model.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ data class ClassDto(
5959
val signature: ClassSignatureDto,
6060
val modifiers: Int,
6161
val decorators: List<DecoratorDto>,
62+
val category: Int = 0,
6263
val typeParameters: List<TypeDto>? = null,
6364
val superClassName: String?,
6465
val implementedInterfaceNames: List<String>,

jacodb-ets/src/main/kotlin/org/jacodb/ets/graph/EtsCfg.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class EtsCfg(
5757
}
5858

5959
override fun predecessors(node: EtsStmt): Set<EtsStmt> {
60-
return predecessorMap[node]!!
60+
return predecessorMap[node].orEmpty()
6161
}
6262

6363
companion object {

jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsClass.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface EtsClass : EtsBaseModel {
2424
val fields: List<EtsField>
2525
val methods: List<EtsMethod>
2626
val ctor: EtsMethod
27+
val category: EtsClassCategory
2728
val superClass: EtsClassSignature?
2829
val implementedInterfaces: List<EtsClassSignature>
2930

@@ -36,6 +37,7 @@ class EtsClassImpl(
3637
override val fields: List<EtsField>,
3738
override val methods: List<EtsMethod>,
3839
override val ctor: EtsMethod,
40+
override val category: EtsClassCategory = EtsClassCategory.CLASS,
3941
override val superClass: EtsClassSignature? = null,
4042
override val implementedInterfaces: List<EtsClassSignature> = emptyList(),
4143
override val typeParameters: List<EtsType> = emptyList(),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.ets.model
18+
19+
enum class EtsClassCategory {
20+
CLASS,
21+
STRUCT,
22+
INTERFACE,
23+
ENUM,
24+
TYPE_LITERAL,
25+
OBJECT,
26+
}

jacodb-ets/src/test/kotlin/org/jacodb/ets/test/EtsFromJsonTest.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.jacodb.ets.dto.ValueDto
4747
import org.jacodb.ets.dto.dtoModule
4848
import org.jacodb.ets.dto.toEtsLocal
4949
import org.jacodb.ets.dto.toEtsMethod
50+
import org.jacodb.ets.model.EtsClassCategory
5051
import org.jacodb.ets.model.EtsClassSignature
5152
import org.jacodb.ets.model.EtsFile
5253
import org.jacodb.ets.model.EtsFileSignature
@@ -478,8 +479,19 @@ class EtsFromJsonTest {
478479
val path = "/samples/etsir/ast/lang/vararg.ts.json"
479480
val file = loadEtsFileFromResource(path)
480481
val method = file.classes.flatMap { it.methods }.first { it.name == "f" }
481-
assertEquals(method.parameters.size, 2)
482-
assertEquals(method.parameters[0].isRest, false)
483-
assertEquals(method.parameters[1].isRest, true)
482+
assertEquals(2, method.parameters.size)
483+
assertEquals(false, method.parameters[0].isRest)
484+
assertEquals(true, method.parameters[1].isRest)
485+
}
486+
487+
@Test
488+
fun testClassCategory() {
489+
val path = "/samples/etsir/ast/lang/enum.ts.json"
490+
val file = loadEtsFileFromResource(path)
491+
val cls = file.classes.first { it.name == "Animal" }
492+
assertEquals(EtsClassCategory.ENUM, cls.category)
493+
assertEquals(2, cls.fields.size)
494+
assertEquals("Cat", cls.fields[0].name)
495+
assertEquals("Dog", cls.fields[1].name)
484496
}
485497
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
enum Animal {
2+
Cat,
3+
Dog,
4+
}

0 commit comments

Comments
 (0)