Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "After Use Trait" to the formatting options #4685 #6467

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public int getBlankLinesBeforeUseTrait() {
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -289,6 +290,7 @@ private static void createDefaults() {
{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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public enum Kind {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,18 @@ && isFirstUseTraitStatementInBlock(path.get(1), node)) {
}
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ protected static class DocumentOptions {
public int blankLinesAfterNamespace;
public int blankLinesBeforeUse;
public int blankLinesBeforeUseTrait;
public int blankLinesAfterUseTrait;
public int blankLinesAfterUse;
public int blankLinesBetweenUseTypes;
public int blankLinesBeforeClass;
Expand Down Expand Up @@ -320,6 +321,7 @@ public DocumentOptions(BaseDocument doc) {
blankLinesAfterNamespace = codeStyle.getBlankLinesAfterNamespace();
blankLinesBeforeUse = codeStyle.getBlankLinesBeforeUse();
blankLinesBeforeUseTrait = codeStyle.getBlankLinesBeforeUseTrait();
blankLinesAfterUseTrait = codeStyle.getBlankLinesAfterUseTrait();
blankLinesAfterUse = codeStyle.getBlankLinesAfterUse();
blankLinesBetweenUseTypes = codeStyle.getBlankLinesBetweenUseTypes();
blankLinesBeforeClass = codeStyle.getBlankLinesBeforeClass();
Expand Down Expand Up @@ -873,6 +875,10 @@ public void run() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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, &quot;{key}&quot;)"/>
</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, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
Expand Down
Loading