You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by tm...@apache.org on 2020/12/06 16:50:22 UTC
[netbeans] branch master updated: [NETBEANS-5096] Fix formatting in
executable script
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 466d94b [NETBEANS-5096] Fix formatting in executable script
new a64fefc Merge pull request #2581 from KacerCZ/netbeans-5096-fix-script-format
466d94b is described below
commit 466d94bd0bd51282ae6fcf407dc9c36b67572fce
Author: Tomas Prochazka <ka...@razdva.cz>
AuthorDate: Sat Dec 5 13:07:01 2020 +0100
[NETBEANS-5096] Fix formatting in executable script
https://issues.apache.org/jira/browse/NETBEANS-5096
Fixes blank lines formatting after open tag in script starting with shebang.
Setting for "After Open Tag" is applied instead of "After Open Tag in HTML".
Sample script:
```php
<?php
echo "Hello World!\n";
```
---
.../src/org/netbeans/modules/php/editor/indent/FormatVisitor.java | 6 +++++-
.../unit/data/testfiles/formatting/blankLines/OpenClosePHPTag06.php | 6 ++++++
.../testfiles/formatting/blankLines/OpenClosePHPTag06.php.formatted | 4 ++++
.../modules/php/editor/indent/PHPFormatterBlankLinesTest.java | 5 +++++
4 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java
index eb408c3..9172ede 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java
@@ -2292,7 +2292,7 @@ public class FormatVisitor extends DefaultVisitor {
break;
case T_INLINE_HTML:
FormatToken.InitToken token = (FormatToken.InitToken) formatTokens.get(0);
- if (!token.hasHTML() && !isWhitespace(ts.token().text())) {
+ if (!token.hasHTML() && !isWhitespace(ts.token().text()) && !isShebang(ts.token().text())) {
token.setHasHTML(true);
}
int tokenStartOffset = ts.offset();
@@ -2718,6 +2718,10 @@ public class FormatVisitor extends DefaultVisitor {
return index == text.length();
}
+ private boolean isShebang(final CharSequence text) {
+ return TokenUtilities.startsWith(text, "#!"); //NOI18N
+ }
+
private static boolean isAnonymousClass(ASTNode astNode) {
return astNode instanceof ClassInstanceCreation && ((ClassInstanceCreation) astNode).isAnonymous();
}
diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/OpenClosePHPTag06.php b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/OpenClosePHPTag06.php
new file mode 100644
index 0000000..85c88f6
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/OpenClosePHPTag06.php
@@ -0,0 +1,6 @@
+#!/usr/bin/php
+<?php
+
+
+
+echo "Hello World!\n";
diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/OpenClosePHPTag06.php.formatted b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/OpenClosePHPTag06.php.formatted
new file mode 100644
index 0000000..7d09ee6
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/OpenClosePHPTag06.php.formatted
@@ -0,0 +1,4 @@
+#!/usr/bin/php
+<?php
+
+echo "Hello World!\n";
diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java
index 9c19b6e..6547266 100644
--- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java
+++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java
@@ -1033,6 +1033,11 @@ public class PHPFormatterBlankLinesTest extends PHPFormatterTestBase {
reformatFileContents("testfiles/formatting/blankLines/OpenClosePHPTag05.php", options);
}
+ public void testOpenClosePHPTag06() throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>(FmtOptions.getDefaults());
+ reformatFileContents("testfiles/formatting/blankLines/OpenClosePHPTag06.php", options);
+ }
+
public void testMaxPreservedBlankLines01() throws Exception {
HashMap<String, Object> options = new HashMap<String, Object>(FmtOptions.getDefaults());
options.put(FmtOptions.BLANK_LINES_MAX_PRESERVED, 0);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists