sdedic commented on code in PR #6595:
URL: https://github.com/apache/netbeans/pull/6595#discussion_r1366613513
##########
java/java.hints/src/org/netbeans/modules/java/hints/introduce/ScanStatement.java:
##########
@@ -114,12 +116,18 @@ public Void scan(Tree tree, Void p) {
}
return null;
}
-
+
@Override
public Void visitLambdaExpression(LambdaExpressionTree node, Void p) {
nesting++;
+ if (node.equals(firstInSelection)) {
Review Comment:
I'd use `==` here.
##########
java/java.hints/src/org/netbeans/modules/java/hints/introduce/ScanStatement.java:
##########
@@ -114,12 +116,18 @@ public Void scan(Tree tree, Void p) {
}
return null;
}
-
+
@Override
public Void visitLambdaExpression(LambdaExpressionTree node, Void p) {
nesting++;
+ if (node.equals(firstInSelection)) {
+ phase = PHASE_INSIDE_SELECTION;
+ }
+ isLambda = true;
Review Comment:
hmmm ... what about nested lambdas ? Suppose a code like
```
Runnable r = () -> new Worker() {
public void n() {
doSomething(variable);
}
public void someOverrideMethod() {
someExecutor.execute(
// selection starts here
() -> whateverMethodCall(variable);
// selection ends here
);
}
}.run();
```
The `lambda` flag becomes `true` on the outermost lambda, which is still
unrelated to the selection
##########
java/java.hints/src/org/netbeans/modules/java/hints/introduce/ScanStatement.java:
##########
@@ -164,7 +172,14 @@ public Void visitIdentifier(IdentifierTree node, Void p) {
if (IntroduceHint.LOCAL_VARIABLES.contains(e.getKind())) {
switch (phase) {
case PHASE_INSIDE_SELECTION:
- if (localVariables.contains(e) &&
usedLocalVariables.get(e) == null) {
+
+ final boolean isUsedInLambda = isLambda
+ && treesSeensInSelection.contains(node)
Review Comment:
Question: if `PHASE_INSIDE_SELECTION` is active, then the `node` is already
added in `scan()` line 106 ?
--
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