Skip to content

Commit d93afe5

Browse files
committed
fix main problem;
only two new more spawns: 1) /main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt:75:27: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: don't use nullable type (diktat-ruleset:nullable-type) 2)TreeMappings.kt:75:43: [AVOID_NULL_CHECKS] Try to avoid explicit null-checks: use '.let/.also/?:/e.t.c' instead of excsTypes != null (diktat-ruleset:null-checks)
1 parent 0fe4ef0 commit d93afe5

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

src/main/kotlin/org/polystat/j2eo/eotree/EOMeta.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class EOMeta(var name: String, var value: String) : EONode() {
2424
return true
2525
}
2626

27-
override fun hashCode(): Int {
28-
var result = name.hashCode()
29-
result = 31 * result + value.hashCode()
30-
return result
31-
}
27+
override fun hashCode(): Int =
28+
31 * name.hashCode() + value.hashCode()
3229
}

src/main/kotlin/org/polystat/j2eo/translator/Translator.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class Translator(val relativePath: Path) {
5353

5454
// FIXME: assuming there is only one top-level component and it is a class
5555
val mainClassName = findMainClass(unit)
56-
var entrypointBnds = listOf<EOBndExpr>()
57-
if (mainClassName != null) {
58-
entrypointBnds = generateEntryPoint(mainClassName)
56+
val entrypointBnds = if (mainClassName != null) {
57+
generateEntryPoint(mainClassName)
5958
} else {
6059
logger.info { "No entry point here!" }
60+
listOf()
6161
}
6262

6363
// FIXME: assuming there is only one top-level component and it is a class

src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ fun MemberDeclarationContext.toDeclaration(modifiers: List<ModifierContext>?): L
7272
fun ConstructorDeclarationContext.toDeclaration(modifiers: List<ModifierContext>?): Declaration {
7373
val excsTypes = qualifiedNameList()?.qualifiedName()?.map { TypeName(it.toCompoundName(), null) }
7474

75-
var excsTypeList: TypeList? = null
76-
if (excsTypes != null) {
77-
excsTypeList = TypeList(null)
78-
excsTypeList.types = ArrayList(excsTypes)
75+
val excsTypeList: TypeList? = if (excsTypes != null) {
76+
TypeList(null)
77+
} else {
78+
null
7979
}
8080

81+
excsTypeList?.types = ArrayList(excsTypes)
82+
8183
return ConstructorDeclaration(
8284
modifiers.getModifiers(),
8385
null,

src/test/kotlin/eotree/TestEOLicense.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import java.util.stream.Collectors
1313
class TestEOLicense {
1414
@Test
1515
fun testGenerateEOZeroIndent() {
16-
var license = EOLicense(
16+
val license = EOLicense(
1717
EOComment("test comment 1"),
1818
EOComment("test comment 2")
1919
)
@@ -24,7 +24,7 @@ class TestEOLicense {
2424
# test comment 2
2525
""".trimIndent()
2626
)
27-
license = EOLicense(
27+
val licenseFromStream = EOLicense(
2828
Arrays.stream(
2929
arrayOf(
3030
EOComment("test comment 3"),
@@ -33,7 +33,7 @@ class TestEOLicense {
3333
).collect(Collectors.toList())
3434
)
3535
Assertions.assertEquals(
36-
license.generateEO(0),
36+
licenseFromStream.generateEO(0),
3737
"""
3838
# test comment 3
3939
# test comment 4
@@ -43,7 +43,7 @@ class TestEOLicense {
4343

4444
@Test
4545
fun testGenerateEONonZeroIndent() {
46-
var license = EOLicense(
46+
val license = EOLicense(
4747
EOComment("test comment 5"),
4848
EOComment("test comment 6")
4949
)
@@ -54,7 +54,7 @@ class TestEOLicense {
5454
# test comment 6
5555
""".trimIndent()
5656
)
57-
license = EOLicense(
57+
val licenseFromStream = EOLicense(
5858
Arrays.stream(
5959
arrayOf(
6060
EOComment("test comment 7"),
@@ -63,7 +63,7 @@ class TestEOLicense {
6363
).collect(Collectors.toList())
6464
)
6565
Assertions.assertEquals(
66-
license.generateEO(1),
66+
licenseFromStream.generateEO(1),
6767
"""
6868
# test comment 7
6969
# test comment 8

src/test/kotlin/eotree/data/TestEOByte.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ class TestEOByte {
1111
@Test
1212
fun testGenerateEOZeroIndent() {
1313
// Single-digit byte
14-
var b = EOByte(1.toByte())
15-
Assertions.assertEquals(b.generateEO(0), "01")
14+
val oneByte = EOByte(1.toByte())
15+
Assertions.assertEquals(oneByte.generateEO(0), "01")
1616

1717
// Double-digit byte
18-
b = EOByte(255.toByte())
19-
Assertions.assertEquals(b.generateEO(0), "FF")
18+
val maxByte = EOByte(255.toByte())
19+
Assertions.assertEquals(maxByte.generateEO(0), "FF")
2020
}
2121

2222
@Test
2323
fun testGenerateEONonZeroIndent() {
24-
var b = EOByte(1.toByte())
25-
Assertions.assertEquals(b.generateEO(1), "01")
24+
val oneByte = EOByte(1.toByte())
25+
Assertions.assertEquals(oneByte.generateEO(1), "01")
2626

2727
// Double-digit byte
28-
b = EOByte(255.toByte())
29-
Assertions.assertEquals(b.generateEO(1), "FF")
28+
val maxByte = EOByte(255.toByte())
29+
Assertions.assertEquals(maxByte.generateEO(1), "FF")
3030
}
3131
}

0 commit comments

Comments
 (0)