This is an automated email from the ASF dual-hosted git repository. tmysik pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 9cab4ae67a Fix variable highlighting in arrow function #4209 new e5a51e294b Merge pull request #4250 from junichi11/gh4209-incorrect-highlighting 9cab4ae67a is described below commit 9cab4ae67adca0221144fea552ab04e29e5c1a26 Author: Junichi Yamamoto <junich...@apache.org> AuthorDate: Sat Jun 18 23:59:49 2022 +0900 Fix variable highlighting in arrow function #4209 - https://github.com/apache/netbeans/issues/4209 - Fix the scope for the variable in the arrow function - Add unit tests --- .../php/editor/model/impl/ModelVisitor.java | 4 ++- .../testArrowFunctions/testArrowFunctions.php | 5 +++ .../testArrowFunctions/testArrowFunctions.php | 5 +++ ...s.php.testArrowFunctions_GH4209_01a.occurrences | 3 ++ ...s.php.testArrowFunctions_GH4209_01b.occurrences | 3 ++ ...s.php.testArrowFunctions_GH4209_01c.occurrences | 3 ++ ...s.php.testArrowFunctions_GH4209_01d.occurrences | 3 ++ ...s.php.testArrowFunctions_GH4209_01e.occurrences | 3 ++ ...s.php.testArrowFunctions_GH4209_02a.occurrences | 2 ++ ...s.php.testArrowFunctions_GH4209_02b.occurrences | 2 ++ ...s.php.testArrowFunctions_GH4209_03a.occurrences | 1 + ...s.php.testArrowFunctions_GH4209_03b.occurrences | 1 + .../php/editor/csl/GotoDeclarationPHP74Test.java | 24 +++++++++++++++ .../editor/csl/OccurrencesFinderImplPHP74Test.java | 36 ++++++++++++++++++++++ 14 files changed, 94 insertions(+), 1 deletion(-) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java index d53d479b81..28384978dc 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java @@ -862,9 +862,11 @@ public final class ModelVisitor extends DefaultTreePathVisitor { && ((FunctionScope)inScope).isAnonymous()) { FunctionScope functionScope = (FunctionScope) inScope; Collection<? extends VariableName> declaredVariables = functionScope.getDeclaredVariables(); + List<? extends String> parameterNames = functionScope.getParameterNames(); for (VariableName declaredVariable : declaredVariables) { if (declaredVariable.getName().equals(CodeUtils.extractVariableName(node))) { - if (isLexicalVariable(node)) { + if (isLexicalVariable(node) + || (functionScope instanceof ArrowFunctionScope) && !parameterNames.contains(declaredVariable.getName())) { // GH-4209 occurencesBuilder.prepare(node, inScope.getInScope()); } else { occurencesBuilder.prepare(node, inScope); diff --git a/php/php.editor/test/unit/data/testfiles/gotodeclaration/testArrowFunctions/testArrowFunctions.php b/php/php.editor/test/unit/data/testfiles/gotodeclaration/testArrowFunctions/testArrowFunctions.php index 0fb500423d..aeb30e069e 100644 --- a/php/php.editor/test/unit/data/testfiles/gotodeclaration/testArrowFunctions/testArrowFunctions.php +++ b/php/php.editor/test/unit/data/testfiles/gotodeclaration/testArrowFunctions/testArrowFunctions.php @@ -72,6 +72,11 @@ $fn4 = function ($x) use ($y) { return fn($x) => $x + $y; }; +// GH-4209 +$gh4209a = 0; +$gh4209b = fn() => $gh4209a > 0 ? $gh4209a + 1 : 2; +$gh4209b = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2; + function test(callable $f) { return fn(...$args) => !$f(...$args); } diff --git a/php/php.editor/test/unit/data/testfiles/markoccurences/testArrowFunctions/testArrowFunctions.php b/php/php.editor/test/unit/data/testfiles/markoccurences/testArrowFunctions/testArrowFunctions.php index 0fb500423d..aeb30e069e 100644 --- a/php/php.editor/test/unit/data/testfiles/markoccurences/testArrowFunctions/testArrowFunctions.php +++ b/php/php.editor/test/unit/data/testfiles/markoccurences/testArrowFunctions/testArrowFunctions.php @@ -72,6 +72,11 @@ $fn4 = function ($x) use ($y) { return fn($x) => $x + $y; }; +// GH-4209 +$gh4209a = 0; +$gh4209b = fn() => $gh4209a > 0 ? $gh4209a + 1 : 2; +$gh4209b = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2; + function test(callable $f) { return fn(...$args) => !$f(...$args); } diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01a.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01a.occurrences new file mode 100644 index 0000000000..5581cd48bf --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01a.occurrences @@ -0,0 +1,3 @@ +$|>MARK_OCCURRENCES:gh^4209a<| = 0; +$gh4209b = fn() => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : 2; +$gh4209b = fn($gh4209c) => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : $gh4209c + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01b.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01b.occurrences new file mode 100644 index 0000000000..37f07ff233 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01b.occurrences @@ -0,0 +1,3 @@ +$|>MARK_OCCURRENCES:gh4209a<| = 0; +$gh4209b = fn() => $|>MARK_OCCURRENCES:gh420^9a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : 2; +$gh4209b = fn($gh4209c) => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : $gh4209c + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01c.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01c.occurrences new file mode 100644 index 0000000000..2e4ebdb5e2 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01c.occurrences @@ -0,0 +1,3 @@ +$|>MARK_OCCURRENCES:gh4209a<| = 0; +$gh4209b = fn() => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh^4209a<| + 1 : 2; +$gh4209b = fn($gh4209c) => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : $gh4209c + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01d.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01d.occurrences new file mode 100644 index 0000000000..191d511958 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01d.occurrences @@ -0,0 +1,3 @@ +$|>MARK_OCCURRENCES:gh4209a<| = 0; +$gh4209b = fn() => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : 2; +$gh4209b = fn($gh4209c) => $|>MARK_OCCURRENCES:gh42^09a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : $gh4209c + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01e.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01e.occurrences new file mode 100644 index 0000000000..ac3f240c5f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_01e.occurrences @@ -0,0 +1,3 @@ +$|>MARK_OCCURRENCES:gh4209a<| = 0; +$gh4209b = fn() => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh4209a<| + 1 : 2; +$gh4209b = fn($gh4209c) => $|>MARK_OCCURRENCES:gh4209a<| > 0 ? $|>MARK_OCCURRENCES:gh4^209a<| + 1 : $gh4209c + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_02a.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_02a.occurrences new file mode 100644 index 0000000000..1e5eb94140 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_02a.occurrences @@ -0,0 +1,2 @@ +$|>MARK_OCCURRENCES:gh4^209b<| = fn() => $gh4209a > 0 ? $gh4209a + 1 : 2; +$|>MARK_OCCURRENCES:gh4209b<| = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_02b.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_02b.occurrences new file mode 100644 index 0000000000..f3331302af --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_02b.occurrences @@ -0,0 +1,2 @@ +$|>MARK_OCCURRENCES:gh4209b<| = fn() => $gh4209a > 0 ? $gh4209a + 1 : 2; +$|>MARK_OCCURRENCES:gh42^09b<| = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_03a.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_03a.occurrences new file mode 100644 index 0000000000..62ee664770 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_03a.occurrences @@ -0,0 +1 @@ +$gh4209b = fn($|>MARK_OCCURRENCES:gh^4209c<|) => $gh4209a > 0 ? $gh4209a + 1 : $|>MARK_OCCURRENCES:gh4209c<| + 2; diff --git a/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_03b.occurrences b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_03b.occurrences new file mode 100644 index 0000000000..d0219c52d2 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/testArrowFunctions.php.testArrowFunctions_GH4209_03b.occurrences @@ -0,0 +1 @@ +$gh4209b = fn($|>MARK_OCCURRENCES:gh4209c<|) => $gh4209a > 0 ? $gh4209a + 1 : $|>MARK_OCCURRENCES:gh42^09c<| + 2; diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/GotoDeclarationPHP74Test.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/GotoDeclarationPHP74Test.java index ad2a48ce1a..13981589d0 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/GotoDeclarationPHP74Test.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/GotoDeclarationPHP74Test.java @@ -411,4 +411,28 @@ public class GotoDeclarationPHP74Test extends GotoDeclarationTestBase { checkDeclaration(getTestPath(), " return fn(...$args) => !$f(...$ar^gs);", " return fn(...$^args) => !$f(...$args);"); } + public void testArrowFunctions_GH4209_01a() throws Exception { + checkDeclaration(getTestPath(), "$gh4209b = fn() => $g^h4209a > 0 ? $gh4209a + 1 : 2;", "$^gh4209a = 0;"); + } + + public void testArrowFunctions_GH4209_01b() throws Exception { + checkDeclaration(getTestPath(), "$gh4209b = fn() => $gh4209a > 0 ? $gh4^209a + 1 : 2;", "$^gh4209a = 0;"); + } + + public void testArrowFunctions_GH4209_01c() throws Exception { + checkDeclaration(getTestPath(), "$gh4209b = fn($gh4209c) => $gh420^9a > 0 ? $gh4209a + 1 : $gh4209c + 2;", "$^gh4209a = 0;"); + } + + public void testArrowFunctions_GH4209_01d() throws Exception { + checkDeclaration(getTestPath(), "$gh4209b = fn($gh4209c) => $gh4209a > 0 ? $gh4209^a + 1 : $gh4209c + 2;", "$^gh4209a = 0;"); + } + + public void testArrowFunctions_GH4209_02a() throws Exception { + checkDeclaration(getTestPath(), "$gh420^9b = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2;", "$^gh4209b = fn() => $gh4209a > 0 ? $gh4209a + 1 : 2;"); + } + + public void testArrowFunctions_GH4209_03a() throws Exception { + checkDeclaration(getTestPath(), "$gh4209b = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh^4209c + 2;", "$gh4209b = fn($^gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2;"); + } + } diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImplPHP74Test.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImplPHP74Test.java index b249c6969a..db0f77441e 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImplPHP74Test.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImplPHP74Test.java @@ -596,4 +596,40 @@ public class OccurrencesFinderImplPHP74Test extends OccurrencesFinderImplTestBas checkOccurrences(getTestPath(), " return fn(...$args) => !$f(...$ar^gs);", true); } + public void testArrowFunctions_GH4209_01a() throws Exception { + checkOccurrences(getTestPath(), "$gh^4209a = 0;", true); + } + + public void testArrowFunctions_GH4209_01b() throws Exception { + checkOccurrences(getTestPath(), "$gh4209b = fn() => $gh420^9a > 0 ? $gh4209a + 1 : 2;", true); + } + + public void testArrowFunctions_GH4209_01c() throws Exception { + checkOccurrences(getTestPath(), "$gh4209b = fn() => $gh4209a > 0 ? $gh^4209a + 1 : 2;", true); + } + + public void testArrowFunctions_GH4209_01d() throws Exception { + checkOccurrences(getTestPath(), "$gh4209b = fn($gh4209c) => $gh42^09a > 0 ? $gh4209a + 1 : $gh4209c + 2;", true); + } + + public void testArrowFunctions_GH4209_01e() throws Exception { + checkOccurrences(getTestPath(), "$gh4209b = fn($gh4209c) => $gh4209a > 0 ? $gh4^209a + 1 : $gh4209c + 2;", true); + } + + public void testArrowFunctions_GH4209_02a() throws Exception { + checkOccurrences(getTestPath(), "$gh4^209b = fn() => $gh4209a > 0 ? $gh4209a + 1 : 2;", true); + } + + public void testArrowFunctions_GH4209_02b() throws Exception { + checkOccurrences(getTestPath(), "$gh42^09b = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2;", true); + } + + public void testArrowFunctions_GH4209_03a() throws Exception { + checkOccurrences(getTestPath(), "$gh4209b = fn($gh^4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh4209c + 2;", true); + } + + public void testArrowFunctions_GH4209_03b() throws Exception { + checkOccurrences(getTestPath(), "$gh4209b = fn($gh4209c) => $gh4209a > 0 ? $gh4209a + 1 : $gh42^09c + 2;", true); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists