mbien commented on code in PR #6658:
URL: https://github.com/apache/netbeans/pull/6658#discussion_r1405508090
##########
java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToLambdaPreconditionChecker.java:
##########
@@ -137,9 +137,48 @@ private MethodTree
getMethodFromFunctionalInterface(TreePath pathToNewClassTree)
candidate = (MethodTree)member;
}
}
+ // default methods can't be implemented with a lambda
+ ExecutableElement candidateElement = (ExecutableElement)
info.getTrees().getElement(new TreePath(pathToNewClassTree, candidate));
+ if (overridesDefaultMethod(candidateElement, (TypeElement)
baseElement)) {
+ return null;
+ }
return candidate;
}
+ private boolean overridesDefaultMethod(ExecutableElement method,
TypeElement superType) {
+ Boolean overrides = overridesDefaultMethodImpl(method, superType);
+ return overrides != null && overrides;
+ }
+
+ private Boolean overridesDefaultMethodImpl(ExecutableElement method,
TypeElement superType) {
+ List<? extends VariableElement> methodParams = method.getParameters();
+ for (Element e : superType.getEnclosedElements()) {
+ if (e.getKind() == ElementKind.METHOD &&
method.getSimpleName().equals(e.getSimpleName())
+ && parameterTypesMatch(methodParams, ((ExecutableElement)
e).getParameters())) {
+ return e.getModifiers().contains(Modifier.DEFAULT);
+ }
+ }
+ for (TypeMirror otherType : superType.getInterfaces()) {
+ Boolean overrides = overridesDefaultMethodImpl(method,
(TypeElement) types.asElement(otherType));
+ if (overrides != null) {
+ return overrides;
+ }
+ }
+ return null; // no match here but check the rest of the interface tree
+ }
Review Comment:
@lahodaj javac won't create the model of invalid code which produces cycles
in interface hierarchies, right? I tested it and this seems to work fine.
--
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