-
Notifications
You must be signed in to change notification settings - Fork 2
Fix filtering #173
base: master
Are you sure you want to change the base?
Fix filtering #173
Changes from 21 commits
5eae93f
d140c06
91a084b
368b73e
436df68
e7bea69
162cc35
068c938
5204e0c
4bcdce0
162142f
1dd7385
186e1c2
0fcecf9
368ae6e
1c32f45
454ca48
6d69dbc
5ddd630
2793061
dffa31e
8cf7162
0742a7e
2370ae3
484e0d3
8747165
09ccc19
b006441
44c297d
54bcd5a
9a3158e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright 2023, TeamDev. All rights reserved. | ||
| * | ||
| * 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 | ||
| * | ||
| * Redistribution and use in source and/or binary forms, with or without | ||
| * modification, must retain the above copyright notice and the following | ||
| * disclaimer. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package io.spine.protodata.renderer | ||
|
|
||
| import io.spine.tools.code.Language | ||
|
|
||
| /** | ||
| * A label for a source file set. | ||
| * | ||
| * The label marks the programming language that the files use and the name of the generator that | ||
| * created the files. | ||
| */ | ||
| public data class SourceFileSetLabel( | ||
| public val language: Language, | ||
| public val generator: SourceGeneratorName = DefaultGenerator | ||
| ) { | ||
|
|
||
| /** | ||
| * Creates a new `SourceFileSetLabel` with the given language and a custom generator name. | ||
| */ | ||
| public constructor(language: Language, generatorName: String) | ||
| : this(language, CustomGenerator(generatorName)) | ||
|
|
||
| override fun toString(): String = | ||
| "${language.name}(${generator.name})" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright 2023, TeamDev. All rights reserved. | ||
| * | ||
| * 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 | ||
| * | ||
| * Redistribution and use in source and/or binary forms, with or without | ||
| * modification, must retain the above copyright notice and the following | ||
| * disclaimer. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package io.spine.protodata.renderer | ||
|
|
||
| /** | ||
| * A name of a source code generator. | ||
| * | ||
| * This can be a `protoc` plugin or builtin, or a custom code generator tool. | ||
| */ | ||
| public sealed interface SourceGeneratorName { | ||
|
|
||
| public val name: String | ||
| get() = javaClass.simpleName.lowercase() | ||
| } | ||
|
|
||
| /** | ||
| * The default generator is the default way for the Protobuf compiler to generate source code for | ||
| * a given language. | ||
| * | ||
| * For example, in Java, the default generator, given a message `Foo`, would generate a message | ||
| * classes and auxiliary types, such as classes `Foo`, `Foo.Builder`, `Foo.Parser`, | ||
| * and the interface `FooOrBuilder`. | ||
| * | ||
| * Since the Protobuf compiler does not support all the existing programming languages, | ||
| * the `DefaultGenerator` is only defined for those languages that are supported, such as Java, JS, | ||
| * C++, etc. For other languages, as well as for other code generation scenarios, | ||
| * see [CustomGenerator]. | ||
| */ | ||
| public object DefaultGenerator : SourceGeneratorName | ||
|
|
||
| /** | ||
| * A name of a custom source code generator. | ||
| * | ||
| * May represent a Protobuf compiler plugin, or any other code generator. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something strange. "Generator" in all cases is the thing producing the code. Why would we need a "default" and "custom" generators? They both generate something, and why would we care about their origin? And again, in this piece of documentation, you mention "labels". Which still does not add up: "generator"s, source set labels and "language" all dance around :(
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Default" simply references the case most users will likely face most of the time. And it is the default way in which Protoc generated code, as opposed to custom generators/Protoc plugins. I've cleared up the doc's wording a bit so that there is no confusion with the labels. |
||
| * | ||
| * Conventionally, the name of the generator should coincide with the name of the directory where | ||
| * the generated files are placed. Users should follow this convention where possible, yet diverge | ||
| * when necessary. For example, Java gRPC stubs should be labelled with the `grpc` name. However, | ||
| * files generated for Dart should be labelled with the name `dart`, not `lib`. | ||
| */ | ||
| public class CustomGenerator( | ||
| override val name: String | ||
| ) : SourceGeneratorName | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the usage example (the one from the PR description) it is not clear how labels relate to
languageandgeneratorName. More than that, with this description, it is now more confusing.I would use the same terms both in CLI, Gradle DSL, and in the code.