From cbb5c44d14af21703e7171e7b3071750226b0db4 Mon Sep 17 00:00:00 2001 From: Junichi Yamamoto Date: Mon, 6 Jan 2025 22:14:37 +0900 Subject: [PATCH] PHP 8.4 Support: new MyClass()->method() without parentheses (Part 6) - https://github.com/apache/netbeans/issues/8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Add a unit test for the navigator --- .../php84/newWithoutParentheses.pass | 22 ++++++ .../structure/php84/newWithoutParentheses.php | 67 +++++++++++++++++++ .../modules/php/editor/csl/NavigatorTest.java | 5 ++ 3 files changed, 94 insertions(+) create mode 100644 php/php.editor/test/unit/data/goldenfiles/org/netbeans/modules/php/editor/csl/NavigatorTest/structure/php84/newWithoutParentheses.pass create mode 100644 php/php.editor/test/unit/data/testfiles/structure/php84/newWithoutParentheses.php diff --git a/php/php.editor/test/unit/data/goldenfiles/org/netbeans/modules/php/editor/csl/NavigatorTest/structure/php84/newWithoutParentheses.pass b/php/php.editor/test/unit/data/goldenfiles/org/netbeans/modules/php/editor/csl/NavigatorTest/structure/php84/newWithoutParentheses.pass new file mode 100644 index 000000000000..dd9403293352 --- /dev/null +++ b/php/php.editor/test/unit/data/goldenfiles/org/netbeans/modules/php/editor/csl/NavigatorTest/structure/php84/newWithoutParentheses.pass @@ -0,0 +1,22 @@ +|-#anon#newWithoutParentheses_php#1 [846, 888] : ESCAPED{{}} +|--CONSTANT [864, 872] : ESCAPED{CONSTANT}ESCAPED{ }ESCAPED{'constant'} +|-#anon#newWithoutParentheses_php#2 [910, 952] : ESCAPED{{}} +|--CONSTANT [928, 936] : ESCAPED{CONSTANT}ESCAPED{ }ESCAPED{'constant'} +|-#anon#newWithoutParentheses_php#3 [978, 1016] : ESCAPED{{}} +|--$field [998, 1003] : ESCAPED{$field} +|-#anon#newWithoutParentheses_php#4 [1035, 1093] : ESCAPED{{}} +|--$staticField [1062, 1073] : ESCAPED{$staticField} +|-#anon#newWithoutParentheses_php#5 [1114, 1155] : ESCAPED{{}} +|--method [1142, 1153] : ESCAPED{method}ESCAPED{(}ESCAPED{)} +|-#anon#newWithoutParentheses_php#6 [1190, 1231] : ESCAPED{{}} +|--method [1218, 1229] : ESCAPED{method}ESCAPED{(}ESCAPED{)} +|-#anon#newWithoutParentheses_php#7 [1248, 1302] : ESCAPED{{}} +|--staticMethod [1283, 1300] : ESCAPED{staticMethod}ESCAPED{(}ESCAPED{)} +|-#anon#newWithoutParentheses_php#8 [1325, 1368] : ESCAPED{{}} +|--__invoke [1353, 1366] : ESCAPED{__invoke}ESCAPED{(}ESCAPED{)} +|-#anon#newWithoutParentheses_php#9 [1399, 1442] : ESCAPED{{}} +|--__invoke [1427, 1440] : ESCAPED{__invoke}ESCAPED{(}ESCAPED{)} +|-#anon#newWithoutParentheses_php#10 [1451, 1486] : ESCAPED{{}} +|-#anon#newWithoutParentheses_php#11 [1508, 1571] : ESCAPED{{}} +|--$field [1559, 1564] : ESCAPED{$field}:ESCAPED{int} +|-#anon#newWithoutParentheses_php#12 [1591, 1639] : ESCAPED{{}} diff --git a/php/php.editor/test/unit/data/testfiles/structure/php84/newWithoutParentheses.php b/php/php.editor/test/unit/data/testfiles/structure/php84/newWithoutParentheses.php new file mode 100644 index 000000000000..0a5b798e8b6e --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/structure/php84/newWithoutParentheses.php @@ -0,0 +1,67 @@ +field; + +echo new class { + public static $staticField = 'static field'; +}::$staticField; + +new class { + public function method() {} +}->method(); + +$anon = new #[Attr()] class { + public function method() {} +}->method(); + +new class { + public static function staticMethod() {} +}::staticMethod(); + +new class { + public function __invoke() {} +}(); + +$anon = new #[Attr(1, 2)] class { + public function __invoke() {} +}(); + +new class () implements ArrayAccess { +}['key']; + +$anon = new class () implements ArrayAccess { + private int $field = 1; +}['key']; + +isset(new class ($a, 1, "test") implements ArrayAccess { +}['key']); diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/NavigatorTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/NavigatorTest.java index c0a78b2397ce..e92c6cfaa184 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/NavigatorTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/NavigatorTest.java @@ -159,4 +159,9 @@ public void testFunctionGuessingArrayReturnType() throws Exception { public void testTypedClassConstants() throws Exception { performTest("structure/php83/typedClassConstants"); } + + // PHP 8.4 + public void testNewWithoutParentheses() throws Exception { + performTest("structure/php84/newWithoutParentheses"); + } }