-
Notifications
You must be signed in to change notification settings - Fork 758
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
Introduce new isEnum()
and getEnumSymbol()
APIs in UnionTypeSymbol
to distinguish and get enum-symbol in union-type descriptors
#41173
Conversation
isEnum()
and getEnumSymbol()
APIs in UnionTypeSymbol
to distinguish and get enum-symbol's form union-type descriptorsisEnum()
and getEnumSymbol()
APIs in UnionTypeSymbol
to distinguish and get enum-symbol in union-type descriptors
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #41173 +/- ##
=============================================
+ Coverage 0.00% 76.39% +76.39%
- Complexity 0 52112 +52112
=============================================
Files 9 2858 +2849
Lines 35 195978 +195943
Branches 0 25403 +25403
=============================================
+ Hits 0 149723 +149723
- Misses 35 37953 +37918
- Partials 0 8302 +8302
☔ View full report in Codecov by Sentry. |
SymbolFactory symbolFactory = SymbolFactory.getInstance(this.context); | ||
this.enumSymbol = symbolFactory.createEnumSymbol((BEnumSymbol) tsymbol, tsymbol.getName().value);; | ||
|
||
return Optional.ofNullable(this.enumSymbol); |
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.
return Optional.ofNullable(this.enumSymbol); | |
return Optional.of(this.enumSymbol); |
At this point can the enumSymbol be null?
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.
Thanks for noticing!
@Override | ||
public Optional<EnumSymbol> getEnumSymbol() { |
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'm not sure this is ideal. isEnum kinda makes sense, but why do we need to allow retrieving the enum symbol like this? In a way, it's like having a reference to the definition from the type symbol.
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.
Yes. It's kinda exposing the information related to the enum symbol. Currently, we may not have such things, but having this may allow us to expose that information right?
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.
and this is not a way of referencing. For referencing we have a structure as TypeRefType
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 meant having enumSymbol
in BallerinaUnionTypeSymbol
. This isn't quite right, IMO. The type doesn't need to how it was defined.
Yes. It's kinda exposing the information related to the enum symbol. Currently, we may not have such things, but having this may allow us to expose that information right?
I don't think that's the correct way. If someone wants enum symbol they can still get it from the model, right? I don't think the type symbol should expose it.
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 meant having enumSymbol in BallerinaUnionTypeSymbol. This isn't quite right, IMO. The type doesn't need to how it was defined.
yeah. What if we have introduced some attributes only related to enums and the ballerina extension developer needs to get them? We can't expose that only-enum information via the BallerinaUnionTypeSymbol right?
I don't think that's the correct way. If someone wants enum symbol they can still get it from the model, right? I don't think the type symbol should expose it.
How can they get an enum symbol without the location?
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 meant having enumSymbol in BallerinaUnionTypeSymbol. This isn't quite right, IMO. The type doesn't need to how it was defined.
yeah. What if we have introduced some attributes only related to enums and the ballerina extension developer needs to get them? We can't expose that only-enum information via the BallerinaUnionTypeSymbol right?
Can you give an example for this?
I don't think that's the correct way. If someone wants enum symbol they can still get it from the model, right? I don't think the type symbol should expose it.
How can they get an enum symbol without the location?
Can't they filter out from module symbols by name?
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.
We can't expose that only-enum information via the BallerinaUnionTypeSymbol right?
Yes, we can't. I can't think of such info anyway. We shouldn't mix up enums and types. An enum is just another way to define a union of string singletons. From a type symbol point of view, they are basically the same.
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.
Can you give an example for this?
what about annotation attachments? We shouldn't link them with the UnionTypeSymbol right?
Can't they filter out module symbols by name?
Yeah, we can, but we need the name to filter out right? What if we need to get the enum that is in another module, and we have referenced an enum value (e.x: OPEN) and we need to know the other sibling values of the enum (which is referenced in new type?
// defined in another module `test0.module1`'
public enum State {
OPEN,
CLOSED
}
// main.bal
import test0.module1;
type ConnectionState State;
function test() {
string x = module1.OPEN;
}
Let's say there is a ballerina extension writer who needs to get only the sibling values of OPEN
.
Also, isn't it costly to use the filter when there are so many symbols?
Yes, we can't. I can't think of such info anyway. We shouldn't mix up enums and types. An enum is just another way to define a union of string singletons. From a type symbol point of view, they are basically the same.
Yes. This is true, but here we are just showing the relationship with the associated enum defined somewhere
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.
what about annotation attachments? We shouldn't link them with the UnionTypeSymbol right?
annotation annot on type;
const RED = "RED";
const BLUE = "BLUE";
@annot
type Colour RED|BLUE;
is the same as
annotation annot on type;
@annot
enum Colour {
RED,
BLUE
}
so we shouldn't have to special case anything for enums.
Yeah, we can, but we need the name to filter out right?
If you have the union type you have the name?
What if we need to get the enum that is in another module, and we have referenced an enum value (e.x: OPEN) and we need to know the other sibling values of the enum (which is referenced in new type?
How does adding the enum symbol to the union type help with this? The union type corresponds to the enum, not the member?
Also, isn't it costly to use the filter when there are so many symbols?
It's just filtering based on a string? Anyway, the API being well-defined is more important IMO.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
Closing due to this: #38179 (comment) |
Purpose
$title
Fixes #38179
Approach
Samples
Remarks
Check List