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
Added Optional method in SymbolReference #3740
Added Optional method in SymbolReference #3740
Conversation
this.correspondingDeclaration = correspondingDeclaration; | ||
} | ||
|
||
/** | ||
* Create a solve reference to the given symbol. | ||
*/ | ||
public static <S extends ResolvedDeclaration, S2 extends S> SymbolReference<S> solved(S2 symbolDeclaration) { | ||
return new SymbolReference<S>(Optional.of(symbolDeclaration)); | ||
return new SymbolReference<>(symbolDeclaration); |
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 this method declaration be simplified?
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.
It's a good question. Simplifying is not easy, since it impacts the api. For example, tried to do that in commit c4e42df but it may break the current API.
} | ||
|
||
/** | ||
* Create an unsolved reference specifying the type of the value expected. | ||
*/ | ||
public static <S extends ResolvedDeclaration, S2 extends S> SymbolReference<S> unsolved(Class<S2> clazz) { | ||
return new SymbolReference<>(Optional.empty()); | ||
return new SymbolReference<>(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.
Can this method declaration be simplified?
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.
It's a good question. Simplifying is not easy, since it impacts the api.
I think the best approach would be leave it as it is, and consider it as deprecated :)
Codecov Report
@@ Coverage Diff @@
## master #3740 +/- ##
===============================================
+ Coverage 57.315% 57.319% +0.004%
- Complexity 2670 2672 +2
===============================================
Files 635 635
Lines 33553 33559 +6
Branches 5784 5787 +3
===============================================
+ Hits 19231 19236 +5
- Misses 12270 12271 +1
Partials 2052 2052
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
When i was working with the code noticed an inconsistency in SymbolReference method comparing with other classes.
Most of the methods that can return null return an optional to allow the programmer to check when the value is present or not.
This method was not following this guideline requiring the use of an additional method isSolved() before the call of getCorrespondingDeclaration().
This Pull Request adds support for the Optional, allowing a more consistent pattern between methods.
This PR is similar to #3044 BUT does not affect the Public API.
Let me know your thoughts!