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

Added Optional method in SymbolReference #3740

Merged
merged 11 commits into from Oct 31, 2022

Conversation

4everTheOne
Copy link
Contributor

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!

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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Merging #3740 (ac55139) into master (ed5d3ef) will increase coverage by 0.004%.
The diff coverage is 71.212%.

Impacted file tree graph

@@               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               
Flag Coverage Δ
AlsoSlowTests 57.319% <71.212%> (+0.004%) ⬆️
javaparser-core 52.463% <ø> (ø)
javaparser-symbol-solver 36.750% <71.212%> (+0.008%) ⬆️
jdk-10 57.309% <71.212%> (-0.002%) ⬇️
jdk-11 57.315% <71.212%> (+0.004%) ⬆️
jdk-12 57.315% <71.212%> (+0.004%) ⬆️
jdk-13 57.315% <71.212%> (+0.010%) ⬆️
jdk-14 57.315% <71.212%> (+0.004%) ⬆️
jdk-15 57.315% <71.212%> (+0.004%) ⬆️
jdk-16 57.312% <71.212%> (+0.001%) ⬆️
jdk-8 57.317% <71.212%> (+0.004%) ⬆️
jdk-9 57.309% <71.212%> (+0.004%) ⬆️
macos-latest 57.308% <71.212%> (+0.004%) ⬆️
ubuntu-latest 57.305% <69.696%> (+0.004%) ⬆️
windows-latest 57.299% <71.212%> (+0.004%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...symbolsolver/javaparsermodel/JavaParserFacade.java 75.155% <0.000%> (ø)
...avaparsermodel/contexts/InstanceOfExprContext.java 90.000% <0.000%> (ø)
...del/contexts/JavaParserTypeDeclarationAdapter.java 91.919% <0.000%> (ø)
...rsermodel/contexts/MethodReferenceExprContext.java 61.363% <0.000%> (ø)
...ver/reflectionmodel/ReflectionEnumDeclaration.java 32.835% <0.000%> (ø)
...eflectionmodel/ReflectionInterfaceDeclaration.java 47.524% <0.000%> (ø)
...vaparser/symbolsolver/resolution/SymbolSolver.java 45.945% <0.000%> (ø)
...vaparser/symbolsolver/core/resolution/Context.java 86.956% <33.333%> (ø)
...lver/javassistmodel/JavassistClassDeclaration.java 75.581% <50.000%> (ø)
...olver/javassistmodel/JavassistEnumDeclaration.java 55.172% <50.000%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ed5d3ef...ac55139. Read the comment docs.

@jlerbsc jlerbsc merged commit 828e7ff into javaparser:master Oct 31, 2022
@jlerbsc jlerbsc added this to the next release milestone Oct 31, 2022
@jlerbsc jlerbsc added the PR: Changed A PR that changes implementation without changing behaviour (e.g. performance) label Oct 31, 2022
@4everTheOne 4everTheOne deleted the improvement/symbol-reference branch December 7, 2022 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Changed A PR that changes implementation without changing behaviour (e.g. performance)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants