This is an automated email from the ASF dual-hosted git repository.
junichi11 pushed a commit to branch php-nb21-features
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/php-nb21-features by this push:
new dd68f675ab Fix incorrect indentation behavior #6731
new e91ac6221d Merge pull request #6738 from
junichi11/php-gh-6731-incorrect-indent
dd68f675ab is described below
commit dd68f675abe3be2950364f9bcb1f48a6a70b6237
Author: Junichi Yamamoto <[email protected]>
AuthorDate: Wed Nov 22 12:10:48 2023 +0900
Fix incorrect indentation behavior #6731
- https://github.com/apache/netbeans/issues/6731
- When a multi-line parameter of a function/method invocation has a string
with a variable(e.g. `"example {$example}"`), ignore the variable within the
string(i.e. {$example}) to avoid adding extra indentations
Example:
```php
$x = test(
"test {$test}"
);// enter key here
```
Before:
```php
$x = test(
"test {$test}"
);
// one indentation is added
```
After:
```php
$x = test(
"test {$test}"
);
// no indentation
```
---
.../modules/php/editor/lexer/LexUtilities.java | 13 ++++++++--
.../test/unit/data/testfiles/indent/gh6731_01.php | 23 +++++++++++++++++
.../data/testfiles/indent/gh6731_01.php.indented | 24 ++++++++++++++++++
.../test/unit/data/testfiles/indent/gh6731_02.php | 23 +++++++++++++++++
.../data/testfiles/indent/gh6731_02.php.indented | 24 ++++++++++++++++++
.../test/unit/data/testfiles/indent/gh6731_03.php | 21 ++++++++++++++++
.../data/testfiles/indent/gh6731_03.php.indented | 22 ++++++++++++++++
.../test/unit/data/testfiles/indent/gh6731_04.php | 27 ++++++++++++++++++++
.../data/testfiles/indent/gh6731_04.php.indented | 28 +++++++++++++++++++++
.../test/unit/data/testfiles/indent/gh6731_05.php | 28 +++++++++++++++++++++
.../data/testfiles/indent/gh6731_05.php.indented | 29 ++++++++++++++++++++++
.../test/unit/data/testfiles/indent/gh6731_06.php | 28 +++++++++++++++++++++
.../data/testfiles/indent/gh6731_06.php.indented | 29 ++++++++++++++++++++++
.../test/unit/data/testfiles/indent/gh6731_07.php | 28 +++++++++++++++++++++
.../data/testfiles/indent/gh6731_07.php.indented | 29 ++++++++++++++++++++++
.../php/editor/indent/PHPNewLineIndenterTest.java | 28 +++++++++++++++++++++
16 files changed, 402 insertions(+), 2 deletions(-)
diff --git
a/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java
b/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java
index 009abedf4f..c00a2999eb 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java
@@ -507,6 +507,7 @@ public final class LexUtilities {
Token token;
int balance = 0;
int curlyBalance = 0;
+ boolean isInQuotes = false; // GH-6731 for checking a variable in
string
do {
token = ts.token();
if (token.id() == PHPTokenId.PHP_TOKEN) {
@@ -520,6 +521,14 @@ public final class LexUtilities {
default:
//no-op
}
+ } else if (token.id() == PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING) {
+ // GH-6731 for checking a variable in string
+ // e.g. "example {$example}"
+ if ((token.text().length() == 1 &&
TokenUtilities.textEquals(token.text(), "\"")) // NOI18N
+ || (!TokenUtilities.startsWith(token.text(), "\"") &&
TokenUtilities.endsWith(token.text(), "\"")) // NOI18N
+ || (TokenUtilities.startsWith(token.text(), "\"") &&
!TokenUtilities.endsWith(token.text(), "\""))) { // NOI18N
+ isInQuotes = !isInQuotes;
+ }
} else if ((token.id() == PHPTokenId.PHP_SEMICOLON || token.id()
== PHPTokenId.PHP_OPENTAG)
&& ts.moveNext()) {
// we found previous end of expression => find begin of the
current.
@@ -584,7 +593,7 @@ public final class LexUtilities {
break;
} else if (token.id() == PHPTokenId.PHP_CURLY_CLOSE) {
curlyBalance--;
- if (curlyBalance == -1 && ts.moveNext()) {
+ if (!isInQuotes && curlyBalance == -1 && ts.moveNext()) {
// we are after previous blog close
LexUtilities.findNext(ts, Arrays.asList(
PHPTokenId.WHITESPACE,
@@ -600,7 +609,7 @@ public final class LexUtilities {
}
} else if (token.id() == PHPTokenId.PHP_CURLY_OPEN) {
curlyBalance++;
- if (curlyBalance == 1 && ts.moveNext()) {
+ if (!isInQuotes && curlyBalance == 1 && ts.moveNext()) {
// we are at the begining of a blog
LexUtilities.findNext(ts, Arrays.asList(
PHPTokenId.WHITESPACE,
diff --git a/php/php.editor/test/unit/data/testfiles/indent/gh6731_01.php
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_01.php
new file mode 100644
index 0000000000..217b87a45a
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_01.php
@@ -0,0 +1,23 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test(
+ "test {$test}"
+);^
diff --git
a/php/php.editor/test/unit/data/testfiles/indent/gh6731_01.php.indented
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_01.php.indented
new file mode 100644
index 0000000000..62309a8107
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_01.php.indented
@@ -0,0 +1,24 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test(
+ "test {$test}"
+);
+^
diff --git a/php/php.editor/test/unit/data/testfiles/indent/gh6731_02.php
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_02.php
new file mode 100644
index 0000000000..02c1dfda3a
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_02.php
@@ -0,0 +1,23 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test(
+ "test {$test} test"
+);^
diff --git
a/php/php.editor/test/unit/data/testfiles/indent/gh6731_02.php.indented
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_02.php.indented
new file mode 100644
index 0000000000..ff40070508
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_02.php.indented
@@ -0,0 +1,24 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test(
+ "test {$test} test"
+);
+^
diff --git a/php/php.editor/test/unit/data/testfiles/indent/gh6731_03.php
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_03.php
new file mode 100644
index 0000000000..de58ba0464
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_03.php
@@ -0,0 +1,21 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test("test {$test} test");^
diff --git
a/php/php.editor/test/unit/data/testfiles/indent/gh6731_03.php.indented
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_03.php.indented
new file mode 100644
index 0000000000..3fdb0bda53
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_03.php.indented
@@ -0,0 +1,22 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test("test {$test} test");
+^
diff --git a/php/php.editor/test/unit/data/testfiles/indent/gh6731_04.php
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_04.php
new file mode 100644
index 0000000000..6299dded6b
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_04.php
@@ -0,0 +1,27 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test(
+ "test"
+ . "test"
+ . "test"
+ . "test"
+ . "test {$test}"
+);^
diff --git
a/php/php.editor/test/unit/data/testfiles/indent/gh6731_04.php.indented
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_04.php.indented
new file mode 100644
index 0000000000..e735aaf76f
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_04.php.indented
@@ -0,0 +1,28 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+$result = test(
+ "test"
+ . "test"
+ . "test"
+ . "test"
+ . "test {$test}"
+);
+^
diff --git a/php/php.editor/test/unit/data/testfiles/indent/gh6731_05.php
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_05.php
new file mode 100644
index 0000000000..396f6a1522
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_05.php
@@ -0,0 +1,28 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+class GH6731 {
+
+ public function test() {
+ $result = test(
+ "test {$test}"
+ );^
+ }
+}
diff --git
a/php/php.editor/test/unit/data/testfiles/indent/gh6731_05.php.indented
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_05.php.indented
new file mode 100644
index 0000000000..01cc7003e0
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_05.php.indented
@@ -0,0 +1,29 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+class GH6731 {
+
+ public function test() {
+ $result = test(
+ "test {$test}"
+ );
+ ^
+ }
+}
diff --git a/php/php.editor/test/unit/data/testfiles/indent/gh6731_06.php
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_06.php
new file mode 100644
index 0000000000..c8186823e3
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_06.php
@@ -0,0 +1,28 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+class GH6731 {
+
+ public function test() {
+ $result = $this->something(
+ "test {$test}"
+ );^
+ }
+}
diff --git
a/php/php.editor/test/unit/data/testfiles/indent/gh6731_06.php.indented
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_06.php.indented
new file mode 100644
index 0000000000..712d99b45c
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_06.php.indented
@@ -0,0 +1,29 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+class GH6731 {
+
+ public function test() {
+ $result = $this->something(
+ "test {$test}"
+ );
+ ^
+ }
+}
diff --git a/php/php.editor/test/unit/data/testfiles/indent/gh6731_07.php
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_07.php
new file mode 100644
index 0000000000..3cd1cb8e53
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_07.php
@@ -0,0 +1,28 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+class GH6731 {
+
+ public function test() {
+ $result = self::something(
+ "test {$test} test"
+ );^
+ }
+}
diff --git
a/php/php.editor/test/unit/data/testfiles/indent/gh6731_07.php.indented
b/php/php.editor/test/unit/data/testfiles/indent/gh6731_07.php.indented
new file mode 100644
index 0000000000..2bb10c5a6e
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/indent/gh6731_07.php.indented
@@ -0,0 +1,29 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+class GH6731 {
+
+ public function test() {
+ $result = self::something(
+ "test {$test} test"
+ );
+ ^
+ }
+}
diff --git
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPNewLineIndenterTest.java
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPNewLineIndenterTest.java
index edf9649258..34d6cbfdf8 100644
---
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPNewLineIndenterTest.java
+++
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPNewLineIndenterTest.java
@@ -1234,6 +1234,34 @@ public class PHPNewLineIndenterTest extends PHPTestBase {
testIndentInFile("testfiles/indent/php81/enumerationsWithBackingType_03.php");
}
+ public void testGH6731_01() throws Exception {
+ testIndentInFile("testfiles/indent/gh6731_01.php");
+ }
+
+ public void testGH6731_02() throws Exception {
+ testIndentInFile("testfiles/indent/gh6731_02.php");
+ }
+
+ public void testGH6731_03() throws Exception {
+ testIndentInFile("testfiles/indent/gh6731_03.php");
+ }
+
+ public void testGH6731_04() throws Exception {
+ testIndentInFile("testfiles/indent/gh6731_04.php");
+ }
+
+ public void testGH6731_05() throws Exception {
+ testIndentInFile("testfiles/indent/gh6731_05.php");
+ }
+
+ public void testGH6731_06() throws Exception {
+ testIndentInFile("testfiles/indent/gh6731_06.php");
+ }
+
+ public void testGH6731_07() throws Exception {
+ testIndentInFile("testfiles/indent/gh6731_07.php");
+ }
+
@Override
protected boolean runInEQ() {
return true;
---------------------------------------------------------------------
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