Comments (5)
And either we want a box, like NullableTypeName
that holds a non-nullable type, or to put the modifier on the type directly. We put annotations directly on TypeName
and that’s worked well.
from kotlinpoet.
Upon investigation, I think TypeName
is the wrong place for this.
In Java, java.lang.reflect.Class
extends from java.lang.reflect.Type
, but that's not the same for Kotlin.
This is evident in the fact that TypeName
represents things like classes, interfaces, etc., which can't be nullable. Nullability applies to things like properties, parameters, and return types (KCallable
, with the nullability identified by the KType.isMarkedNullable
field on the returnType
property).
As a result, I see two options:
- Adjust the model in KotlinPoet to better reflect the model in Kotlin.
- Add the nullability checks to callable types (properties, params, functions, etc.)
The first option is a bit of a major overhaul, the second means possible code duplication.
from kotlinpoet.
This is evident in the fact that TypeName represents things like classes, interfaces, etc., which can't be nullable.
It represents a reference to those components but not those components themselves. And since the reference can be nullable, it makes sense to model that as part of the type.
Kotlin models it on KType as you said, and TypeName is our version of the data modeled by it.
from kotlinpoet.
TypeName
is intended to be “something that could be a return type, a parameter type, or a property type”.
from kotlinpoet.
Fix merged!
#70
from kotlinpoet.
Related Issues (20)
- Can we add IDE highlighting to addStatement or similar statements HOT 4
- kotlin.* imports in generated classes HOT 1
- There is no way to add format strings to the code HOT 2
- Support at least few Kotlin API targets via apiVersion to simplify migrations
- Split the KotlinPoet documentation page into multiple subpages
- addKdoc not working as expected when property is involved HOT 2
- com.squareup:kotlinpoet 1.15.3 missing class files. HOT 3
- callSuperConstructor does not generate code for its parameters HOT 2
- Code generated with ksp interop's toAnnotationSpec() generates code that fails to compile when passed an OptIn annotation HOT 1
- Integration with okio's file system HOT 4
- Aliased imports not working for nested classes and generate unused imports and usage of FQNs HOT 2
- Aliased imports not used when generating code in same package for which the aliased import is defined HOT 1
- Reference Kotlinpoet created class in another class.
- Kotlin Keywords escaped in Class and Property names HOT 6
- Comments outside of code block HOT 1
- Wrap supertype/superinterfaces like parameters
- The get / set index access operator overloads are incorrectly escaped HOT 2
- `joinToCode` on `Iterable<T>` which accepts `(T) -> CodeBlock` trailing lambda
- Redundant visibility modifier added on interfaces HOT 3
- Option to disable line wrapping HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlinpoet.