Skip to content

Commit

Permalink
Add LIME IDL support for "validator" keyword
Browse files Browse the repository at this point in the history
Updated LIME IDL grammar and model builder to add support for `validator` keyword in classes.

See: #637
Signed-off-by: Daniel Kamkha <[email protected]>
  • Loading branch information
DanielKamkha committed Dec 8, 2020
1 parent e14065d commit c250a4d
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 4 deletions.
14 changes: 14 additions & 0 deletions docs/lime_idl.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,20 @@ attributes (or omitted if the name is the name of the type in IDL declaration).
type which is generated when a converter is specified has an additional `_internal` suffix to its
name in Swift and Dart.

#### Validator

* Syntax: **validator** *ValidatorName* **()**
* Example: `validator checkState()`
* Can be placed in: class. If present, it must be:
* The first child element, if no external descriptor is present.
* The second child element, if an external descriptor is present.
* Description: enables state validation and specifies the name for the validator function. For C++ a pure virtual const
function with *ValidatorName* name is generated, that takes no parameters and returns an `optional<std::string>`. For
Java/Swift/Dart a private function with *ValidatorName* name is generated, that takes no parameters and returns no
value. This private function is called before each other non-static function (method or property accessor) call is
executed. If the C++ function returns a non-empty optional, the Java/Swift/Dart function throws an unchecked exception
with the returned string value as a message. If the returned optional value is empty, no exception is thrown.

### Type references

A type reference is a mention of a type anywhere, as opposed to a type declaration. A type reference
Expand Down
33 changes: 33 additions & 0 deletions examples/libhello/lime/test/Validator.lime
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2016-2020 HERE Europe B.V.
#
# 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
# License-Filename: LICENSE

package test

class ValidatedClass {
validator checkMe()
constructor makeMe()

fun doStuff()
static fun doStaticStuff()

property something: String
static property somethingStatic: String
}

class ValidationController {
static fun setFailState(state: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
{{>lime/LimeDocumentation}}
{{visibility}}class {{escapedName}} {{#parent}}: {{type.name}} {{/parent}}{
{{prefixPartial "lime/LimeExternalDescriptor" " "}}
{{#if validatorName}} validator {{validatorName}}(){{/if}}
{{>lime/LimeContainerContents}}
}
1 change: 0 additions & 1 deletion gluecodium/src/test/java/com/here/gluecodium/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

@RunWith(Parameterized::class)

class SmokeTest(
private val featureDirectory: File,
generatorName: String,
Expand Down
29 changes: 29 additions & 0 deletions gluecodium/src/test/resources/smoke/validator/input/Validator.lime
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2016-2020 HERE Europe B.V.
#
# 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
# License-Filename: LICENSE

package smoke

class ValidatedClass {
validator checkMe()
constructor makeMe()

fun doStuff()
static fun doStaticStuff()

property something: String
static property somethingStatic: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package smoke
class ValidatedClass {
validator checkMe()
constructor makeMe()
fun doStuff()
static fun doStaticStuff()
property something: String
static property somethingStatic: String
}
1 change: 1 addition & 0 deletions lime-loader/src/main/antlr/LimeLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Struct: 'struct' ;
Throws: 'throws' ;
TypeAlias: 'typealias' ;
Types: 'types' ;
Validator: 'validator' ;

// Predefined types

Expand Down
6 changes: 5 additions & 1 deletion lime-loader/src/main/antlr/LimeParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ importStatement

container
: docComment* annotation* visibility? ('class' | 'interface') NewLine* simpleId NewLine*
(':' NewLine* identifier NewLine*)? '{' NewLine* externalDescriptor?
(':' NewLine* identifier NewLine*)? '{' NewLine* externalDescriptor? validator?
((function | constructor | property | struct | enumeration | constant | typealias |
exception | lambda | container) NewLine*)* '}' NewLine+
;
Expand Down Expand Up @@ -73,6 +73,10 @@ throwsClause
: 'throws' NewLine* docComment* typeRef NewLine*
;

validator
: 'validator' NewLine* simpleId NewLine* '(' NewLine* ')' NewLine*
;

property
: docComment* annotation* visibility? ('static' NewLine*)? 'property' NewLine* simpleId NewLine*
':' NewLine* typeRef NewLine* ('{' NewLine* getter (setter)? '}' )? NewLine+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ internal class AntlrLimeModelBuilder(
exceptions = getPreviousResults(LimeException::class.java),
classes = getPreviousResults(LimeClass::class.java),
interfaces = getPreviousResults(LimeInterface::class.java),
lambdas = getPreviousResults(LimeLambda::class.java)
lambdas = getPreviousResults(LimeLambda::class.java),
validatorName = ctx.validator()?.simpleId()?.text
)
} else {
LimeInterface(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ internal abstract class AntlrLimeModelBuilderBase(

override fun exitExternalDescriptorValue(ctx: LimeParser.ExternalDescriptorValueContext?) {}

override fun enterValidator(ctx: LimeParser.ValidatorContext?) {}

override fun exitValidator(ctx: LimeParser.ValidatorContext?) {}

override fun visitTerminal(node: TerminalNode) {}

override fun visitErrorNode(node: ErrorNode) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.here.gluecodium.model.lime

import java.security.cert.CertPathValidator

class LimeClass(
path: LimePath,
visibility: LimeVisibility = LimeVisibility.PUBLIC,
Expand All @@ -35,7 +37,8 @@ class LimeClass(
classes: List<LimeClass> = emptyList(),
interfaces: List<LimeInterface> = emptyList(),
lambdas: List<LimeLambda> = emptyList(),
parent: LimeTypeRef? = null
parent: LimeTypeRef? = null,
val validatorName: String? = null
) : LimeContainerWithInheritance(
path = path,
visibility = visibility,
Expand Down
Binary file modified tools/Lime_IDL_file_type_for_IntelliJ.jar
Binary file not shown.

0 comments on commit c250a4d

Please sign in to comment.