Skip to content
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

Merged
merged 46 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fdc909b
Emit events about all types
dmdashenkov Mar 16, 2023
a4f32df
Add a test for non-request files
dmdashenkov Mar 16, 2023
1534077
Bump version
dmdashenkov Mar 17, 2023
77a711d
Add doc
dmdashenkov Mar 17, 2023
c551eb9
Add definitions for a dependency-based view
dmdashenkov Mar 17, 2023
643ad58
Implement a view collecting dependency file data
dmdashenkov Mar 17, 2023
b5963fd
Move some implementation details to `:compiler`
dmdashenkov Mar 20, 2023
f8ca578
Emit events for dependencies
dmdashenkov Mar 22, 2023
9811ba2
More testing
dmdashenkov Mar 22, 2023
a412d59
Add file path in services and remove the `shouldGenerate` flag
dmdashenkov Mar 22, 2023
ea7025a
Split new model-building code into a separate file
dmdashenkov Mar 22, 2023
47884bb
Assemble separate functions into a context-class
dmdashenkov Mar 24, 2023
b363bf2
Add missing type details
dmdashenkov Mar 24, 2023
7a0617e
Add a test for ensuring event-based and procedure-based model builder…
dmdashenkov Mar 24, 2023
85c211e
Clean up Proto definition
dmdashenkov Mar 24, 2023
b105840
Fix imports
dmdashenkov Mar 24, 2023
e078f86
More doc
dmdashenkov Mar 24, 2023
281d9b1
Revert changes from `config`
dmdashenkov Mar 27, 2023
2527f70
More details on the new compiler event
dmdashenkov Mar 27, 2023
040fb73
Better naming
dmdashenkov Mar 27, 2023
ee687ae
Style fixes
dmdashenkov Mar 27, 2023
d6d2708
Make a destructing call more obvious
dmdashenkov Mar 27, 2023
f4c7a76
Fix a typo
dmdashenkov Mar 27, 2023
83f51c7
Improve naming and add static imports
dmdashenkov Mar 27, 2023
5de89bc
More static imports
dmdashenkov Mar 27, 2023
514ce41
Yet more static imports
dmdashenkov Mar 27, 2023
e88a6bd
Yet more static imports
dmdashenkov Mar 27, 2023
342ecc2
Use Kotlin DSL for Proto messages where possible
dmdashenkov Mar 27, 2023
37ad5f3
Revert `config` changes
dmdashenkov Mar 27, 2023
1a25dbd
Kotlinize message building
dmdashenkov Mar 28, 2023
5ebf770
Use Kotest asasertions
dmdashenkov Mar 28, 2023
6dddbbe
Better naming for the new view
dmdashenkov Mar 28, 2023
796127d
Extract common functionality
dmdashenkov Mar 28, 2023
51ed614
Simplify proto definition construction
dmdashenkov Mar 28, 2023
07dea0f
Improve readability
dmdashenkov Mar 28, 2023
c477f1b
Fix type nullability
dmdashenkov Mar 30, 2023
c8b2a60
Refactor functions to avoid `this@smth`-s
dmdashenkov Mar 30, 2023
0fa23c7
Extract duplicates
dmdashenkov Mar 30, 2023
d6133ec
Repackage event factories
dmdashenkov Mar 30, 2023
af59295
Fix typo
dmdashenkov Mar 30, 2023
cd18964
Add doc
dmdashenkov Mar 30, 2023
113e558
Fix typo
dmdashenkov Mar 30, 2023
518c8b2
Clear up imports and use Kotest where possible
dmdashenkov Mar 30, 2023
8e207c1
Remove redundant `Companion` specifier
dmdashenkov Mar 30, 2023
5a11ddd
Add static imports
dmdashenkov Mar 30, 2023
ff3ab1e
Use `val` instead of `fun`
dmdashenkov Mar 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 4 additions & 52 deletions api/src/main/kotlin/io/spine/protodata/AstExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,10 @@ import io.spine.protodata.CallCardinality.UNARY
*/
public fun MessageType.qualifiedName(): String = name.qualifiedName()

/**
* Obtains the type URl of the type.
*
* A type URL contains the type URL prefix and the qualified name of the type separated by
* the slash (`/`) symbol. See the docs of `google.protobuf.Any.type_url` for more info.
*
* @see MessageType.qualifiedName
* @see TypeName.typeUrl
*/
public fun MessageType.typeUrl(): String = name.typeUrl()

/**
* Obtains the type URl of the type.
*
* A type URL contains the type URL prefix and the qualified name of the type separated by
* the slash (`/`) symbol. See the docs of `google.protobuf.Any.type_url` for more info.
*
* @see MessageType.qualifiedName
* @see TypeName.typeUrl
*/
public fun EnumType.typeUrl(): String = name.typeUrl()

/**
* Obtains the fully qualified name from this `TypeName`.
*/
public fun TypeName.qualifiedName(): String {
public fun TypeNameOrBuilder.qualifiedName(): String {
val names = buildList<String> {
add(packageName)
addAll(nestingTypeNameList)
Expand All @@ -83,32 +61,6 @@ public fun TypeName.qualifiedName(): String {
return names.filter { it.isNotEmpty() }.joinToString(separator = ".")
}

/**
* Obtains the type URL from this `TypeName`.
*
* A type URL contains the type URL prefix and the qualified name of the type separated by
* the slash (`/`) symbol. See the docs of `google.protobuf.Any.type_url` for more info.
*
* @see TypeName.qualifiedName
* @see MessageType.typeUrl
*/
public fun TypeName.typeUrl(): String = "${typeUrlPrefix}/${qualifiedName()}"

/**
* Obtains the type URl from this `ServiceName`.
*
* A type URL contains the type URL prefix and the qualified name of the type separated by
* the slash (`/`) symbol. See the docs of `google.protobuf.Any.type_url` for more info.
*/
public fun ServiceName.typeUrl(): String = "$typeUrlPrefix/$packageName.$simpleName"

/**
* Obtains the type URl of this service.
*
* @see ServiceName.typeUrl
*/
public fun Service.typeUrl(): String = name.typeUrl()

/**
* Shows if this field is a `map`.
*
Expand Down Expand Up @@ -195,12 +147,12 @@ private val FileDescriptor.typeUrlPrefix: String
/**
* Obtains the name of this `oneof` as a [OneofName].
*/
internal fun OneofDescriptor.name(): OneofName = oneofName { value = name }
public fun OneofDescriptor.name(): OneofName = oneofName { value = name }

/**
* Obtains the name of this field as a [FieldName].
*/
internal fun FieldDescriptor.name(): FieldName = fieldName { value = name }
public fun FieldDescriptor.name(): FieldName = fieldName { value = name }

/**
* Obtains the relative path to this file as a [FilePath].
Expand All @@ -219,7 +171,7 @@ public fun ServiceDescriptor.name(): ServiceName = serviceName {
/**
* Obtains the name of this RPC method as an [RpcName].
*/
internal fun MethodDescriptor.name(): RpcName = rpcName { value = name }
public fun MethodDescriptor.name(): RpcName = rpcName { value = name }

/**
* Obtains a [Type] wrapping this `PrimitiveType`.
Expand Down
53 changes: 53 additions & 0 deletions api/src/main/kotlin/io/spine/protodata/ProtoDeclaration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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

import com.google.protobuf.Message
import io.spine.annotation.GeneratedMixin
import io.spine.annotation.Internal

/**
* A high-level Protobuf declaration, such as a message, an enum, or a service.
*/
@Internal
@GeneratedMixin
public interface ProtoDeclaration : Message {

/**
* Obtains the name of this Protobuf declaration.
*/
public val name: ProtoDeclarationName

/**
* Obtains the type URl of the type.
*
* A type URL contains the type URL prefix and the qualified name of the type separated by
* the slash (`/`) symbol. See the docs of `google.protobuf.Any.type_url` for more info.
*/
public fun typeUrl(): String? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the return value can really be null, please document when such a case can occur.

Copy link
Collaborator

@alexander-yevsyukov alexander-yevsyukov Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProtoDeclarationName has a similar method that returns non-nullable String. How these two types are different in that regards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that was a mistake. Fixed it.

return name.typeUrl()
}
}
46 changes: 46 additions & 0 deletions api/src/main/kotlin/io/spine/protodata/ProtoDeclarationName.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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

import com.google.protobuf.Message
import io.spine.annotation.GeneratedMixin
import io.spine.annotation.Internal

/**
* Name of a high-level Protobuf declaration.
*/
@Internal
@GeneratedMixin
public interface ProtoDeclarationName : Message {

/**
* Prints this name as a type URL.
*
* A type URL contains the type URL prefix and the qualified name of the type separated by
* the slash (`/`) symbol. See the docs of `google.protobuf.Any.type_url` for more info.
*/
public fun typeUrl(): String
}
41 changes: 41 additions & 0 deletions api/src/main/kotlin/io/spine/protodata/ServiceNameMixin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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

import io.spine.annotation.GeneratedMixin
import io.spine.annotation.Internal

/**
* Name of a service declared in Protobuf.
*/
@Internal
@GeneratedMixin
public interface ServiceNameMixin : ProtoDeclarationName, ServiceNameOrBuilder {

override fun typeUrl(): String {
return "$typeUrlPrefix/$packageName.$simpleName"
}
}
41 changes: 41 additions & 0 deletions api/src/main/kotlin/io/spine/protodata/TypeNameMixin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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

import io.spine.annotation.GeneratedMixin
import io.spine.annotation.Internal

/**
* Name of a message or enum type.
*/
@Internal
@GeneratedMixin
public interface TypeNameMixin : ProtoDeclarationName, TypeNameOrBuilder {

override fun typeUrl(): String {
return "$typeUrlPrefix/${qualifiedName()}"
}
}
2 changes: 1 addition & 1 deletion api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface Plugin {
*/
public fun BoundedContextBuilder.apply(plugin: Plugin) {
val repos = plugin.viewRepositories().toMutableList()
val defaultRepos = plugin.views().map { io.spine.protodata.plugin.ViewRepository.default(it) }
val defaultRepos = plugin.views().map { ViewRepository.default(it) }
repos.addAll(defaultRepos)
val repeatedView = repos.map { it.entityClass() }
.groupingBy { it }
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/proto/spine/protodata/ast.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ message File {
// Applicable to message and enum types.
//
message TypeName {
option (is).java_type = "TypeNameMixin";

// The short name of the type.
string simple_name = 1;
Expand Down Expand Up @@ -115,6 +116,7 @@ message TypeName {

// A Protobuf message type.
message MessageType {
option (is).java_type = "ProtoDeclaration";

TypeName name = 1;

Expand Down Expand Up @@ -159,6 +161,7 @@ message MessageType {

// A Protobuf enum type.
message EnumType {
option (is).java_type = "ProtoDeclaration";

TypeName name = 1;

Expand Down Expand Up @@ -372,6 +375,7 @@ message OneofGroup {

// A name of a Protobuf service type.
message ServiceName {
option (is).java_type = "ServiceNameMixin";

// The short name of the service type.
string simple_name = 1;
Expand All @@ -391,6 +395,7 @@ message ServiceName {

// A Protobuf service type.
message Service {
option (is).java_type = "ProtoDeclaration";

ServiceName name = 1;

Expand All @@ -405,6 +410,9 @@ message Service {

// Documentation of this service.
Doc doc = 4;

// Path to the file which declares this service.
FilePath file = 5;
}

// A name of an RPC method.
Expand Down
21 changes: 21 additions & 0 deletions api/src/main/proto/spine/protodata/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ option java_outer_classname = "EventsProto";
option java_multiple_files = true;

import "spine/protodata/ast.proto";
import "spine/protodata/source.proto";

// Emitted when processing of a file begins.
message FileEntered {
Expand Down Expand Up @@ -264,3 +265,23 @@ message RpcExited {

RpcName rpc = 3;
}

// Emitted when the Protobuf compiler discovers a dependency file.
//
// The order of files reported by events of this type is unspecified. Users should not rely on any
// particular order.
//
// Each file is only reported by one event, even if the file is imported into
//
// `DependencyDiscovered` events always precede all other Protobuf compiler events, i.e.
// the first `FileEntered` will always be emitted after the last `DependencyDiscovered`.
//
// Normally, no code should be generated for dependencies. However, they can be used for additional
// info when generating code for the module's own types.
//
message DependencyDiscovered {
Copy link
Collaborator

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.

Copy link
Contributor Author

@dmdashenkov dmdashenkov Mar 27, 2023

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:

  • we only work with Protobuf, no Java or JS or other dependency is ever considered in ProtoData (not talking about the Gradle compiler here, only ProtoData proper);
  • this is one of a series of events such as TypeEntered, OptionDiscovered, etc., which do not specify the language either.


FilePath path = 1;

ProtobufSourceFile file = 2;
}
Loading