Kotlin - 1.1


Extension ID

com.castsoftware.kotlin

What’s new?

See Release Notes.

Description

If your application contains Kotlin source code and you want to view these object types and their links with other objects, then you should install this extension. All files with the .kt extension are analyzed. Kotlin code and Java code may coexist in the same application, and a Kotlin method may call a Java method, and inversely. If a JEE analysis is defined for the Application, call links from Kotlin methods to Java methods should be created. But links from Java methods to Kotlin methods are not supported yet: this is a limitation.

Technology support

  • Kotlin 1.x

Function Point, Quality and Sizing support

  • Function Points (transactions): A green tick indicates that OMG Function Point counting and Transaction Risk Index are supported.
  • Quality and Sizing: A green tick indicates that CAST can measure size and that a minimum set of Quality Rules exist.
Function Points (transactions) Quality and Sizing

Compatibility

Core release Operating System Supported
8.4.x Microsoft Windows / Linux
8.3.x Microsoft Windows

Download and installation instructions

The extension will be automatically installed by CAST Imaging Console when at least one .kt file is delivered for analysis.

Source code discovery

A discoverer is provided with the extension to automatically detect Kotlin code: one Kotlin project will be discovered for the package’s root folder when at least one .kt file is detected in the root folder or any sub-folders, resulting in a corresponding Universal Technology Analysis Unit.

Supported frameworks

The following libraries are supported for Web Service HTTP calls:

  • Retrofit
  • Android Volley
  • Spring Http

Once the Kotlin extension analysis is finished, the analyzer will output the final number of web service calls created.

The following libraries are supported for database calls:

  • Spring JDBC
  • Android SQLite
  • Android Room

Once the Kotlin extension analysis is finished, the analyzer will output the final number of sql links created.

Retrofit

import retrofit2.http.GET
import retrofit2.http.POST
interface ApiInterfaces {
@GET("v2/Contacts")
fun getContacts(): Call<CrmContacts>

@POST("v2/Contacts")
fun addContact(): Call<AddResponse>
}

This code produces Web Service HTTP calls

Android Volley

import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.VolleyError
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley

class MainActivity
{
    private fun apiHit() {
        val textView : AppCompatTextView = findViewById(R.id.textView)
        val url = "https://jsonplaceholder.typicode.com/users"
        val queue : RequestQueue = Volley.newRequestQueue(this)
        val request =  JsonObjectRequest(Request.Method.POST ,  url, null , {
            response: JSONObject? ->
            textView.text = response.toString()
        } , {
            error: VolleyError? ->
            textView.text =  error.toString()
        })
        queue.add(request)
    }
}

JsonObjectRequest, StringRequest are supported

This code produces Web Service HTTP calls

Spring http operation (since version 1.0.3-funcrel)

import org.springframework.stereotype.Controller
import org.springframework.validation.BindingResult
import org.springframework.web.bind.WebDataBinder
import org.springframework.web.bind.annotation.*

interface ApiInterfaces {
@Controller
class VisitController(val visits: VisitRepository, val pets: PetRepository) {
    // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
    @GetMapping("/owners/*/pets/{petId}/visits/new")
    fun initNewVisitForm(@PathVariable("petId") petId: Int, model: Map<String, Any>): String
            = "pets/createOrUpdateVisitForm"
}

This code produces Web Service HTTP operations. Supported annotations are:

  • @GetMapping
  • @PostMapping
  • @PutMapping
  • @DeleteMapping

Spring beans (since version 1.0.3-funcrel)

The following code:

import pkg.queue.StandaloneBxCleanup
import org.springframework.context.annotation.AnnotationConfigApplicationContext
        
fun main(args: Array<String>) {
    val standaloneBxCleanup = app.getBean(StandaloneBxCleanup::class.java)
    standaloneBxCleanup.cleanupBxData()
}
package pkg.queue
        
@Component
class StandaloneBxCleanup(@Autowired val parseProcApiFactory: ProcApiFactory,
                          @Autowired val bxCleanerFactory: BxCleanerFactory,
                          @Autowired val cleanupExecutorService: ExecutorService) {
    fun cleanupBxData() {
    }
}

will generate the following links when analyzed:

The following code:

import pkg.queue.BillQueueProcessor
import org.springframework.context.annotation.AnnotationConfigApplicationContext
        
fun main(args: Array<String>) {
    val billQueueProcessor= app.getBean(BillQueueProcessor::class.java)
    Thread(billQueueProcessor).start()
}
package pkg.queue
        
@Component
class BillQueueProcessor(@Autowired val parseProcApiFactory: ProcApiFactory,
                          @Autowired val bxCleanerFactory: BxCleanerFactory,
                          @Autowired val cleanupExecutorService: ExecutorService) {
    override fun run() {
    }
}

will generate the following links when analyzed:

Spring JDBC (since version 1.0.3-funcrel)

Only links to database procedures are supported. The following code:

package pkg.db.proc

import org.springframework.jdbc.`object`.StoredProcedure

class BxCleanupBillList(jdbcTemplate: JdbcTemplate) :
        StoredProcedure(jdbcTemplate, "best.pkg_bb_bill_load.bbl_get_bx_cleanup_bills") {
        
    fun getBxCleanupBills(): List<Long> {
        val outputParams = execute()
        return outputParams[cv1Param] as List<Long>
    }
}

will generate the following links when analyzed:

Same for following code where “REPLACE_FORBEARANCE” is a procedure.

interface ForbearanceRepository : CrudRepository<Client, String> {

    @Query("CALL FORBEARANCE_P.REPLACE_FORBEARANCE(:clientId, :eventId, :category, :type, :subtype, :note, :reasons, :accountNumber, :productSource, :expectedEndDate, :monitoringPeriodStartDate, :forbearanceChangeRequestAt, :source)")
    fun replaceForbearance(clientId: String,
                           eventId: String,
                           category: String,
                           type: String,
                           subtype: String?,
                           note: String?,
                           reasons: String?,
                           accountNumber: String?,
                           productSource: String?,
                           expectedEndDate: LocalDate?,
                           monitoringPeriodStartDate: LocalDate?,
                           forbearanceChangeRequestAt: LocalDate?,
                           source: String)
}

A link is created to the “FORBEARANCE_CV” table for code:

interface ForbearanceRepository : CrudRepository<Client, String> {

    @Query("select * from FORBEARANCE_CV f where f.CLIENT_ID = :clientId", rowMapperClass = ForbearanceAdapter.ForbearanceMapper::class)
    fun replaceForbearance(clientId: String,
                           eventId: String,
                           category: String,
                           type: String,
                           subtype: String?,
                           note: String?,
                           reasons: String?,
                           accountNumber: String?,
                           productSource: String?,
                           expectedEndDate: LocalDate?,
                           monitoringPeriodStartDate: LocalDate?,
                           forbearanceChangeRequestAt: LocalDate?,
                           source: String)
}

A link to the “ENROLL_CORPORATE_CLIENT” procedure is created for code:

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate

....
            namedParameterJdbcTemplate.update("""
                    CALL ENROLLMENT_P.ENROLL_CORPORATE_CLIENT(
                        :enrollmentDraftId
                    )""".trimIndent(),...)
 

Android SQLite (since version 1.1.8-funcrel)

Supported libraries are:

  • android.database.sqlite.SQLiteDatabase
  • androidx.sqlite.db.SupportSQLiteDatabase
package fr

import androidx.sqlite.db.SupportSQLiteDatabase

abstract class GalleryDatabase : RoomDatabase() {
    companion object {
        private val MIGRATION_4_5 = object : Migration(4, 5) {
            override fun migrate(database: SupportSQLiteDatabase) {
                database.execSQL("ALTER TABLE media ADD COLUMN video_duration INTEGER default 0 NOT NULL")
            }
        }
    }
}

img.png

Android Room (since version 1.1.8-funcrel)

Supported libraries are:

  • androidx.room
  • android.arch.persistence.room
package fr

import androidx.room.Entity

@Entity(
    tableName = "card_alert", primaryKeys = ["idelco", "type"]
)
data class Alert (
    val idelco: String,
    val type: AlertType,
)
import androidx.room.*
import fr.Alert

@Dao
abstract class AlertDao {

    @Query("DELETE FROM card_alert")
    abstract fun deleteAll()

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    abstract fun insert(obj: Alert): Long

    @Update
    abstract fun update(obj: Alert)
}

img.png

img.png

What results can you expect?

Example application

Kotlin code which calls java code:

Properties, getters, setters

Alt text

class class1 {
    val counter = 0
        get() = field
        set(value) {
            if (value >= 0)
                field = value
        }
}

Objects

Icon Description
Kotlin anonymous class
Kotlin class / Kotlin generic class / Kotlin JVM class / Kotlin JVM generic class
Kotlin function / Kotlin JVM method
Kotlin generic interface / Kotlin interface
Kotlin instantiated class
Kotlin lambda
Kotlin main
Kotlin method
Kotlin object
Kotlin property
Kotlin getter
Kotlin setter
Kotlin source code
Kotlin Get HttpRequest Service

Kotlin Web service Get Operation
Kotlin Post HttpRequest Service

Kotlin Web service Post Operation
Kotlin Delete HttpRequest Service

Kotlin Web service Delete Operation
Kotlin Put HttpRequest Service

Kotlin Web service Put Operation
Kotlin SQL Query
Kotlin Entity
Kotlin Entity Operation

Structural rules

The following structural rules are provided:

You can also find a global list here: https://technologies.castsoftware.com/AIP/technologies/1030000external link.

Known Limitations

  • Links from Java methods to Kotlin methods are not supported.