Skip to content

Commit

Permalink
chore: Align Class Names
Browse files Browse the repository at this point in the history
  • Loading branch information
wba2hi committed Mar 7, 2024
1 parent 373382e commit adb2002
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import com.squareup.kotlinpoet.ksp.writeTo
import org.eclipse.kuksa.vsscore.annotation.VssDefinition
import org.eclipse.kuksa.vsscore.model.VssNode
import org.eclipse.kuksa.vsscore.model.parentClassName
import org.eclipse.kuksa.vssprocessor.parser.factory.VssDefinitionParserFactory
import org.eclipse.kuksa.vssprocessor.parser.factory.VssParserFactory
import org.eclipse.kuksa.vssprocessor.spec.VssNodeSpecModel
import org.eclipse.kuksa.vssprocessor.spec.VssPath
import org.eclipse.kuksa.vssprocessor.spec.VssSpecificationSpecModel
import java.io.File

/**
Expand All @@ -51,12 +51,12 @@ import java.io.File
* @param codeGenerator to generate class files with
* @param logger to log output with
*/
class VssDefinitionProcessor(
class VssModelGeneratorProcessor(
private val codeGenerator: CodeGenerator,
private val logger: KSPLogger,
) : SymbolProcessor {
private val visitor = VssDefinitionVisitor()
private val vssDefinitionParserFactory = VssDefinitionParserFactory()
private val vssParserFactory = VssParserFactory()

override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(VssDefinition::class.qualifiedName.toString())
Expand Down Expand Up @@ -86,11 +86,11 @@ class VssDefinitionProcessor(
return
}

val simpleSpecificationElements = mutableListOf<VssSpecificationSpecModel>()
val simpleSpecificationElements = mutableListOf<VssNodeSpecModel>()
definitionFiles.forEach { definitionFile ->
logger.info("Parsing models for definition file: ${definitionFile.name}")
val vssDefinitionParser = vssDefinitionParserFactory.create(definitionFile)
val specModels = vssDefinitionParser.parseSpecifications(definitionFile)
val vssDefinitionParser = vssParserFactory.create(definitionFile)
val specModels = vssDefinitionParser.parseNodes(definitionFile)

simpleSpecificationElements.addAll(specModels)
}
Expand All @@ -116,7 +116,7 @@ class VssDefinitionProcessor(
.toSet()
}

private fun generateModelFiles(vssPathToSpecification: Map<VssPath, VssSpecificationSpecModel>) {
private fun generateModelFiles(vssPathToSpecification: Map<VssPath, VssNodeSpecModel>) {
val duplicateSpecificationNames = vssPathToSpecification.keys
.groupBy { it.leaf }
.filter { it.value.size > 1 }
Expand Down Expand Up @@ -159,7 +159,7 @@ class VssDefinitionProcessor(
// If the actual parent is a sub class (Driver) in another class file (e.g. Vehicle) then this method returns
// a sub import e.g. "Vehicle.Driver". Otherwise just "Vehicle" is returned.
private fun buildParentImport(
specModel: VssSpecificationSpecModel,
specModel: VssNodeSpecModel,
parentVssPathToClassName: Map<String, String>,
): String {
var availableParentVssPath = specModel.vssPath
Expand Down Expand Up @@ -200,12 +200,12 @@ class VssDefinitionProcessor(
}

/**
* Provides the environment for the [VssDefinitionProcessor].
* Provides the environment for the [VssModelGeneratorProcessor].
*/
class VssDefinitionProcessorProvider : SymbolProcessorProvider {
override fun create(
environment: SymbolProcessorEnvironment,
): SymbolProcessor {
return VssDefinitionProcessor(environment.codeGenerator, environment.logger)
return VssModelGeneratorProcessor(environment.codeGenerator, environment.logger)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

package org.eclipse.kuksa.vssprocessor.parser

import org.eclipse.kuksa.vssprocessor.spec.VssSpecificationSpecModel
import org.eclipse.kuksa.vssprocessor.spec.VssNodeSpecModel
import java.io.File

internal interface VssDefinitionParser {
internal interface VssParser {
/**
* @param definitionFile to parse [VssSpecificationSpecModel] with
* @param definitionFile to parse [VssNodeSpecModel] with
*
* @throws java.io.IOException will be thrown when parsing the SpecModels failed
*/
fun parseSpecifications(definitionFile: File): List<VssSpecificationSpecModel>
fun parseNodes(definitionFile: File): List<VssNodeSpecModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@

package org.eclipse.kuksa.vssprocessor.parser.factory

import org.eclipse.kuksa.vssprocessor.parser.VssDefinitionParser
import org.eclipse.kuksa.vssprocessor.parser.VssParser
import org.eclipse.kuksa.vssprocessor.parser.factory.VssFileExtension.JSON
import org.eclipse.kuksa.vssprocessor.parser.factory.VssFileExtension.YAML
import org.eclipse.kuksa.vssprocessor.parser.json.JsonDefinitionParser
import org.eclipse.kuksa.vssprocessor.parser.yaml.YamlDefinitionParser
import org.eclipse.kuksa.vssprocessor.parser.json.JsonVssParser
import org.eclipse.kuksa.vssprocessor.parser.yaml.YamlVssParser
import java.io.File

internal class VssDefinitionParserFactory {
internal class VssParserFactory {

/**
* @throws IllegalStateException when the specified extension is not supported
*/
fun create(extension: String): VssDefinitionParser {
fun create(extension: String): VssParser {
return when {
JSON.fileExtensions.contains(extension) -> {
JsonDefinitionParser()
JsonVssParser()
}

YAML.fileExtensions.contains(extension) -> {
YamlDefinitionParser()
YamlVssParser()
}

else -> {
Expand All @@ -50,7 +50,7 @@ internal class VssDefinitionParserFactory {
/**
* @throws IllegalStateException when the extension of the specified file is not supported
*/
fun create(file: File): VssDefinitionParser {
fun create(file: File): VssParser {
val fileName = file.name // with extension
val fileExtension = fileName.substringAfterLast(".")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ package org.eclipse.kuksa.vssprocessor.parser.json
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonParseException
import org.eclipse.kuksa.vssprocessor.parser.VssDefinitionParser
import org.eclipse.kuksa.vssprocessor.spec.VssSpecificationSpecModel
import org.eclipse.kuksa.vssprocessor.parser.VssParser
import org.eclipse.kuksa.vssprocessor.spec.VssNodeSpecModel
import java.io.File
import java.io.IOException

Expand All @@ -36,7 +36,7 @@ private const val KEY_DATA_COMMENT = "comment"
private const val KEY_DATA_DATATYPE = "datatype"
private const val KEY_DATA_CHILDREN = "children"

internal class JsonDefinitionParser : VssDefinitionParser {
internal class JsonVssParser : VssParser {
private val dataKeys = listOf(
KEY_DATA_DESCRIPTION,
KEY_DATA_TYPE,
Expand All @@ -46,8 +46,8 @@ internal class JsonDefinitionParser : VssDefinitionParser {
KEY_DATA_CHILDREN,
)

override fun parseSpecifications(definitionFile: File): List<VssSpecificationSpecModel> {
val vssSpecificationSpecModels = mutableListOf<VssSpecificationSpecModel>()
override fun parseNodes(definitionFile: File): List<VssNodeSpecModel> {
val vssNodeSpecModels = mutableListOf<VssNodeSpecModel>()

try {
val jsonStreamReader = definitionFile.reader()
Expand All @@ -57,22 +57,22 @@ internal class JsonDefinitionParser : VssDefinitionParser {

if (rootJsonObject.has(ROOT_KEY_VEHICLE)) {
val vehicleJsonObject = rootJsonObject.getAsJsonObject(ROOT_KEY_VEHICLE)
vssSpecificationSpecModels += parseSpecModels(ROOT_KEY_VEHICLE, vehicleJsonObject)
vssNodeSpecModels += parseSpecModels(ROOT_KEY_VEHICLE, vehicleJsonObject)
} else {
throw IOException("Invalid VSS Specification file '${definitionFile.path}'")
}
} catch (e: JsonParseException) {
throw IOException("Invalid VSS Specification file '${definitionFile.path}'", e)
}

return vssSpecificationSpecModels.toList()
return vssNodeSpecModels.toList()
}

private fun parseSpecModels(
vssPath: String,
jsonObject: JsonObject,
): Collection<VssSpecificationSpecModel> {
val parsedSpecModels = mutableListOf<VssSpecificationSpecModel>()
): Collection<VssNodeSpecModel> {
val parsedSpecModels = mutableListOf<VssNodeSpecModel>()

val parsedSpecModel = parseSpecModel(vssPath, jsonObject)
parsedSpecModels += parsedSpecModel
Expand All @@ -97,7 +97,7 @@ internal class JsonDefinitionParser : VssDefinitionParser {
private fun parseSpecModel(
vssPath: String,
jsonObject: JsonObject,
): VssSpecificationSpecModel {
): VssNodeSpecModel {
val uuid = jsonObject.get(KEY_DATA_UUID).asString
?: throw JsonParseException("Could not parse '$KEY_DATA_UUID' for '$vssPath'")

Expand All @@ -108,6 +108,6 @@ internal class JsonDefinitionParser : VssDefinitionParser {
val datatype = jsonObject.get(KEY_DATA_DATATYPE)?.asString ?: ""
val comment = jsonObject.get(KEY_DATA_COMMENT)?.asString ?: ""

return VssSpecificationSpecModel(uuid, vssPath, description, type, comment, datatype)
return VssNodeSpecModel(uuid, vssPath, description, type, comment, datatype)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
package org.eclipse.kuksa.vssprocessor.parser.yaml

import org.eclipse.kuksa.vsscore.model.VssSpecification
import org.eclipse.kuksa.vssprocessor.parser.VssDefinitionParser
import org.eclipse.kuksa.vssprocessor.spec.VssSpecificationSpecModel
import org.eclipse.kuksa.vssprocessor.parser.VssParser
import org.eclipse.kuksa.vssprocessor.spec.VssNodeSpecModel
import java.io.File
import kotlin.reflect.KMutableProperty
import kotlin.reflect.KProperty
import kotlin.reflect.full.memberProperties

internal class YamlDefinitionParser(private val elementDelimiter: String = "") : VssDefinitionParser {
override fun parseSpecifications(definitionFile: File): List<VssSpecificationSpecModel> {
val specificationElements = mutableListOf<VssSpecificationSpecModel>()
internal class YamlVssParser(private val elementDelimiter: String = "") : VssParser {
override fun parseNodes(definitionFile: File): List<VssNodeSpecModel> {
val specificationElements = mutableListOf<VssNodeSpecModel>()
definitionFile.useLines { lines ->
val yamlAttributes = mutableListOf<String>()
for (line in lines.toList()) {
Expand Down Expand Up @@ -62,14 +62,14 @@ internal class YamlDefinitionParser(private val elementDelimiter: String = "") :
// description: Antilock Braking System signals.
// type: branch
// uuid: 219270ef27c4531f874bbda63743b330
private fun parseYamlElement(yamlElement: List<String>, delimiter: Char = ';'): VssSpecificationSpecModel? {
private fun parseYamlElement(yamlElement: List<String>, delimiter: Char = ';'): VssNodeSpecModel? {
val elementVssPath = yamlElement.first().substringBefore(":")

val yamlElementJoined = yamlElement
.joinToString(separator = delimiter.toString())
.substringAfter(delimiter) // Remove vssPath (already parsed)
.prependIndent(delimiter.toString()) // So the parsing is consistent for the first element
val members = VssSpecificationSpecModel::class.memberProperties
val members = VssNodeSpecModel::class.memberProperties
val fieldsToSet = mutableListOf<Pair<String, Any?>>()

// The VSSPath is an exception because it is parsed from the top level name.
Expand All @@ -90,7 +90,7 @@ internal class YamlDefinitionParser(private val elementDelimiter: String = "") :
fieldsToSet.add(fieldInfo)
}

val vssSpecificationMember = VssSpecificationSpecModel()
val vssSpecificationMember = VssNodeSpecModel()
vssSpecificationMember.setFields(fieldsToSet)

if (vssSpecificationMember.uuid.isEmpty()) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ import kotlin.reflect.full.declaredMemberProperties

// Reflects the specification file as a model and is filled via reflection. That is why the variable names
// should exactly match the names inside the specification file and be of a string type.
internal class VssSpecificationSpecModel(
internal class VssNodeSpecModel(
override var uuid: String = "",
override var vssPath: String = "",
override var description: String = "",
override var type: String = "",
override var comment: String = "",
@Suppress("MemberVisibilityCanBePrivate") var datatype: String = "",
) : VssSpecification, SpecModel<VssSpecificationSpecModel> {
) : VssSpecification, SpecModel<VssNodeSpecModel> {
var logger: KSPLogger? = null

private val datatypeProperty: TypeName
Expand Down Expand Up @@ -99,7 +99,7 @@ internal class VssSpecificationSpecModel(

override fun createClassSpec(
packageName: String,
relatedSpecifications: Collection<VssSpecificationSpecModel>,
relatedSpecifications: Collection<VssNodeSpecModel>,
nestedClasses: Collection<String>,
): TypeSpec {
val childSpecifications = relatedSpecifications.filter { it.parentKey == name }
Expand Down Expand Up @@ -210,7 +210,7 @@ internal class VssSpecificationSpecModel(
private fun createVssSpecificationSpecs(
className: String,
packageName: String,
specification: VssSpecificationSpecModel = this,
specification: VssNodeSpecModel = this,
): List<PropertySpec> {
val propertySpecs = mutableListOf<PropertySpec>()
val members = VssSpecification::class.declaredMemberProperties
Expand All @@ -232,7 +232,7 @@ internal class VssSpecificationSpecModel(
}

fun createObjectTypeSpec(
specification: VssSpecificationSpecModel,
specification: VssNodeSpecModel,
packageName: String,
): PropertySpec {
val prefixedTypeName = ClassName(packageName, specification.className)
Expand All @@ -259,7 +259,7 @@ internal class VssSpecificationSpecModel(
return listOf(objectTypeSpec)
}

private fun createVssNodeSpecs(childSpecifications: List<VssSpecificationSpecModel>): List<PropertySpec> {
private fun createVssNodeSpecs(childSpecifications: List<VssNodeSpecModel>): List<PropertySpec> {
fun createSetSpec(memberName: String, memberType: TypeName): PropertySpec {
val specificationNamesJoined = childSpecifications.joinToString(", ") { it.variableName }

Expand Down Expand Up @@ -311,7 +311,7 @@ internal class VssSpecificationSpecModel(
}

override fun equals(other: Any?): Boolean {
if (other !is VssSpecificationSpecModel) return false
if (other !is VssNodeSpecModel) return false

return uuid == other.uuid
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ package org.eclipse.kuksa.vssprocessor.parser.factory
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.instanceOf
import org.eclipse.kuksa.vssprocessor.parser.json.JsonDefinitionParser
import org.eclipse.kuksa.vssprocessor.parser.yaml.YamlDefinitionParser
import org.eclipse.kuksa.vssprocessor.parser.json.JsonVssParser
import org.eclipse.kuksa.vssprocessor.parser.yaml.YamlVssParser
import java.io.File

class VssDefinitionParserFactoryTest : BehaviorSpec({
class VssParserFactoryTest : BehaviorSpec({

given("An instance of DefinitionParserFactory") {
val classUnderTest = VssDefinitionParserFactory()
val classUnderTest = VssParserFactory()

`when`("Calling create with supported extension 'json'") {
val vssDefinitionParser = classUnderTest.create("json")

then("It should return a JsonDefinitionParser") {
vssDefinitionParser shouldBe instanceOf(JsonDefinitionParser::class)
vssDefinitionParser shouldBe instanceOf(JsonVssParser::class)
}
}

`when`("Calling create with supported extension 'yaml'") {
val vssDefinitionParser = classUnderTest.create("yaml")

then("It should return a YamlDefinitionParser") {
vssDefinitionParser shouldBe instanceOf(YamlDefinitionParser::class)
vssDefinitionParser shouldBe instanceOf(YamlVssParser::class)
}
}

`when`("Calling create with supported extension 'yml'") {
val vssDefinitionParser = classUnderTest.create("yml")

then("It should return a YamlDefinitionParser") {
vssDefinitionParser shouldBe instanceOf(YamlDefinitionParser::class)
vssDefinitionParser shouldBe instanceOf(YamlVssParser::class)
}
}

Expand All @@ -60,7 +60,7 @@ class VssDefinitionParserFactoryTest : BehaviorSpec({
val vssDefinitionParser = classUnderTest.create(supportedFile)

then("It should correctly extract the extension and return the corresponding VssDefinitionParser") {
vssDefinitionParser shouldBe instanceOf(JsonDefinitionParser::class)
vssDefinitionParser shouldBe instanceOf(JsonVssParser::class)
}
}

Expand Down
Loading

0 comments on commit adb2002

Please sign in to comment.