This is an automated email from the ASF dual-hosted git repository. junichi11 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 161f65c97d Add "After Use Trait" to the formatting options #4685 new b0fc0d628e Merge pull request #6467 from junichi11/php-formatter-after-use-trait 161f65c97d is described below commit 161f65c97dd8d9dade357bb3621453bd81a5ec68 Author: Junichi Yamamoto <junich...@apache.org> AuthorDate: Fri Sep 15 14:44:56 2023 +0900 Add "After Use Trait" to the formatting options #4685 - https://github.com/apache/netbeans/issues/4685 - Add "After Use Trait" option - Add unit tests --- .../modules/php/editor/indent/CodeStyle.java | 4 ++ .../modules/php/editor/indent/FmtOptions.java | 2 + .../modules/php/editor/indent/FormatToken.java | 1 + .../modules/php/editor/indent/FormatVisitor.java | 11 +++ .../modules/php/editor/indent/TokenFormatter.java | 6 ++ .../modules/php/editor/indent/ui/Bundle.properties | 2 + .../php/editor/indent/ui/FmtBlankLines.form | 78 +++++++++++++--------- .../php/editor/indent/ui/FmtBlankLines.java | 71 ++++++++++++-------- .../formatting/blankLines/AfterUseTrait_01.php | 52 +++++++++++++++ ...php.testAfterUseTraitHasBlankLine_01a.formatted | 57 ++++++++++++++++ ...php.testAfterUseTraitHasBlankLine_01b.formatted | 62 +++++++++++++++++ ....php.testAfterUseTraitNoBlankLine_01a.formatted | 55 +++++++++++++++ ....php.testAfterUseTraitNoBlankLine_01b.formatted | 62 +++++++++++++++++ .../editor/indent/PHPFormatterBlankLinesTest.java | 40 +++++++++++ 14 files changed, 443 insertions(+), 60 deletions(-) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java index a1ba761f73..885c6ff243 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java @@ -172,6 +172,10 @@ public final class CodeStyle { return preferences.getInt(BLANK_LINES_BEFORE_USE_TRAIT, getDefaultAsInt(BLANK_LINES_BEFORE_USE_TRAIT)); } + public int getBlankLinesAfterUseTrait() { + return preferences.getInt(BLANK_LINES_AFTER_USE_TRAIT, getDefaultAsInt(BLANK_LINES_AFTER_USE_TRAIT)); + } + public int getBlankLinesAfterUse() { return preferences.getInt(BLANK_LINES_AFTER_USE, getDefaultAsInt(BLANK_LINES_AFTER_USE)); } diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java index 24d05c20a4..5ba623e44a 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java @@ -94,6 +94,7 @@ public final class FmtOptions { public static final String BLANK_LINES_AFTER_NAMESPACE = "blankLinesAfterNamespace"; //NOI18N public static final String BLANK_LINES_BEFORE_USE = "blankLinesBeforeUse"; //NOI18N public static final String BLANK_LINES_BEFORE_USE_TRAIT = "blankLinesBeforeUseTrait"; //NOI18N + public static final String BLANK_LINES_AFTER_USE_TRAIT = "blankLinesAfterUseTrait"; //NOI18N public static final String BLANK_LINES_AFTER_USE = "blankLinesAfterUse"; //NOI18N public static final String BLANK_LINES_BETWEEN_USE_TYPES = "blankLinesBetweenUseType"; //NOI18N public static final String BLANK_LINES_BEFORE_CLASS = "blankLinesBeforeClass"; //NOI18N @@ -289,6 +290,7 @@ public final class FmtOptions { {BLANK_LINES_AFTER_NAMESPACE, "1"}, //NOI18N {BLANK_LINES_BEFORE_USE, "1"}, //NOI18N {BLANK_LINES_BEFORE_USE_TRAIT, "1"}, //NOI18N + {BLANK_LINES_AFTER_USE_TRAIT, "1"}, //NOI18N {BLANK_LINES_AFTER_USE, "1"}, //NOI18N {BLANK_LINES_BETWEEN_USE_TYPES, "0"}, //NOI18N {BLANK_LINES_BEFORE_CLASS, "1"}, //NOI18N diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java index 4f464a826f..ec0d6cda7f 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java @@ -103,6 +103,7 @@ public class FormatToken { WHITESPACE_BEFORE_OTHER_RIGHT_BRACE, WHITESPACE_BEFORE_USES_PART, WHITESPACE_BEFORE_USE_TRAIT, + WHITESPACE_AFTER_USE_TRAIT, WHITESPACE_BEFORE_USE_TRAIT_PART, WHITESPACE_BEFORE_USE_TRAIT_BODY_LEFT_BRACE, WHITESPACE_BEFORE_USE_TRAIT_BODY_RIGHT_BRACE, 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 00a727a56e..c03939e031 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 @@ -2362,7 +2362,18 @@ public class FormatVisitor extends DefaultVisitor { } includeWSBeforePHPDoc = true; isFirstUseTraitStatementPart = true; + Block block = (Block) path.get(1); + int index = 0; + List<Statement> statements = block.getStatements(); super.visit(node); + while (index < statements.size() && statements.get(index).getStartOffset() < node.getStartOffset()) { + index++; + } + if (index == statements.size() - 1 + || ((index < statements.size() - 1) && !(statements.get(index + 1) instanceof UseTraitStatement))) { + addRestOfLine(); + formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_AFTER_USE_TRAIT, ts.offset() + ts.token().length())); + } } @Override diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java index 0d4e9a41a9..c8ac89f817 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java @@ -152,6 +152,7 @@ public class TokenFormatter { public int blankLinesAfterNamespace; public int blankLinesBeforeUse; public int blankLinesBeforeUseTrait; + public int blankLinesAfterUseTrait; public int blankLinesAfterUse; public int blankLinesBetweenUseTypes; public int blankLinesBeforeClass; @@ -320,6 +321,7 @@ public class TokenFormatter { blankLinesAfterNamespace = codeStyle.getBlankLinesAfterNamespace(); blankLinesBeforeUse = codeStyle.getBlankLinesBeforeUse(); blankLinesBeforeUseTrait = codeStyle.getBlankLinesBeforeUseTrait(); + blankLinesAfterUseTrait = codeStyle.getBlankLinesAfterUseTrait(); blankLinesAfterUse = codeStyle.getBlankLinesAfterUse(); blankLinesBetweenUseTypes = codeStyle.getBlankLinesBetweenUseTypes(); blankLinesBeforeClass = codeStyle.getBlankLinesBeforeClass(); @@ -873,6 +875,10 @@ public class TokenFormatter { indentRule = true; newLines = docOptions.blankLinesBeforeUseTrait + 1; break; + case WHITESPACE_AFTER_USE_TRAIT: + indentRule = true; + newLines = docOptions.blankLinesAfterUseTrait + 1; + break; case WHITESPACE_BEFORE_USE_TRAIT_PART: indentRule = true; if (formatTokens.get(index - 1).getId() == FormatToken.Kind.ANCHOR) { diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties index 60f568d079..328edd2866 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties @@ -456,3 +456,5 @@ FmtBlankLines.betweenUseTypesField.text= FmtBlankLines.endOfFileCheckBox.text=En&d of File FmtUses.putInPSR12OrderCheckBox.text=Put in PSR-12 &Order FmtUses.keepExistingUseTypeOrderCheckBox.text=&Keep Existing Order of Use Types(types, functions, constants) If Possible +FmtBlankLines.afterUseTraitLabel.text=After U&se Trait: +FmtBlankLines.afterUseTraitTextField.text= diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.form b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.form index bf1de5ceda..8485967c6a 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.form +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.form @@ -116,42 +116,39 @@ <Component id="bNamespaceLabel" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="bUseTraitLabel" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="maxPreservedBlankLabel" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="afterUseTraitLabel" alignment="0" min="-2" max="-2" attributes="0"/> </Group> + <EmptySpace min="12" pref="12" max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <EmptySpace min="-2" pref="12" max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="103" alignment="0" groupAlignment="1" max="-2" attributes="0"> - <Component id="aMethodsField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="bMethodsField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="aFieldsField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="bFunctionEndField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="betweenFields" linkSize="1" alignment="0" max="32767" attributes="1"/> - <Component id="bFieldsField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="aClassField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="bClassEndField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="aClassHeaderField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="bClassField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="aUseField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="bUseField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="aNamespaceField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="bNamespaceField" linkSize="1" alignment="0" max="32767" attributes="3"/> - <Component id="betweenUseTypesField" alignment="0" max="32767" attributes="0"/> - </Group> - <Component id="aOpenPHPTagField" linkSize="1" min="-2" max="-2" attributes="3"/> - <Group type="103" alignment="1" groupAlignment="0" max="-2" attributes="0"> - <Component id="bClosePHPTagField" linkSize="1" alignment="0" min="-2" max="-2" attributes="3"/> - <Component id="aOpenPHPTagHTMLField" linkSize="1" alignment="0" min="-2" max="-2" attributes="3"/> - </Group> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="103" alignment="0" groupAlignment="1" max="-2" attributes="0"> + <Component id="aMethodsField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="bMethodsField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="aFieldsField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="bFunctionEndField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="betweenFields" linkSize="1" alignment="0" max="32767" attributes="1"/> + <Component id="bFieldsField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="aClassField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="bClassEndField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="aClassHeaderField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="bClassField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="aUseField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="bUseField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="aNamespaceField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="bNamespaceField" linkSize="1" alignment="0" max="32767" attributes="3"/> + <Component id="betweenUseTypesField" alignment="0" max="32767" attributes="0"/> </Group> - </Group> - <Group type="102" alignment="1" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" max="-2" attributes="0"> - <Component id="maxPreservedBlankField" max="32767" attributes="0"/> - <Component id="bUseTraitField" linkSize="1" max="32767" attributes="0"/> + <Component id="aOpenPHPTagField" linkSize="1" min="-2" max="-2" attributes="3"/> + <Group type="103" alignment="1" groupAlignment="0" max="-2" attributes="0"> + <Component id="bClosePHPTagField" linkSize="1" alignment="0" min="-2" max="-2" attributes="3"/> + <Component id="aOpenPHPTagHTMLField" linkSize="1" alignment="0" min="-2" max="-2" attributes="3"/> </Group> </Group> + <Group type="103" alignment="1" groupAlignment="0" max="-2" attributes="0"> + <Component id="maxPreservedBlankField" max="32767" attributes="0"/> + <Component id="bUseTraitField" linkSize="1" alignment="0" max="32767" attributes="0"/> + <Component id="afterUseTraitTextField" alignment="0" max="32767" attributes="0"/> + </Group> </Group> </Group> <Component id="cbGroupFields" alignment="0" min="-2" max="-2" attributes="0"/> @@ -261,6 +258,11 @@ <Component id="bUseTraitLabel" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="afterUseTraitLabel" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="afterUseTraitTextField" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="maxPreservedBlankLabel" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="maxPreservedBlankField" alignment="3" min="-2" max="-2" attributes="0"/> @@ -816,6 +818,20 @@ </Property> </Properties> </Component> + <Component class="javax.swing.JLabel" name="afterUseTraitLabel"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/php/editor/indent/ui/Bundle.properties" key="FmtBlankLines.afterUseTraitLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="afterUseTraitTextField"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/php/editor/indent/ui/Bundle.properties" key="FmtBlankLines.afterUseTraitTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + </Properties> + </Component> </SubComponents> </Container> </SubComponents> diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.java index a820aa09b1..8f76fd205c 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBlankLines.java @@ -60,6 +60,7 @@ public class FmtBlankLines extends javax.swing.JPanel { aUseField.putClientProperty(OPTION_ID, BLANK_LINES_AFTER_USE); betweenUseTypesField.putClientProperty(OPTION_ID, BLANK_LINES_BETWEEN_USE_TYPES); bUseTraitField.putClientProperty(OPTION_ID, BLANK_LINES_BEFORE_USE_TRAIT); + afterUseTraitTextField.putClientProperty(OPTION_ID, BLANK_LINES_AFTER_USE_TRAIT); bClassField.putClientProperty(OPTION_ID, BLANK_LINES_BEFORE_CLASS); aClassField.putClientProperty(OPTION_ID, BLANK_LINES_AFTER_CLASS); aClassHeaderField.putClientProperty(OPTION_ID, BLANK_LINES_AFTER_CLASS_HEADER); @@ -83,6 +84,7 @@ public class FmtBlankLines extends javax.swing.JPanel { aUseField.addKeyListener(new NumericKeyListener()); betweenUseTypesField.addKeyListener(new NumericKeyListener()); bUseTraitField.addKeyListener(new NumericKeyListener()); + afterUseTraitTextField.addKeyListener(new NumericKeyListener()); bClassField.addKeyListener(new NumericKeyListener()); aClassField.addKeyListener(new NumericKeyListener()); bClassEndField.addKeyListener(new NumericKeyListener()); @@ -164,6 +166,8 @@ public class FmtBlankLines extends javax.swing.JPanel { betweenUseTypesLabel = new JLabel(); betweenUseTypesField = new JTextField(); endOfFileCheckBox = new JCheckBox(); + afterUseTraitLabel = new JLabel(); + afterUseTraitTextField = new JTextField(); setName(NbBundle.getMessage(FmtBlankLines.class, "LBL_BlankLines")); // NOI18N setOpaque(false); @@ -270,6 +274,10 @@ public class FmtBlankLines extends javax.swing.JPanel { Mnemonics.setLocalizedText(endOfFileCheckBox, NbBundle.getMessage(FmtBlankLines.class, "FmtBlankLines.endOfFileCheckBox.text")); // NOI18N + Mnemonics.setLocalizedText(afterUseTraitLabel, NbBundle.getMessage(FmtBlankLines.class, "FmtBlankLines.afterUseTraitLabel.text")); // NOI18N + + afterUseTraitTextField.setText(NbBundle.getMessage(FmtBlankLines.class, "FmtBlankLines.afterUseTraitTextField.text")); // NOI18N + GroupLayout jPanel1Layout = new GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -298,36 +306,35 @@ public class FmtBlankLines extends javax.swing.JPanel { .addComponent(aNamespaceLabel) .addComponent(bNamespaceLabel) .addComponent(bUseTraitLabel) - .addComponent(maxPreservedBlankLabel)) + .addComponent(maxPreservedBlankLabel) + .addComponent(afterUseTraitLabel)) + .addGap(12, 12, 12) .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(12, 12, 12) - .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false) - .addComponent(aMethodsField, GroupLayout.Alignment.LEADING) - .addComponent(bMethodsField, GroupLayout.Alignment.LEADING) - .addComponent(aFieldsField, GroupLayout.Alignment.LEADING) - .addComponent(bFunctionEndField, GroupLayout.Alignment.LEADING) - .addComponent(betweenFields, GroupLayout.Alignment.LEADING) - .addComponent(bFieldsField, GroupLayout.Alignment.LEADING) - .addComponent(aClassField, GroupLayout.Alignment.LEADING) - .addComponent(bClassEndField, GroupLayout.Alignment.LEADING) - .addComponent(aClassHeaderField, GroupLayout.Alignment.LEADING) - .addComponent(bClassField, GroupLayout.Alignment.LEADING) - .addComponent(aUseField, GroupLayout.Alignment.LEADING) - .addComponent(bUseField, GroupLayout.Alignment.LEADING) - .addComponent(aNamespaceField, GroupLayout.Alignment.LEADING) - .addComponent(bNamespaceField, GroupLayout.Alignment.LEADING) - .addComponent(betweenUseTypesField, GroupLayout.Alignment.LEADING)) - .addComponent(aOpenPHPTagField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) - .addComponent(bClosePHPTagField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(aOpenPHPTagHTMLField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))) - .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) - .addComponent(maxPreservedBlankField) - .addComponent(bUseTraitField))))) + .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false) + .addComponent(aMethodsField, GroupLayout.Alignment.LEADING) + .addComponent(bMethodsField, GroupLayout.Alignment.LEADING) + .addComponent(aFieldsField, GroupLayout.Alignment.LEADING) + .addComponent(bFunctionEndField, GroupLayout.Alignment.LEADING) + .addComponent(betweenFields, GroupLayout.Alignment.LEADING) + .addComponent(bFieldsField, GroupLayout.Alignment.LEADING) + .addComponent(aClassField, GroupLayout.Alignment.LEADING) + .addComponent(bClassEndField, GroupLayout.Alignment.LEADING) + .addComponent(aClassHeaderField, GroupLayout.Alignment.LEADING) + .addComponent(bClassField, GroupLayout.Alignment.LEADING) + .addComponent(aUseField, GroupLayout.Alignment.LEADING) + .addComponent(bUseField, GroupLayout.Alignment.LEADING) + .addComponent(aNamespaceField, GroupLayout.Alignment.LEADING) + .addComponent(bNamespaceField, GroupLayout.Alignment.LEADING) + .addComponent(betweenUseTypesField, GroupLayout.Alignment.LEADING)) + .addComponent(aOpenPHPTagField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) + .addComponent(bClosePHPTagField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(aOpenPHPTagHTMLField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) + .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) + .addComponent(maxPreservedBlankField) + .addComponent(bUseTraitField) + .addComponent(afterUseTraitTextField)))) .addComponent(cbGroupFields, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(betweenUseTypesLabel) .addComponent(endOfFileCheckBox)) @@ -415,6 +422,10 @@ public class FmtBlankLines extends javax.swing.JPanel { .addComponent(bUseTraitField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(bUseTraitLabel)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(afterUseTraitLabel) + .addComponent(afterUseTraitTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(maxPreservedBlankLabel) .addComponent(maxPreservedBlankField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) @@ -512,6 +523,8 @@ public class FmtBlankLines extends javax.swing.JPanel { private JLabel aOpenPHPTagLebel; private JTextField aUseField; private JLabel aUseLabel; + private JLabel afterUseTraitLabel; + private JTextField afterUseTraitTextField; private JTextField bClassEndField; private JLabel bClassEndLabel; private JTextField bClassField; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php new file mode 100644 index 0000000000..c389fa74a7 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php @@ -0,0 +1,52 @@ +<?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 AfterUseTrait { + use Trait1; + use Trait2; + + public function test() { + + } +} + +class AfterUseTraitWithProperties { + use Trait1; + private int $int = 1; + private const CONSTANT1 = "CONSTANT1"; + public function foobar() { + + } +} + +class AfterUseTraitOnlyUseTrait { + use Trait1; +} + +class AfterUseTraitOnlyProperties { + private int $int = 1; + private const CONSTANT1 = "CONSTANT1"; +} + +class AfterUseTraitOnlyMethod { + public function foobar() { + + } +} diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitHasBlankLine_01a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitHasBlankLine_01a.formatted new file mode 100644 index 0000000000..824d471df5 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitHasBlankLine_01a.formatted @@ -0,0 +1,57 @@ +<?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 AfterUseTrait { + use Trait1; + use Trait2; + + public function test() { + + } +} + +class AfterUseTraitWithProperties { + use Trait1; + + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; + + public function foobar() { + + } +} + +class AfterUseTraitOnlyUseTrait { + use Trait1; +} + +class AfterUseTraitOnlyProperties { + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; +} + +class AfterUseTraitOnlyMethod { + public function foobar() { + + } +} diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitHasBlankLine_01b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitHasBlankLine_01b.formatted new file mode 100644 index 0000000000..f7f823f78d --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitHasBlankLine_01b.formatted @@ -0,0 +1,62 @@ +<?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 AfterUseTrait { + + use Trait1; + use Trait2; + + public function test() { + + } +} + +class AfterUseTraitWithProperties { + + use Trait1; + + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; + + public function foobar() { + + } +} + +class AfterUseTraitOnlyUseTrait { + + use Trait1; +} + +class AfterUseTraitOnlyProperties { + + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; +} + +class AfterUseTraitOnlyMethod { + + public function foobar() { + + } +} diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitNoBlankLine_01a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitNoBlankLine_01a.formatted new file mode 100644 index 0000000000..7f3c77ed6f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitNoBlankLine_01a.formatted @@ -0,0 +1,55 @@ +<?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 AfterUseTrait { + use Trait1; + use Trait2; + public function test() { + + } +} + +class AfterUseTraitWithProperties { + use Trait1; + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; + + public function foobar() { + + } +} + +class AfterUseTraitOnlyUseTrait { + use Trait1; +} + +class AfterUseTraitOnlyProperties { + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; +} + +class AfterUseTraitOnlyMethod { + public function foobar() { + + } +} diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitNoBlankLine_01b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitNoBlankLine_01b.formatted new file mode 100644 index 0000000000..f7f823f78d --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/AfterUseTrait_01.php.testAfterUseTraitNoBlankLine_01b.formatted @@ -0,0 +1,62 @@ +<?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 AfterUseTrait { + + use Trait1; + use Trait2; + + public function test() { + + } +} + +class AfterUseTraitWithProperties { + + use Trait1; + + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; + + public function foobar() { + + } +} + +class AfterUseTraitOnlyUseTrait { + + use Trait1; +} + +class AfterUseTraitOnlyProperties { + + private int $int = 1; + + private const CONSTANT1 = "CONSTANT1"; +} + +class AfterUseTraitOnlyMethod { + + public function foobar() { + + } +} 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 993d745301..a613f2c1e2 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 @@ -1995,4 +1995,44 @@ public class PHPFormatterBlankLinesTest extends PHPFormatterTestBase { reformatFileContents("testfiles/formatting/blankLines/issueGH4609BetweenUseTypes_03.php", options, false, true); } + public void testAfterUseTraitHasBlankLine_01a() throws Exception { + // GH-4685 + HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE_TRAIT, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE_TRAIT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + reformatFileContents("testfiles/formatting/blankLines/AfterUseTrait_01.php", options, false, true); + } + + public void testAfterUseTraitHasBlankLine_01b() throws Exception { + // GH-4685 + HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE_TRAIT, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE_TRAIT,1); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 1); + reformatFileContents("testfiles/formatting/blankLines/AfterUseTrait_01.php", options, false, true); + } + + public void testAfterUseTraitNoBlankLine_01a() throws Exception { + // GH-4685 + HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE_TRAIT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE_TRAIT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + reformatFileContents("testfiles/formatting/blankLines/AfterUseTrait_01.php", options, false, true); + } + + public void testAfterUseTraitNoBlankLine_01b() throws Exception { + // GH-4685 + HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE_TRAIT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE_TRAIT, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 1); + reformatFileContents("testfiles/formatting/blankLines/AfterUseTrait_01.php", options, false, 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