mbien commented on code in PR #9173:
URL: https://github.com/apache/netbeans/pull/9173#discussion_r2747160105
##########
java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java:
##########
@@ -5996,7 +5996,7 @@ private Set<? extends TypeMirror> getSmartTypesImpl(Env
env) throws IOException
path = new TreePath(path, mid);
TypeMirror typeMirror =
controller.getTrees().getTypeMirror(path);
final ExecutableType midTM = typeMirror != null &&
typeMirror.getKind() == TypeKind.EXECUTABLE ? (ExecutableType) typeMirror :
null;
- final ExecutableElement midEl = midTM == null ? null :
(ExecutableElement) controller.getTrees().getElement(path);
+ final ExecutableElement midEl = midTM != null &&
controller.getTrees().getElement(path) instanceof ExecutableElement ee ? ee :
null;
Review Comment:
tbh 70% of the reason i wrote it that way is because the new `instanceof`
get-check-and-assign pattern can be put into a one-liner which is the common
style throughout the whole class. You could do something similar with
`Optional` but it is less elegant IMO. (but of course this shouldn't be an
excuse to write broken code ;))
I did have the `Kind` vs `implements` issue in the back of my head since
@lahodaj explained it to me once, but I believe in this particular case it
probably wouldn't matter the way the two variables are used.
Having `TypeMirror` of kind `Executable` but the `Element` of a type other
than `ExecutableElement` sounds to me like inconsistent state? I suppose thats
why the original code casted it without kind check?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists