Skip to content

Commit

Permalink
chore: Introduce VssNodePropertiesBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
wba2hi committed Mar 22, 2024
1 parent dd6fe35 commit a02f9e6
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ import org.eclipse.kuksa.vssprocessor.parser.ROOT_KEY_VEHICLE
import org.eclipse.kuksa.vssprocessor.parser.VSS_DATA_KEYS
import org.eclipse.kuksa.vssprocessor.parser.VssParser
import org.eclipse.kuksa.vssprocessor.spec.VssDataType
import org.eclipse.kuksa.vssprocessor.spec.VssNodeProperty
import org.eclipse.kuksa.vssprocessor.spec.VssNodePropertiesBuilder
import org.eclipse.kuksa.vssprocessor.spec.VssNodeSpecModel
import org.eclipse.kuksa.vssprocessor.spec.VssSignalProperty
import java.io.File
import java.io.IOException

Expand Down Expand Up @@ -111,16 +110,14 @@ internal class JsonVssParser : VssParser {
val vssDataType = VssDataType.find(datatype)
val valueDataType = vssDataType.valueDataType

val vssNodeProperties = mutableSetOf(
VssNodeProperty(vssPath, KEY_DATA_UUID, uuid, String::class),
VssNodeProperty(vssPath, KEY_DATA_TYPE, type, String::class),
VssNodeProperty(vssPath, KEY_DATA_DESCRIPTION, description, String::class),
VssNodeProperty(vssPath, KEY_DATA_COMMENT, comment, String::class),
VssSignalProperty(vssPath, KEY_DATA_DATATYPE, datatype, valueDataType),
VssSignalProperty(vssPath, KEY_DATA_UNIT, unit, String::class),
VssSignalProperty(vssPath, KEY_DATA_MIN, min, valueDataType),
VssSignalProperty(vssPath, KEY_DATA_MAX, max, valueDataType),
)
val vssNodeProperties = VssNodePropertiesBuilder(uuid, type)
.withDescription(description)
.withComment(comment)
.withDataType(datatype)
.withUnit(unit)
.withMin(min, valueDataType)
.withMax(max, valueDataType)
.build()

return VssNodeSpecModel(vssPath, vssNodeProperties)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_UNIT
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_UUID
import org.eclipse.kuksa.vssprocessor.parser.VssParser
import org.eclipse.kuksa.vssprocessor.spec.VssDataType
import org.eclipse.kuksa.vssprocessor.spec.VssNodeProperty
import org.eclipse.kuksa.vssprocessor.spec.VssNodePropertiesBuilder
import org.eclipse.kuksa.vssprocessor.spec.VssNodeSpecModel
import org.eclipse.kuksa.vssprocessor.spec.VssSignalProperty
import java.io.File
import java.io.IOException

Expand Down Expand Up @@ -102,16 +101,14 @@ internal class YamlVssParser(private val elementDelimiter: String = "") : VssPar
val vssDataType = VssDataType.find(datatype)
val valueDataType = vssDataType.valueDataType

val vssNodeProperties = mutableSetOf(
VssNodeProperty(vssPath, KEY_DATA_UUID, uuid, String::class),
VssNodeProperty(vssPath, KEY_DATA_TYPE, type, String::class),
VssNodeProperty(vssPath, KEY_DATA_DESCRIPTION, description, String::class),
VssNodeProperty(vssPath, KEY_DATA_COMMENT, comment, String::class),
VssSignalProperty(vssPath, KEY_DATA_DATATYPE, datatype, valueDataType),
VssSignalProperty(vssPath, KEY_DATA_UNIT, unit, String::class),
VssSignalProperty(vssPath, KEY_DATA_MIN, min, valueDataType),
VssSignalProperty(vssPath, KEY_DATA_MAX, max, valueDataType),
)
val vssNodeProperties = VssNodePropertiesBuilder(uuid, type)
.withDescription(description)
.withComment(comment)
.withDataType(datatype)
.withUnit(unit)
.withMin(min, valueDataType)
.withMax(max, valueDataType)
.build()

return VssNodeSpecModel(vssPath, vssNodeProperties)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright (c) 2023 - 2024 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.vssprocessor.spec

import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_COMMENT
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_DATATYPE
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_DESCRIPTION
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_MAX
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_MIN
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_TYPE
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_UNIT
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_UUID
import kotlin.reflect.KClass

internal class VssNodePropertiesBuilder(
uuid: String,
type: String,
) {
private val nodePropertyMap: MutableMap<String, VssNodeProperty> = mutableMapOf()

init {
val uuidNodeProperty = VssNodeProperty(KEY_DATA_UUID, uuid, String::class)
nodePropertyMap[KEY_DATA_UUID] = uuidNodeProperty

val typeNodeProperty = VssNodeProperty(KEY_DATA_TYPE, type, String::class)
nodePropertyMap[KEY_DATA_TYPE] = typeNodeProperty
}

fun withDescription(description: String?): VssNodePropertiesBuilder {
if (description == null) return this

val nodeProperty = VssNodeProperty(KEY_DATA_DESCRIPTION, description, String::class)
nodePropertyMap[KEY_DATA_DESCRIPTION] = nodeProperty

return this
}

fun withComment(comment: String?): VssNodePropertiesBuilder {
if (comment == null) return this

val nodeProperty = VssNodeProperty(KEY_DATA_COMMENT, comment, String::class)
nodePropertyMap[KEY_DATA_COMMENT] = nodeProperty

return this
}

fun withDataType(dataType: String?): VssNodePropertiesBuilder {
if (dataType == null) return this

val vssDataType = VssDataType.find(dataType)
val valueDataType = vssDataType.valueDataType

val signalProperty = VssSignalProperty(KEY_DATA_DATATYPE, dataType, valueDataType)
nodePropertyMap[KEY_DATA_DATATYPE] = signalProperty

return this
}

fun withUnit(unit: String?): VssNodePropertiesBuilder {
if (unit == null) return this

val signalProperty = VssSignalProperty(KEY_DATA_UNIT, unit, String::class)
nodePropertyMap[KEY_DATA_UNIT] = signalProperty

return this
}

fun withMin(min: String?, clazz: KClass<*>): VssNodePropertiesBuilder {
if (min == null) return this

val signalProperty = VssSignalProperty(KEY_DATA_MIN, min, clazz)
nodePropertyMap[KEY_DATA_MIN] = signalProperty

return this
}

fun withMin(min: String?, dataType: String): VssNodePropertiesBuilder {
if (min == null) return this

val vssDataType = VssDataType.find(dataType)
val valueDataType = vssDataType.valueDataType

return withMin(min, valueDataType)
}

fun withMax(max: String?, clazz: KClass<*>): VssNodePropertiesBuilder {
if (max == null) return this

val maxSignalProperty = VssSignalProperty(KEY_DATA_MAX, max, clazz)
nodePropertyMap[KEY_DATA_MAX] = maxSignalProperty

return this
}

fun withMax(max: String?, dataType: String): VssNodePropertiesBuilder {
if (max == null) return this

val vssDataType = VssDataType.find(dataType)
val valueDataType = vssDataType.valueDataType

return withMax(max, valueDataType)
}

fun build(): Set<VssNodeProperty> {
return nodePropertyMap.values.toSet()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ package org.eclipse.kuksa.vssprocessor.spec

import kotlin.reflect.KClass

open class VssNodeProperty(
val vssPath: String,
internal open class VssNodeProperty(
val nodePropertyName: String,
val nodePropertyValue: String,
val dataType: KClass<*>,
Expand All @@ -43,11 +42,10 @@ open class VssNodeProperty(
}
}

class VssSignalProperty(
vssPath: String,
internal class VssSignalProperty(
nodePropertyName: String,
nodePropertyValue: String,
dataType: KClass<*>,
) : VssNodeProperty(vssPath, nodePropertyName, nodePropertyValue, dataType) {
) : VssNodeProperty(nodePropertyName, nodePropertyValue, dataType) {
override val isCommon: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import org.eclipse.kuksa.vsscore.model.name
import org.eclipse.kuksa.vsscore.model.parentClassName
import org.eclipse.kuksa.vsscore.model.parentKey
import org.eclipse.kuksa.vsscore.model.variableName
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_COMMENT
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_DATATYPE
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_DESCRIPTION
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_TYPE
import org.eclipse.kuksa.vssprocessor.parser.KEY_DATA_UUID
import org.eclipse.kuksa.vssprocessor.spec.VssNodeProperty.*
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
Expand All @@ -54,11 +59,11 @@ internal class VssNodeSpecModel(

private val propertyNameToNodePropertyMap = vssNodeProperties.associateBy { it.nodePropertyName }

override var uuid: String = propertyNameToNodePropertyMap["uuid"]?.nodePropertyValue ?: ""
override var type: String = propertyNameToNodePropertyMap["type"]?.nodePropertyValue ?: ""
override var description: String = propertyNameToNodePropertyMap["description"]?.nodePropertyValue ?: ""
override var comment: String = propertyNameToNodePropertyMap["comment"]?.nodePropertyValue ?: ""
var datatype: String = propertyNameToNodePropertyMap["datatype"]?.nodePropertyValue ?: ""
override var uuid: String = propertyNameToNodePropertyMap[KEY_DATA_UUID]?.nodePropertyValue ?: ""
override var type: String = propertyNameToNodePropertyMap[KEY_DATA_TYPE]?.nodePropertyValue ?: ""
override var description: String = propertyNameToNodePropertyMap[KEY_DATA_DESCRIPTION]?.nodePropertyValue ?: ""
override var comment: String = propertyNameToNodePropertyMap[KEY_DATA_COMMENT]?.nodePropertyValue ?: ""
var datatype: String = propertyNameToNodePropertyMap[KEY_DATA_DATATYPE]?.nodePropertyValue ?: ""

var logger: KSPLogger? = null

Expand Down
Loading

0 comments on commit a02f9e6

Please sign in to comment.