-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit events for all known types #127
Changes from 19 commits
fdc909b
a4f32df
1534077
77a711d
c551eb9
643ad58
b5963fd
f8ca578
9811ba2
a412d59
ea7025a
47884bb
b363bf2
7a0617e
85c211e
b105840
e078f86
281d9b1
2527f70
040fb73
ee687ae
d6d2708
f4c7a76
83f51c7
5de89bc
514ce41
e88a6bd
342ecc2
37ad5f3
1a25dbd
5ebf770
6dddbbe
796127d
51ed614
07dea0f
c477f1b
c8b2a60
0fa23c7
d6133ec
af59295
cd18964
113e558
518c8b2
8e207c1
5a11ddd
ff3ab1e
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ jobs: | |
run: ./gradlew build --stacktrace | ||
|
||
# See: https://github.com/marketplace/actions/junit-report-action | ||
- name: Publish Unit Test Report | ||
- name: Publish Test Report | ||
uses: mikepenz/[email protected] | ||
if: always() # always run even if the previous step fails | ||
with: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ import "spine/protodata/ast.proto"; | |
// Includes all the message types declared in the file, along with their fields. | ||
// | ||
message ProtobufSourceFile { | ||
option (entity).kind = PROJECTION; | ||
option (entity).kind = VIEW; | ||
|
||
FilePath file_path = 1; | ||
alexander-yevsyukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -70,3 +70,16 @@ message ProtobufSourceFile { | |
// | ||
map<string, Service> service = 5; | ||
} | ||
|
||
// A Protobuf definitions file which is included into the module as a dependency. | ||
// | ||
// Unlike `ProtobufSourceFile`, `ProtobufDependencyFile` should not result in any code generation. | ||
// Rather, it serves an informative purpose. | ||
// | ||
message ProtobufDependencyFile { | ||
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. I think the suffix |
||
option (entity).kind = VIEW; | ||
|
||
FilePath file_path = 1; | ||
|
||
ProtobufSourceFile content = 2; | ||
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. Can we have it named as |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/* | ||
* 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.backend | ||
|
||
import com.google.protobuf.Descriptors | ||
import com.google.protobuf.Empty | ||
import io.spine.protodata.EnumConstant | ||
import io.spine.protodata.Field | ||
import io.spine.protodata.Rpc | ||
import io.spine.protodata.ServiceName | ||
import io.spine.protodata.TypeName | ||
import io.spine.protodata.cardinality | ||
import io.spine.protodata.constantName | ||
import io.spine.protodata.file | ||
import io.spine.protodata.name | ||
import io.spine.protodata.path | ||
|
||
/** | ||
* Converts this field descriptor into a [Field] with options. | ||
* | ||
* @see buildField | ||
*/ | ||
internal fun Descriptors.FieldDescriptor.buildFieldWithOptions( | ||
declaringType: TypeName, | ||
documentation: Documentation | ||
): Field { | ||
val field = buildField(declaringType, documentation) | ||
return field.toBuilder() | ||
.addAllOption(listOptions(options)) | ||
.build() | ||
} | ||
|
||
/** | ||
* Converts this field descriptor into a [Field]. | ||
* | ||
* The resulting [Field] will not reflect the field options. | ||
* | ||
* @see buildFieldWithOptions | ||
*/ | ||
internal fun Descriptors.FieldDescriptor.buildField( | ||
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. Please import |
||
declaringType: TypeName, | ||
documentation: Documentation | ||
): Field { | ||
return Field.newBuilder() | ||
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. Can we use Proto DSL here, please? 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. In methods that already have a receiver, I found it easier to use the builder rather than the DSL. Otherwise, we'd have to specify which this@field.number = this@buildField.number It's similar in other places in 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. We do have name clashes in some cases, but they are rare. I've changed several such blocks myself and know what you're talking about. Try to apply the DSL to this particular case and you'll see that the code becomes much more compact and easier to read. |
||
.setName(name()) | ||
.setDeclaringType(declaringType) | ||
.setNumber(number) | ||
.setOrderOfDeclaration(index) | ||
.assignTypeAndCardinality(this) | ||
.setDoc(documentation.forField(this)) | ||
.build() | ||
} | ||
|
||
/** | ||
* Assigns the field type and cardinality (`map`/`list`/`oneof_name`/`single`) to the receiver | ||
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. Is this, in fact, copying the field type and the cardinality? If so, maybe we could get rid of this "assign" term which feels a bit over-used in our domain? |
||
* builder. | ||
* | ||
* @return the receiver for method chaining. | ||
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. I think, in Kotlin we still don't put periods in |
||
*/ | ||
private fun Field.Builder.assignTypeAndCardinality( | ||
desc: Descriptors.FieldDescriptor | ||
): Field.Builder { | ||
if (desc.isMapField) { | ||
val (keyField, valueField) = desc.messageType.fields | ||
map = Field.OfMap.newBuilder() | ||
.setKeyType(keyField.primitiveType()) | ||
.build() | ||
type = valueField.type() | ||
} else { | ||
type = desc.type() | ||
when { | ||
desc.isRepeated -> list = Empty.getDefaultInstance() | ||
desc.realContainingOneof != null -> oneofName = desc.realContainingOneof.name() | ||
else -> single = Empty.getDefaultInstance() | ||
} | ||
} | ||
return this | ||
} | ||
|
||
/** | ||
* Converts this enum value descriptor into an [EnumConstant] with options. | ||
* | ||
* @see buildConstant | ||
*/ | ||
internal fun Descriptors.EnumValueDescriptor.buildConstantWithOptions( | ||
declaringType: TypeName, | ||
documentation: Documentation | ||
): EnumConstant { | ||
val constant = buildConstant(declaringType, documentation) | ||
return constant.toBuilder() | ||
.addAllOption(listOptions(options)) | ||
.build() | ||
} | ||
|
||
/** | ||
* Converts this enum value descriptor into an [EnumConstant]. | ||
* | ||
* The resulting [EnumConstant] will not reflect the options on the enum constant. | ||
* | ||
* @see buildConstantWithOptions | ||
*/ | ||
internal fun Descriptors.EnumValueDescriptor.buildConstant( | ||
declaringType: TypeName, | ||
documentation: Documentation | ||
): EnumConstant { | ||
return EnumConstant.newBuilder() | ||
.setName(constantName { value = name }) | ||
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. Please use Kotlin proto DSL here. |
||
.setDeclaredIn(declaringType) | ||
.setNumber(number) | ||
.setOrderOfDeclaration(index) | ||
.setDoc(documentation.forEnumConstant(this)) | ||
.build() | ||
} | ||
|
||
/** | ||
* Converts this method descriptor into an [Rpc] with options. | ||
* | ||
* @see buildRpc | ||
*/ | ||
internal fun Descriptors.MethodDescriptor.buildRpcWithOptions( | ||
declaringService: ServiceName, | ||
documentation: Documentation | ||
) : Rpc { | ||
return buildRpc(declaringService, documentation) | ||
.toBuilder() | ||
.addAllOption(listOptions(options)) | ||
.build() | ||
} | ||
|
||
/** | ||
* Converts this method descriptor into an [Rpc]. | ||
* | ||
* The resulting [Rpc] will not reflect the method options. | ||
* | ||
* @see buildRpcWithOptions | ||
*/ | ||
internal fun Descriptors.MethodDescriptor.buildRpc( | ||
declaringService: ServiceName, | ||
documentation: Documentation | ||
) : Rpc { | ||
val name = name() | ||
val cardinality = cardinality() | ||
return Rpc.newBuilder() | ||
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. Please use Kotlin proto DSL here. |
||
.setName(name) | ||
.setCardinality(cardinality) | ||
.setRequestType(inputType.name()) | ||
.setResponseType(outputType.name()) | ||
.setDoc(documentation.forRpc(this)) | ||
.setService(declaringService) | ||
.build() | ||
} | ||
|
||
/** | ||
* Extracts metadata from this file descriptor, including file options. | ||
* | ||
* @see toFile | ||
*/ | ||
internal fun Descriptors.FileDescriptor.toFileWithOptions() = | ||
toFile() | ||
.toBuilder() | ||
.addAllOption(listOptions(options)) | ||
.build() | ||
|
||
/** | ||
* Extracts metadata from this file descriptor, excluding file options. | ||
* | ||
* @see toFileWithOptions | ||
*/ | ||
internal fun Descriptors.FileDescriptor.toFile() = file { | ||
path = path() | ||
packageName = `package` | ||
syntax = [email protected]() | ||
} | ||
|
||
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. I am not sure whether we can remove this empty line (and not break EOF), but if we can, let's. |
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.
I would be more precise with this name, so that Java- and Proto-level dependencies could be distinguished.
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.
I've updated the doc somewhat. I'd like to avoid adding the
Proto
prefix because:TypeEntered
,OptionDiscovered
, etc., which do not specify the language either.