From 0737cced687ac7ed8ad5ab43523408909a1125a4 Mon Sep 17 00:00:00 2001 From: Junichi Yamamoto Date: Wed, 27 Dec 2023 14:13:58 +0900 Subject: [PATCH] Formatting for the group multiline alignment for match arm arrows #6074 - https://github.com/apache/netbeans/issues/6074 - Add "Match Arm Arrow" as an alignment option - Add/Fix unit tests Example: ```php match ($type1) { 'integer', 'test' => 'test', 'string' => match ($type2) { 1, 2 => "test", 3 => "test", 4 => "test", }, default => null, }; ``` Result: ```php match ($type1) { 'integer', 'test' => 'test', 'string' => match ($type2) { 1, 2 => "test", 3 => "test", 4 => "test", }, default => null, }; ``` --- .../modules/php/editor/indent/CodeStyle.java | 8 +- .../modules/php/editor/indent/FmtOptions.java | 2 + .../php/editor/indent/FormatToken.java | 21 +- .../php/editor/indent/FormatVisitor.java | 117 +++++++++- .../php/editor/indent/TokenFormatter.java | 151 ++++++++----- .../php/editor/indent/ui/Bundle.properties | 1 + .../php/editor/indent/ui/FmtAlignment.form | 187 ++++++++-------- .../php/editor/indent/ui/FmtAlignment.java | 166 +++++++------- .../modules/php/editor/indent/ui/Spaces.php | 6 +- .../groupAlignmentMatchArmArrow_01.php | 209 ++++++++++++++++++ ...AlignmentMatchArmArrow_Spaces01a.formatted | 207 +++++++++++++++++ ...AlignmentMatchArmArrow_Spaces01b.formatted | 207 +++++++++++++++++ ...gnmentMatchArmArrow_Tab01_Size4a.formatted | 207 +++++++++++++++++ ...gnmentMatchArmArrow_Tab01_Size4b.formatted | 207 +++++++++++++++++ ...gnmentMatchArmArrow_Tab01_Size8a.formatted | 207 +++++++++++++++++ ...gnmentMatchArmArrow_Tab01_Size8b.formatted | 207 +++++++++++++++++ .../groupAlignmentMatchArmArrow_02.php | 91 ++++++++ ...AlignmentMatchArmArrow_Spaces02a.formatted | 91 ++++++++ ...AlignmentMatchArmArrow_Spaces02b.formatted | 91 ++++++++ ...AlignmentMatchArmArrow_Spaces02c.formatted | 91 ++++++++ ...AlignmentMatchArmArrow_Spaces02d.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size4a.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size4b.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size4c.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size4d.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size8a.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size8b.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size8c.formatted | 91 ++++++++ ...gnmentMatchArmArrow_Tab02_Size8d.formatted | 91 ++++++++ .../alignment/issue210617.php.formatted | 122 +++++----- ...617.php.testIssue210617_TabSize8.formatted | 118 ++++++++++ .../indent/PHPFormatterAlignmentTest.java | 179 +++++++++++++++ .../editor/indent/PHPFormatterSpacesTest.java | 12 + 33 files changed, 3432 insertions(+), 292 deletions(-) create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01a.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01b.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4a.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4b.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8a.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8b.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02a.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02b.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02c.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02d.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4a.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4b.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4c.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4d.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8a.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8b.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8c.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8d.formatted create mode 100644 php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.testIssue210617_TabSize8.formatted 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 6647f612a703..78d3e9de7dc5 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 @@ -576,14 +576,18 @@ public boolean placeNewLineAfterModifiers() { return preferences.getBoolean(PLACE_NEW_LINE_AFTER_MODIFIERS, getDefaultAsBoolean(PLACE_NEW_LINE_AFTER_MODIFIERS)); } - public boolean groupMulitlineAssignment() { + public boolean groupMultilineAssignment() { return preferences.getBoolean(GROUP_ALIGNMENT_ASSIGNMENT, getDefaultAsBoolean(GROUP_ALIGNMENT_ASSIGNMENT)); } - public boolean groupMulitlineArrayInit() { + public boolean groupMultilineArrayInit() { return preferences.getBoolean(GROUP_ALIGNMENT_ARRAY_INIT, getDefaultAsBoolean(GROUP_ALIGNMENT_ARRAY_INIT)); } + public boolean groupMultilineMatchArmArrow() { + return preferences.getBoolean(GROUP_ALIGNMENT_MATCH_ARM_ARROW, getDefaultAsBoolean(GROUP_ALIGNMENT_MATCH_ARM_ARROW)); + } + // Wrapping ---------------------------------------------------------------- public WrapStyle wrapGroupUseList() { 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 d1e405930f99..853aac8b0233 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 @@ -195,6 +195,7 @@ public final class FmtOptions { public static final String ALIGN_MULTILINE_ARRAY_INIT = "alignMultilineArrayInit"; //NOI18N public static final String GROUP_ALIGNMENT_ASSIGNMENT = "groupAlignmentAssignment"; //NOI18N public static final String GROUP_ALIGNMENT_ARRAY_INIT = "groupAlignmentArrayInit"; //NOI18N + public static final String GROUP_ALIGNMENT_MATCH_ARM_ARROW = "groupAlignmentMatchArmArrow"; //NOI18N public static final String WRAP_GROUP_USE_LIST = "wrapGroupUseList"; //NOI18N public static final String WRAP_EXTENDS_IMPLEMENTS_KEYWORD = "wrapExtendsImplementsKeyword"; //NOI18N public static final String WRAP_EXTENDS_IMPLEMENTS_LIST = "wrapExtendsImplementsList"; //NOI18N @@ -392,6 +393,7 @@ private static void createDefaults() { {PLACE_NEW_LINE_AFTER_MODIFIERS, FALSE}, //NOI18N {GROUP_ALIGNMENT_ARRAY_INIT, FALSE}, + {GROUP_ALIGNMENT_MATCH_ARM_ARROW, FALSE}, {GROUP_ALIGNMENT_ASSIGNMENT, FALSE}, {WRAP_GROUP_USE_LIST, WRAP_ALWAYS}, {WRAP_EXTENDS_IMPLEMENTS_KEYWORD, WRAP_NEVER}, //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 727f8f968661..fdd1027af2c4 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 @@ -297,6 +297,12 @@ public void setAnchorColumn(int column) { */ public static class AssignmentAnchorToken extends FormatToken { + public enum Type { + ASSIGNMENT, // "=" + ARRAY, // "=>" + MATCH_ARM, // "=>" + } + /** * length of the identifier that is before the aligned operator */ @@ -315,22 +321,28 @@ public static class AssignmentAnchorToken extends FormatToken { */ private AssignmentAnchorToken previous; private final boolean multilined; + private final Type type; public AssignmentAnchorToken(int offset, boolean multilined) { + this(offset, multilined, Type.ASSIGNMENT); + } + + public AssignmentAnchorToken(int offset, boolean multilined, Type type) { super(Kind.ASSIGNMENT_ANCHOR, offset); length = -1; maxLength = -1; previous = null; isInGroup = false; this.multilined = multilined; + this.type = type; } - public int getLenght() { + public int getLength() { return length; } - public void setLenght(int lenght) { - this.length = lenght; + public void setLength(int length) { + this.length = length; } public int getMaxLength() { @@ -361,6 +373,9 @@ public boolean isMultilined() { return multilined; } + public Type getType() { + return type; + } } public static class UnbreakableSequenceToken extends FormatToken { 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 19d9dcd926c5..b811e01ee062 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 @@ -35,6 +35,7 @@ import org.netbeans.editor.BaseDocument; import org.netbeans.modules.csl.api.OffsetRange; import org.netbeans.modules.csl.spi.GsfUtilities; +import org.netbeans.modules.php.editor.CodeUtils; import org.netbeans.modules.php.editor.indent.FormatToken.AssignmentAnchorToken; import org.netbeans.modules.php.editor.indent.TokenFormatter.DocumentOptions; import org.netbeans.modules.php.editor.lexer.LexUtilities; @@ -419,7 +420,7 @@ public void visit(ArrayElement node) { scan(node.getKey()); while (ts.moveNext() && ts.offset() < node.getValue().getStartOffset()) { if (isKeyValueOperator(ts.token())) { - handleGroupAlignment(node.getKey(), multilinedArray); + handleGroupAlignment(node.getKey(), multilinedArray, AssignmentAnchorToken.Type.ARRAY); } addFormatToken(formatTokens); } @@ -2245,6 +2246,7 @@ public void visit(MatchExpression node) { scan(node.getExpression()); addWhitespaceBeforeMatchLeftBraceToken(node); + createGroupAlignment(); List matchArms = node.getMatchArms(); if (!matchArms.isEmpty()) { MatchArm first = matchArms.get(0); @@ -2259,6 +2261,8 @@ public void visit(MatchExpression node) { if (disabled) { enableIndentForFunctionInvocation(node.getEndOffset()); } + addAllUntilOffset(node.getEndOffset()); + resetGroupAlignment(); } private void addWhitespaceBeforeMatchRightBraceToken(MatchExpression node) { @@ -2289,6 +2293,53 @@ private void addWhitespaceBeforeMatchLeftBraceToken(MatchExpression node) { } } + private boolean isMultilinedMatchArm(MatchExpression matchExpression, MatchArm matchArm) { + boolean result = false; + List matchArms = matchExpression.getMatchArms(); + int start = matchExpression.getStartOffset(); + for (MatchArm arm : matchArms) { + if (arm.getStartOffset() == matchArm.getStartOffset()) { + int end = arm.getStartOffset(); + try { + result = document.getText(start, end - start).contains(CodeUtils.NEW_LINE); + } catch (BadLocationException ex) { + LOGGER.log(Level.WARNING, "Invalid offset: {0}", ex.offsetRequested()); // NOI18N + } + } + start = arm.getEndOffset(); + } + return result; + } + + @Override + public void visit(MatchArm node) { + scan(node.getConditions()); + MatchExpression parentMatchExpression = getParentMatchExpression(); + boolean isMultilined = isMultilinedMatchArm(parentMatchExpression, node); + while (ts.moveNext() && ts.offset() < node.getExpression().getStartOffset()) { + if (isKeyValueOperator(ts.token())) { + List conditions = node.getConditions(); + handleGroupAlignment(conditions, isMultilined, AssignmentAnchorToken.Type.MATCH_ARM); + } + addFormatToken(formatTokens); + } + ts.movePrevious(); + scan(node.getExpression()); + } + + @CheckForNull + private MatchExpression getParentMatchExpression() { + MatchExpression result = null; + for (int i = 0; i < path.size(); i++) { + ASTNode parentInPath = path.get(i); + if (parentInPath instanceof MatchExpression) { + result = (MatchExpression) parentInPath; + break; + } + } + return result; + } + @Override public void visit(TryStatement node) { scan(node.getBody()); @@ -3284,26 +3335,49 @@ private boolean moveNext() { * the group */ private void handleGroupAlignment(int nodeLength, boolean multilined) { + handleGroupAlignment(nodeLength, multilined, AssignmentAnchorToken.Type.ASSIGNMENT); + } + + /** + * Handle group alignment. + * + * @param nodeLength the node length + * @param multilined {@code true} if it has a new line, otherwise {@code false} + * @param type the assingment type + */ + private void handleGroupAlignment(int nodeLength, boolean multilined, AssignmentAnchorToken.Type type) { if (groupAlignmentTokenHolders.isEmpty()) { createGroupAlignment(); } GroupAlignmentTokenHolder tokenHolder = groupAlignmentTokenHolders.peek(); - FormatToken.AssignmentAnchorToken previousGroupToken = tokenHolder.getToken(); + AssignmentAnchorToken previousGroupToken = tokenHolder.getToken(); if (previousGroupToken == null) { // it's the first line in the group - previousGroupToken = new FormatToken.AssignmentAnchorToken(ts.offset(), multilined); - previousGroupToken.setLenght(nodeLength); + previousGroupToken = new AssignmentAnchorToken(ts.offset(), multilined, type); + previousGroupToken.setLength(nodeLength); previousGroupToken.setMaxLength(nodeLength); } else { // it's a next line in the group. - FormatToken.AssignmentAnchorToken aaToken = new FormatToken.AssignmentAnchorToken(ts.offset(), multilined); - aaToken.setLenght(nodeLength); + AssignmentAnchorToken aaToken = new AssignmentAnchorToken(ts.offset(), multilined, type); + aaToken.setLength(nodeLength); aaToken.setPrevious(previousGroupToken); aaToken.setIsInGroup(true); if (!previousGroupToken.isInGroup()) { previousGroupToken.setIsInGroup(true); } - if (previousGroupToken.getMaxLength() < nodeLength) { + if (type == AssignmentAnchorToken.Type.MATCH_ARM) { + int maxLength = getValidMaxLength(aaToken); + previousGroupToken = aaToken; + do { + aaToken.setMaxLength(maxLength); + AssignmentAnchorToken previousToken = aaToken.getPrevious(); + if (previousToken != null + && previousToken.getMaxLength() == maxLength) { + break; + } + aaToken = previousToken; + } while (aaToken != null); + } else if (previousGroupToken.getMaxLength() < nodeLength) { // if the length of the current identifier is bigger, then is in // the group so far, change max length for all items in the group previousGroupToken = aaToken; @@ -3320,6 +3394,25 @@ private void handleGroupAlignment(int nodeLength, boolean multilined) { formatTokens.add(previousGroupToken); } + private int getValidMaxLength(FormatToken.AssignmentAnchorToken assignmentAnchorToken) { + // e.g. avoid adding extra spaces after "1" and "2" in the following case + // match ($type) { + // "1" => 1, "maxLength" => "maxLength", "2" => 2, + // } + int maxLength = assignmentAnchorToken.getLength(); + AssignmentAnchorToken aaToken = assignmentAnchorToken; + int multilinedMaxLength = -1; + do { + int length = aaToken.getLength(); + maxLength = Integer.max(maxLength, length); + if (aaToken.isMultilined()) { + multilinedMaxLength = Integer.max(multilinedMaxLength, length); + } + aaToken = aaToken.getPrevious(); + } while (aaToken != null); + return multilinedMaxLength != -1 ? multilinedMaxLength : maxLength; + } + private void handleGroupAlignment(int nodeLength) { handleGroupAlignment(nodeLength, false); } @@ -3328,8 +3421,14 @@ private void handleGroupAlignment(ASTNode node) { handleGroupAlignment(node.getEndOffset() - node.getStartOffset(), false); } - private void handleGroupAlignment(ASTNode node, boolean multilined) { - handleGroupAlignment(node.getEndOffset() - node.getStartOffset(), multilined); + private void handleGroupAlignment(ASTNode node, boolean multilined, AssignmentAnchorToken.Type type) { + handleGroupAlignment(node.getEndOffset() - node.getStartOffset(), multilined, type); + } + + private void handleGroupAlignment(List nodes, boolean multilined, AssignmentAnchorToken.Type type) { + int start = nodes.get(0).getStartOffset(); + int end = nodes.get(nodes.size() - 1).getEndOffset(); + handleGroupAlignment(end - start, multilined, type); } private void resetAndCreateGroupAlignment() { 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 f834010651c5..269ca955ed35 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 @@ -37,6 +37,7 @@ import org.netbeans.modules.csl.spi.ParserResult; import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.php.editor.CodeUtils; +import org.netbeans.modules.php.editor.indent.FormatToken.AssignmentAnchorToken; import org.netbeans.modules.php.editor.lexer.LexUtilities; import org.netbeans.modules.php.editor.lexer.PHPTokenId; import org.netbeans.modules.php.editor.parser.PHPParseResult; @@ -216,8 +217,9 @@ protected static class DocumentOptions { public boolean alignMultilineFor; // not implemented yet @org.netbeans.api.annotations.common.SuppressWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) public boolean alignMultilineArrayInit; //not implemented yet - public boolean groupMulitilineAssignment; - public boolean groupMulitilineArrayInit; + public boolean groupMultilineAssignment; + public boolean groupMultilineArrayInit; + public boolean groupMultilineMatchArmArrow; boolean wrapNeverKeepLines = Boolean.getBoolean("nb.php.editor.formatting.never.keep.lines"); // NOI18N @@ -382,8 +384,9 @@ public DocumentOptions(BaseDocument doc) { alignMultilineAssignment = codeStyle.alignMultilineAssignment(); alignMultilineFor = codeStyle.alignMultilineFor(); alignMultilineArrayInit = codeStyle.alignMultilineArrayInit(); - groupMulitilineArrayInit = codeStyle.groupMulitlineArrayInit(); - groupMulitilineAssignment = codeStyle.groupMulitlineAssignment(); + groupMultilineArrayInit = codeStyle.groupMultilineArrayInit(); + groupMultilineMatchArmArrow = codeStyle.groupMultilineMatchArmArrow(); + groupMultilineAssignment = codeStyle.groupMultilineAssignment(); } } @@ -1199,12 +1202,17 @@ public void run() { case WHITESPACE_BEFORE_ASSIGN_OP: indentRule = true; countSpaces = 0; - if (index > 0 && docOptions.groupMulitilineAssignment + boolean addSpaceBeforeAssign = true; + if (index > 0 && docOptions.groupMultilineAssignment && formatTokens.get(index - 1).getId() == FormatToken.Kind.ASSIGNMENT_ANCHOR) { FormatToken.AssignmentAnchorToken aaToken = (FormatToken.AssignmentAnchorToken) formatTokens.get(index - 1); + // space of options is added if the token is grouped and tab is not expanded countSpaces = new SpacesCounter(docOptions).count(aaToken); + addSpaceBeforeAssign = addSpaceAroundAssignment(aaToken, docOptions); + } + if (addSpaceBeforeAssign) { + countSpaces += (docOptions.spaceAroundAssignOps ? 1 : 0); } - countSpaces = countSpaces + (docOptions.spaceAroundAssignOps ? 1 : 0); newLines = 0; if (!docOptions.wrapAfterAssignOps) { switch (docOptions.wrapAssignOps) { @@ -1228,12 +1236,17 @@ public void run() { case WHITESPACE_AFTER_ASSIGN_OP: indentRule = true; countSpaces = 0; - if (index > 0 && docOptions.groupMulitilineAssignment + boolean addSpaceAfterAssign = true; + if (index > 0 && docOptions.groupMultilineAssignment && formatTokens.get(index - 1).getId() == FormatToken.Kind.ASSIGNMENT_ANCHOR) { FormatToken.AssignmentAnchorToken aaToken = (FormatToken.AssignmentAnchorToken) formatTokens.get(index - 1); + // space of options is added if the token is grouped and tab is not expanded countSpaces = new SpacesCounter(docOptions).count(aaToken); + addSpaceAfterAssign = addSpaceAroundAssignment(aaToken, docOptions); + } + if (addSpaceAfterAssign) { + countSpaces += (docOptions.spaceAroundAssignOps ? 1 : 0); } - countSpaces = countSpaces + (docOptions.spaceAroundAssignOps ? 1 : 0); newLines = 0; if (docOptions.wrapAfterAssignOps) { switch (docOptions.wrapAssignOps) { @@ -1256,14 +1269,30 @@ public void run() { break; case WHITESPACE_AROUND_KEY_VALUE_OP: countSpaces = 0; - FormatToken lastToken = formatTokens.get(index - 1); - if (index > 0 && docOptions.groupMulitilineArrayInit && lastToken.getId() == FormatToken.Kind.ASSIGNMENT_ANCHOR) { - FormatToken.AssignmentAnchorToken anchorToken = (FormatToken.AssignmentAnchorToken) lastToken; - if (docOptions.wrapArrayInit == CodeStyle.WrapStyle.WRAP_ALWAYS || anchorToken.isMultilined()) { - countSpaces = new SpacesCounter(docOptions).count(anchorToken); + FormatToken lastToken = null; + if (index > 0) { + lastToken = formatTokens.get(index - 1); + } + boolean addSpaceAroundKeyValue = true; + if (lastToken != null && lastToken.getId() == FormatToken.Kind.ASSIGNMENT_ANCHOR) { + AssignmentAnchorToken anchorToken = (AssignmentAnchorToken) lastToken; + if (anchorToken.getType() == AssignmentAnchorToken.Type.ARRAY && docOptions.groupMultilineArrayInit) { + if (docOptions.wrapArrayInit == CodeStyle.WrapStyle.WRAP_ALWAYS || anchorToken.isMultilined()) { + // space of options is added if the token is grouped and tab is not expanded + countSpaces = new SpacesCounter(docOptions).count(anchorToken); + addSpaceAroundKeyValue = addSpaceAroundAssignment(anchorToken, docOptions); + } + } else if (anchorToken.getType() == AssignmentAnchorToken.Type.MATCH_ARM && docOptions.groupMultilineMatchArmArrow) { + if (anchorToken.isMultilined()) { + // space of options is added if the token is grouped and tab is not expanded + countSpaces = new SpacesCounter(docOptions).count(anchorToken); + addSpaceAroundKeyValue = addSpaceAroundAssignment(anchorToken, docOptions); + } } } - countSpaces = countSpaces + (docOptions.spaceAroundKeyValueOps ? 1 : 0); + if (addSpaceAroundKeyValue) { + countSpaces += docOptions.spaceAroundKeyValueOps ? 1 : 0; + } break; case WHITESPACE_BEFORE_ANONYMOUS_CLASS_PAREN: countSpaces = docOptions.spaceBeforeAnonymousClassParen ? 1 : 0; @@ -3184,6 +3213,10 @@ private String getLineEndings(BaseDocument document) { return lineEndings; } + private boolean addSpaceAroundAssignment(AssignmentAnchorToken token, DocumentOptions docOption) { + return docOption.expandTabsToSpaces || !token.isInGroup(); + } + private static final class SpacesCounter { private final DocumentOptions documentOptions; @@ -3202,7 +3235,7 @@ public int count(final FormatToken.AssignmentAnchorToken token) { private int countSpacesForGroupedToken(final FormatToken.AssignmentAnchorToken token) { int spaces; if (documentOptions.expandTabsToSpaces) { - spaces = token.getMaxLength() - token.getLenght(); + spaces = token.getMaxLength() - token.getLength(); } else { spaces = countSpacesWhenNotExpandingTabs(token); } @@ -3211,53 +3244,71 @@ private int countSpacesForGroupedToken(final FormatToken.AssignmentAnchorToken t private int countSpacesWhenNotExpandingTabs(final FormatToken.AssignmentAnchorToken token) { int spaces; + int spaceAroundAssignment = getSpaceAroundAssignment(token); + // consider also the space around assinment here + // to avoid adding extra spaces before assignment + final int maxLength = token.getMaxLength() + spaceAroundAssignment; + final int tokenLength = token.getLength(); // 1 tabSize will be reduced to tabWidthToComplete... - int tabWidthToCompleteMaxLengthToTab = documentOptions.tabSize - (token.getMaxLength() % documentOptions.tabSize); - int tabWidthToCompleteLengthToTab = documentOptions.tabSize - (token.getLenght() % documentOptions.tabSize); - if (tabWidthToCompleteMaxLengthToTab == documentOptions.tabSize) { - // the biggest item of the group doesn't have to be expanded by one Tab - tabWidthToCompleteMaxLengthToTab = 0; - } + int tabWidthToCompleteLengthToTab = documentOptions.tabSize - (tokenLength % documentOptions.tabSize); if (tabWidthToCompleteLengthToTab == documentOptions.tabSize) { // current item is on the Tab offset tabWidthToCompleteLengthToTab = 0; } + boolean hasIncompleteTab = tabWidthToCompleteLengthToTab != 0; - if (token.getLenght() == token.getMaxLength()) { - spaces = countSpacesForBiggestItem(tabWidthToCompleteLengthToTab); - } else { - spaces = countSpacesForCommonItem(token, tabWidthToCompleteLengthToTab, tabWidthToCompleteMaxLengthToTab); - } - return spaces; - } - - private int countSpacesForBiggestItem(final int tabWidthToCompleteLengthToTab) { - int spaces = 0; - if (tabWidthToCompleteLengthToTab != 0) { - // and this biggest item has to be expanded by one tab - spaces = documentOptions.tabSize; - } - return spaces; - } - - private int countSpacesForCommonItem(final FormatToken.AssignmentAnchorToken token, final int tabWidthToCompleteLengthToTab, final int tabWidthToCompleteMaxLengthToTab) { - int spaces; - if (tabWidthToCompleteMaxLengthToTab == 0) { - if (tabWidthToCompleteLengthToTab == 0) { - spaces = token.getMaxLength() - token.getLenght(); - } else { - spaces = (token.getMaxLength() - token.getLenght()) - tabWidthToCompleteLengthToTab + documentOptions.tabSize; - } + if (tokenLength == token.getMaxLength()) { + spaces = spaceAroundAssignment; } else { - if (tabWidthToCompleteLengthToTab == 0) { - spaces = (token.getMaxLength() + tabWidthToCompleteMaxLengthToTab) - token.getLenght(); + spaces = maxLength - tabWidthToCompleteLengthToTab - tokenLength; + // e.g. tab size: 4, spaceAroundKeyValueOps: true + // match ($cond) { + // 666666 => 6, + // 22 => 2, + // }; + // 666666 => + // ^^^^^^^ + // maxLength = 7 + // 22 + // ^^ + // tabWidthToCompleteLengthToTab = 2 (has incomplete tab, i.e. must add 4(tab size) instead of 2) + // ^^ + // tokenLength = 2 + // 666666 => + // 22 + // ^^^ + // spaces = 3 = 7 - 2 - 2 + if (spaces < 0) { + // e.g. tab size: 4, spaceAroundKeyValueOps: true, spaces = -1 + // in this case, add maxLength - tokenLength = 2 + // match ($cond) { + // 22 => 1, // max length = 3 + // 1 => 0, // tabWidthToCompleteLengthToTab = 3, token length = 1 + // }; + spaces = maxLength - tokenLength; } else { - spaces = (token.getMaxLength() + tabWidthToCompleteMaxLengthToTab) - (token.getLenght() + tabWidthToCompleteLengthToTab) + documentOptions.tabSize; + if (hasIncompleteTab) { + spaces += documentOptions.tabSize; + } } } return spaces; } + private int getSpaceAroundAssignment(AssignmentAnchorToken token) { + int space = 0; + switch (token.getType()) { + case ARRAY: // no break + case MATCH_ARM: + space = documentOptions.spaceAroundKeyValueOps ? 1 : 0; + break; + case ASSIGNMENT: + space = documentOptions.spaceAroundAssignOps ? 1 : 0; + break; + default: + assert false : "Unhandled AssignmentAnchorToken.Type: " + token.getType(); // NOI18N + } + return space; + } } - } 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 5da9cc8ba00b..316932a3286b 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 @@ -459,3 +459,4 @@ 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= +FmtAlignment.gmlMatchArmArrowCheckBox.text=Match Arm Arro&w diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.form b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.form index f711f4359b2d..dc4cd9c3901d 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.form +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.form @@ -54,69 +54,82 @@ + + + + + + - + - - - - - - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - + + + - - - - - @@ -127,30 +140,25 @@ - - - - - - - - - - - - - + + + + + + + + + + - + - - - - + + @@ -159,44 +167,38 @@ + + + - - - - - - - - + + - - - - - - - - - - - - - - - - - + + + + - + + + + + + + + + + + - + @@ -529,6 +531,13 @@ + + + + + + + diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.java index 55ad77930d82..08620dfc2d9a 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtAlignment.java @@ -22,7 +22,9 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; +import org.netbeans.modules.php.editor.CodeUtils; import static org.netbeans.modules.php.editor.indent.FmtOptions.*; import org.netbeans.modules.php.editor.indent.FmtOptions.CategorySupport; import static org.netbeans.modules.php.editor.indent.FmtOptions.CategorySupport.OPTION_ID; @@ -34,6 +36,8 @@ */ public class FmtAlignment extends javax.swing.JPanel { + @StaticResource + private static final String PREVIEW_FILE = "org/netbeans/modules/php/editor/indent/ui/Spaces.php"; // NOI18N private static final Logger LOGGER = Logger.getLogger(FmtAlignment.class.getName()); public FmtAlignment() { @@ -62,17 +66,17 @@ public FmtAlignment() { gmlAssignmentCheckBox.putClientProperty(OPTION_ID, GROUP_ALIGNMENT_ASSIGNMENT); gmlArrayInitializerCheckBox.putClientProperty(OPTION_ID, GROUP_ALIGNMENT_ARRAY_INIT); + gmlMatchArmArrowCheckBox.putClientProperty(OPTION_ID, GROUP_ALIGNMENT_MATCH_ARM_ARROW); } public static PreferencesCustomizer.Factory getController() { - String preview = ""; + String preview = CodeUtils.EMPTY_STRING; try { - preview = Utils.loadPreviewText(FmtBlankLines.class.getClassLoader().getResourceAsStream("org/netbeans/modules/php/editor/indent/ui/Spaces.php")); + preview = Utils.loadPreviewText(FmtBlankLines.class.getClassLoader().getResourceAsStream(PREVIEW_FILE)); } catch (IOException ex) { LOGGER.log(Level.WARNING, null, ex); } - return new CategorySupport.Factory("alignment", FmtAlignment.class, //NOI18N - preview); + return new CategorySupport.Factory("alignment", FmtAlignment.class, preview); // NOI18N // return new CategorySupport.Factory("alignment", FmtAlignment.class, //NOI18N // org.openide.util.NbBundle.getMessage(FmtAlignment.class, "SAMPLE_AlignBraces"), // NOI18N // new String[] { FmtOptions.wrapAnnotations, WrapStyle.WRAP_ALWAYS.name() }, @@ -126,6 +130,7 @@ private void initComponents() { jSeparator3 = new javax.swing.JSeparator(); gmlAssignmentCheckBox = new javax.swing.JCheckBox(); gmlArrayInitializerCheckBox = new javax.swing.JCheckBox(); + gmlMatchArmArrowCheckBox = new javax.swing.JCheckBox(); nlFinallyCheckBox = new javax.swing.JCheckBox(); noteLabel = new javax.swing.JLabel(); @@ -183,6 +188,8 @@ private void initComponents() { org.openide.awt.Mnemonics.setLocalizedText(gmlArrayInitializerCheckBox, org.openide.util.NbBundle.getMessage(FmtAlignment.class, "FmtAlignment.gmlArrayInitializerCheckBox.text")); // NOI18N gmlArrayInitializerCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + org.openide.awt.Mnemonics.setLocalizedText(gmlMatchArmArrowCheckBox, org.openide.util.NbBundle.getMessage(FmtAlignment.class, "FmtAlignment.gmlMatchArmArrowCheckBox.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(nlFinallyCheckBox, org.openide.util.NbBundle.getMessage(FmtAlignment.class, "FmtAlignment.nlFinallyCheckBox.text")); // NOI18N nlFinallyCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); @@ -194,116 +201,120 @@ private void initComponents() { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(multilineAlignmentLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSeparator2)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(newLinesLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)) + .addComponent(jSeparator1)) .addGroup(layout.createSequentialGroup() - .addComponent(groupMultilineAlignmentLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(multilineAlignmentLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(6, 6, 6) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(nlWhileCheckBox) + .addComponent(nlElseCheckBox) + .addComponent(nlFinallyCheckBox) + .addComponent(amMethodParamsCheckBox) + .addComponent(amImplementsCheckBox1) + .addComponent(amAssignCheckBox1) + .addComponent(amParenthesizedCheckBox1) + .addComponent(amForCheckBox1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(nlCatchCheckBox) + .addComponent(nlModifiersCheckBox) + .addComponent(gmlArrayInitializerCheckBox))) + .addGroup(layout.createSequentialGroup() + .addGap(167, 167, 167) + .addComponent(amCallArgsCheckBox)) + .addGroup(layout.createSequentialGroup() + .addGap(167, 167, 167) + .addComponent(amBinaryOpCheckBox1)) + .addGroup(layout.createSequentialGroup() + .addGap(167, 167, 167) + .addComponent(amArrayInitCheckBox1)) + .addGroup(layout.createSequentialGroup() + .addGap(167, 167, 167) + .addComponent(amTernaryOpCheckBox1))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)))) .addGroup(layout.createSequentialGroup() + .addGap(6, 6, 6) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(nlWhileCheckBox) - .addComponent(nlElseCheckBox)) - .addGap(71, 71, 71) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(nlCatchCheckBox) - .addComponent(nlModifiersCheckBox))) - .addGroup(layout.createSequentialGroup() - .addComponent(gmlAssignmentCheckBox) - .addGap(93, 93, 93) - .addComponent(gmlArrayInitializerCheckBox)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(amMethodParamsCheckBox) - .addComponent(amParenthesizedCheckBox1) - .addComponent(amAssignCheckBox1) - .addComponent(amForCheckBox1) - .addComponent(amImplementsCheckBox1)) + .addComponent(groupMultilineAlignmentLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSeparator3)) + .addGroup(layout.createSequentialGroup() + .addGap(6, 6, 6) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(amBinaryOpCheckBox1) - .addComponent(amTernaryOpCheckBox1) - .addComponent(amArrayInitCheckBox1) - .addComponent(amCallArgsCheckBox)))) - .addGap(0, 0, Short.MAX_VALUE))) + .addComponent(gmlMatchArmArrowCheckBox) + .addComponent(gmlAssignmentCheckBox)) + .addGap(0, 0, Short.MAX_VALUE))))) .addContainerGap()) - .addGroup(layout.createSequentialGroup() - .addComponent(nlFinallyCheckBox) - .addGap(0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(noteLabel) + .addComponent(noteLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(newLinesLabel)) - .addGroup(layout.createSequentialGroup() - .addGap(17, 17, 17) - .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(newLinesLabel) + .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(nlModifiersCheckBox) + .addComponent(nlElseCheckBox)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(nlElseCheckBox) - .addComponent(nlModifiersCheckBox)) + .addComponent(nlWhileCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(nlWhileCheckBox) + .addComponent(nlFinallyCheckBox) .addComponent(nlCatchCheckBox)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(nlFinallyCheckBox) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(groupMultilineAlignmentLabel) .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(gmlAssignmentCheckBox) .addComponent(gmlArrayInitializerCheckBox)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(gmlMatchArmArrowCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(multilineAlignmentLabel)) - .addGroup(layout.createSequentialGroup() - .addGap(14, 14, 14) - .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(multilineAlignmentLabel, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(amMethodParamsCheckBox) .addComponent(amCallArgsCheckBox)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(20, 20, 20) - .addComponent(amArrayInitCheckBox1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(amTernaryOpCheckBox1)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(amImplementsCheckBox1) - .addComponent(amBinaryOpCheckBox1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(amAssignCheckBox1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(amParenthesizedCheckBox1))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(amForCheckBox1) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(amImplementsCheckBox1) + .addComponent(amBinaryOpCheckBox1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(amAssignCheckBox1) + .addComponent(amArrayInitCheckBox1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(amParenthesizedCheckBox1) + .addComponent(amTernaryOpCheckBox1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(noteLabel) - .addContainerGap(26, Short.MAX_VALUE)) + .addComponent(amForCheckBox1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(noteLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); newLinesLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FmtAlignment.class, "FmtAlignment.newLinesLabel.AccessibleContext.accessibleName")); // NOI18N @@ -354,6 +365,7 @@ private void initComponents() { private javax.swing.JCheckBox amTernaryOpCheckBox1; private javax.swing.JCheckBox gmlArrayInitializerCheckBox; private javax.swing.JCheckBox gmlAssignmentCheckBox; + private javax.swing.JCheckBox gmlMatchArmArrowCheckBox; private javax.swing.JLabel groupMultilineAlignmentLabel; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php index aa7c76110e2e..a98d5cee96d9 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php @@ -150,4 +150,8 @@ function namedArguments($a, $b) {} 'very_looong_key'=>100, ]; -?> +$match = match ($type) { + "condition" => 1, + "loooooong condition" => 2, + default => 0, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php new file mode 100644 index 000000000000..8630f4571cfe --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php @@ -0,0 +1,209 @@ + 'min', 'maxLength' => 'maxLength', default => null, +}; + +$m = match ($type1) { + 'maxLength' => 'maxLength', 'min' => 'min', default => null, +}; + +match ($type1) { + 'min' => 'min', 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength' => 'maxLength', + 'min' => 'mim', + default => null, +}; +match ($type1) { + 'min' => 'min', + 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength', 'min' => 'min', + 'test' => 'test', + default => null, +}; + +match ($type1) { + 'maxLength', 'test' => 'maxLength', + 'min' => match ($type2) { + 1, 2 => "nested", + 3 => "nested", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 'min' => 'min', + 'maxLength' => match ($type2) { + 1 => "nested", + "maxLength" => "nested", "test" => "test", + 4 => "nested", + }, + default => null, +}; + + + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + 155555555555555 => '15', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01a.formatted new file mode 100644 index 000000000000..d11662f46d00 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01a.formatted @@ -0,0 +1,207 @@ + 'min', 'maxLength' => 'maxLength', default => null, +}; + +$m = match ($type1) { + 'maxLength' => 'maxLength', 'min' => 'min', default => null, +}; + +match ($type1) { + 'min' => 'min', 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength' => 'maxLength', + 'min' => 'mim', + default => null, +}; +match ($type1) { + 'min' => 'min', + 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength', 'min' => 'min', + 'test' => 'test', + default => null, +}; + +match ($type1) { + 'maxLength', 'test' => 'maxLength', + 'min' => match ($type2) { + 1, 2 => "nested", + 3 => "nested", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 'min' => 'min', + 'maxLength' => match ($type2) { + 1 => "nested", + "maxLength" => "nested", "test" => "test", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + 155555555555555 => '15', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01b.formatted new file mode 100644 index 000000000000..b085a077c916 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Spaces01b.formatted @@ -0,0 +1,207 @@ + 'min', 'maxLength' => 'maxLength', default => null, +}; + +$m = match ($type1) { + 'maxLength' => 'maxLength', 'min' => 'min', default => null, +}; + +match ($type1) { + 'min' => 'min', 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength' => 'maxLength', + 'min' => 'mim', + default => null, +}; +match ($type1) { + 'min' => 'min', + 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength', 'min' => 'min', + 'test' => 'test', + default => null, +}; + +match ($type1) { + 'maxLength', 'test' => 'maxLength', + 'min' => match ($type2) { + 1, 2 => "nested", + 3 => "nested", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 'min' => 'min', + 'maxLength' => match ($type2) { + 1 => "nested", + "maxLength" => "nested", "test" => "test", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + 155555555555555 => '15', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4a.formatted new file mode 100644 index 000000000000..5c8ae9efc955 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4a.formatted @@ -0,0 +1,207 @@ + 'min', 'maxLength' => 'maxLength', default => null, +}; + +$m = match ($type1) { + 'maxLength' => 'maxLength', 'min' => 'min', default => null, +}; + +match ($type1) { + 'min' => 'min', 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength' => 'maxLength', + 'min' => 'mim', + default => null, +}; +match ($type1) { + 'min' => 'min', + 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength', 'min' => 'min', + 'test' => 'test', + default => null, +}; + +match ($type1) { + 'maxLength', 'test' => 'maxLength', + 'min' => match ($type2) { + 1, 2 => "nested", + 3 => "nested", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 'min' => 'min', + 'maxLength' => match ($type2) { + 1 => "nested", + "maxLength" => "nested", "test" => "test", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + 155555555555555 => '15', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4b.formatted new file mode 100644 index 000000000000..5636d4c2060d --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size4b.formatted @@ -0,0 +1,207 @@ + 'min', 'maxLength' => 'maxLength', default => null, +}; + +$m = match ($type1) { + 'maxLength' => 'maxLength', 'min' => 'min', default => null, +}; + +match ($type1) { + 'min' => 'min', 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength' => 'maxLength', + 'min' => 'mim', + default => null, +}; +match ($type1) { + 'min' => 'min', + 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength', 'min' => 'min', + 'test' => 'test', + default => null, +}; + +match ($type1) { + 'maxLength', 'test' => 'maxLength', + 'min' => match ($type2) { + 1, 2 => "nested", + 3 => "nested", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 'min' => 'min', + 'maxLength' => match ($type2) { + 1 => "nested", + "maxLength" => "nested", "test" => "test", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + 155555555555555 => '15', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8a.formatted new file mode 100644 index 000000000000..c1f217edf92e --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8a.formatted @@ -0,0 +1,207 @@ + 'min', 'maxLength' => 'maxLength', default => null, +}; + +$m = match ($type1) { + 'maxLength' => 'maxLength', 'min' => 'min', default => null, +}; + +match ($type1) { + 'min' => 'min', 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength' => 'maxLength', + 'min' => 'mim', + default => null, +}; +match ($type1) { + 'min' => 'min', + 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength', 'min' => 'min', + 'test' => 'test', + default => null, +}; + +match ($type1) { + 'maxLength', 'test' => 'maxLength', + 'min' => match ($type2) { + 1, 2 => "nested", + 3 => "nested", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 'min' => 'min', + 'maxLength' => match ($type2) { + 1 => "nested", + "maxLength" => "nested", "test" => "test", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + 155555555555555 => '15', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8b.formatted new file mode 100644 index 000000000000..5636d4c2060d --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_01.php.testGroupAlignmentMatchArmArrow_Tab01_Size8b.formatted @@ -0,0 +1,207 @@ + 'min', 'maxLength' => 'maxLength', default => null, +}; + +$m = match ($type1) { + 'maxLength' => 'maxLength', 'min' => 'min', default => null, +}; + +match ($type1) { + 'min' => 'min', 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength' => 'maxLength', + 'min' => 'mim', + default => null, +}; +match ($type1) { + 'min' => 'min', + 'maxLength' => 'maxLength', + default => null, +}; + +match ($type1) { + 'maxLength', 'min' => 'min', + 'test' => 'test', + default => null, +}; + +match ($type1) { + 'maxLength', 'test' => 'maxLength', + 'min' => match ($type2) { + 1, 2 => "nested", + 3 => "nested", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 'min' => 'min', + 'maxLength' => match ($type2) { + 1 => "nested", + "maxLength" => "nested", "test" => "test", + 4 => "nested", + }, + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + default => null, +}; + +match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + 14444444444444 => '14', + 155555555555555 => '15', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php new file mode 100644 index 000000000000..607f05c90391 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], +11111111111 => '11', +122222222222 => '12', +1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02a.formatted new file mode 100644 index 000000000000..68d2d3a25d32 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02a.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02b.formatted new file mode 100644 index 000000000000..8d473991995f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02b.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02c.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02c.formatted new file mode 100644 index 000000000000..e11483e8cc7a --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02c.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02d.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02d.formatted new file mode 100644 index 000000000000..eb5f678380a2 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Spaces02d.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4a.formatted new file mode 100644 index 000000000000..0c1ea8f8beba --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4a.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4b.formatted new file mode 100644 index 000000000000..71cc477dee9a --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4b.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4c.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4c.formatted new file mode 100644 index 000000000000..122774657c68 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4c.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4d.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4d.formatted new file mode 100644 index 000000000000..b07103223d6f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size4d.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8a.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8a.formatted new file mode 100644 index 000000000000..16b005d6c30b --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8a.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8b.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8b.formatted new file mode 100644 index 000000000000..1b2cca46abef --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8b.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8c.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8c.formatted new file mode 100644 index 000000000000..77231c0ad186 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8c.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8d.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8d.formatted new file mode 100644 index 000000000000..b07103223d6f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/groupAlignmentMatchArmArrow_02.php.testGroupAlignmentMatchArmArrow_Tab02_Size8d.formatted @@ -0,0 +1,91 @@ + '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + default => null, +}; + +$result = match ($type1) { + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + 'maxLength' => [ + '1' => 1, + 'test' => [ + 'nested' => "nested", + 'nested2' => "nested", + 'nestedMaxLength' => "nested", + 'nested3' => "nested", + 'nestedTest' => "nested", + ], + 1 => '1', + 22 => '2', + 333 => '3', + 4444 => '4', + 55555 => '5', + 666666 => '6', + 7777777 => '7', + 88888888 => '8', + 999999999 => '9', + 1000000000 => '10', + ], + 11111111111 => '11', + 122222222222 => '12', + 1333333333333 => '13', + default => null, +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.formatted index ad29c5bae9a5..98e08bbe2c8a 100644 --- a/php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.formatted +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.formatted @@ -16,35 +16,35 @@ $var111111 = 'test'; $var1111111 = 'test'; $longVarName = 'test'; -$v = 'test'; -$va = 'test'; -$var = 'test'; -$var1 = 'test'; -$var11 = 'test'; -$var111 = 'test'; -$var1111 = 'test'; -$var11111 = 'test'; -$var111111 = 'test'; -$var1111111 = 'test'; - -$v = 'test'; -$va = 'test'; -$var = 'test'; -$var1 = 'test'; -$var11 = 'test'; -$var111 = 'test'; -$var1111 = 'test'; -$var11111 = 'test'; -$var111111 = 'test'; - -$v = 'test'; -$va = 'test'; -$var = 'test'; -$var1 = 'test'; -$var11 = 'test'; -$var111 = 'test'; -$var1111 = 'test'; -$var11111 = 'test'; +$v = 'test'; +$va = 'test'; +$var = 'test'; +$var1 = 'test'; +$var11 = 'test'; +$var111 = 'test'; +$var1111 = 'test'; +$var11111 = 'test'; +$var111111 = 'test'; +$var1111111 = 'test'; + +$v = 'test'; +$va = 'test'; +$var = 'test'; +$var1 = 'test'; +$var11 = 'test'; +$var111 = 'test'; +$var1111 = 'test'; +$var11111 = 'test'; +$var111111 = 'test'; + +$v = 'test'; +$va = 'test'; +$var = 'test'; +$var1 = 'test'; +$var11 = 'test'; +$var111 = 'test'; +$var1111 = 'test'; +$var11111 = 'test'; $v = 'test'; $va = 'test'; @@ -54,43 +54,43 @@ $var11 = 'test'; $var111 = 'test'; $var1111 = 'test'; -$v = 'test'; -$va = 'test'; -$var = 'test'; -$var1 = 'test'; -$var11 = 'test'; -$var111 = 'test'; +$v = 'test'; +$va = 'test'; +$var = 'test'; +$var1 = 'test'; +$var11 = 'test'; +$var111 = 'test'; -$v = 'test'; -$va = 'test'; -$var = 'test'; -$var1 = 'test'; -$var11 = 'test'; +$v = 'test'; +$va = 'test'; +$var = 'test'; +$var1 = 'test'; +$var11 = 'test'; -$v = 'test'; -$va = 'test'; -$var = 'test'; -$var1 = 'test'; +$v = 'test'; +$va = 'test'; +$var = 'test'; +$var1 = 'test'; $v = 'test'; $va = 'test'; $var = 'test'; -$v = 'test'; -$va = 'test'; +$v = 'test'; +$va = 'test'; $short = 'test'; $shortli = "test"; $ar = array( - "var" => 10, - "longname" => 20, - "short" => 333 + "var" => 10, + "longname" => 20, + "short" => 333 ); function functionName($param) { - $va4567890 = 'test'; - $var1 = 10; + $va4567890 = 'test'; + $var1 = 10; $va4567890 = 'test'; } @@ -99,19 +99,19 @@ $ar = array( "longname" => 20, ); -$var1111 = 'test'; -$var111111 = 'test'; +$var1111 = 'test'; +$var111111 = 'test'; -$va4567890 = 'test'; -$var1 = 10; -$var1111 = 'test'; -$var11111 = 'test'; +$va4567890 = 'test'; +$var1 = 10; +$var1111 = 'test'; +$var11111 = 'test'; -$var = 'test'; -$var1 = 'test'; +$var = 'test'; +$var1 = 'test'; -$var = 'test'; -$var11111 = 'test'; +$var = 'test'; +$var11111 = 'test'; $v = 'test'; $longVarName = 'test'; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.testIssue210617_TabSize8.formatted b/php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.testIssue210617_TabSize8.formatted new file mode 100644 index 000000000000..86a51d4c694b --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/issue210617.php.testIssue210617_TabSize8.formatted @@ -0,0 +1,118 @@ + 10, + "longname" => 20, + "short" => 333 +); + +function functionName($param) { + $va4567890 = 'test'; + $var1 = 10; + + $va4567890 = 'test'; +} + +$ar = array( + "longname" => 20, +); + +$var1111 = 'test'; +$var111111 = 'test'; + +$va4567890 = 'test'; +$var1 = 10; +$var1111 = 'test'; +$var11111 = 'test'; + +$var = 'test'; +$var1 = 'test'; + +$var = 'test'; +$var11111 = 'test'; + +$v = 'test'; +$longVarName = 'test'; +?> diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java index bc8c50c98553..b084e3ddb9aa 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java @@ -315,4 +315,183 @@ public void testGH6714WithSpaces_02b() throws Exception { reformatFileContents(getTestFilePath("gh6714_02.php"), options, false, true); } + public void testGroupAlignmentMatchArmArrow_Spaces01a() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_01.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Spaces01b() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_01.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab01_Size4a() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 4); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_01.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab01_Size4b() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 4); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_01.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab01_Size8a() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 8); + options.put(FmtOptions.INDENT_SIZE, 8); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_01.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab01_Size8b() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 8); + options.put(FmtOptions.INDENT_SIZE, 8); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_01.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Spaces02a() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Spaces02b() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Spaces02c() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Spaces02d() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size4a() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 4); + options.put(FmtOptions.INDENT_SIZE, 4); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size4b() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 4); + options.put(FmtOptions.INDENT_SIZE, 4); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size4c() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 4); + options.put(FmtOptions.INDENT_SIZE, 4); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size4d() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 4); + options.put(FmtOptions.INDENT_SIZE, 4); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 4); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size8a() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 8); + options.put(FmtOptions.INDENT_SIZE, 8); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size8b() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 8); + options.put(FmtOptions.INDENT_SIZE, 8); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, true); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size8c() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 8); + options.put(FmtOptions.INDENT_SIZE, 8); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, true); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } + + public void testGroupAlignmentMatchArmArrow_Tab02_Size8d() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 8); + options.put(FmtOptions.INDENT_SIZE, 8); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_MATCH_ARM_ARROW, false); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 8); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, false); + reformatFileContents(getTestFilePath("groupAlignmentMatchArmArrow_02.php"), options, false, true); + } } diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java index 872ee7f86c55..f3cfb01dc743 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java @@ -236,6 +236,18 @@ public void testIssue210617() throws Exception { reformatFileContents("testfiles/formatting/alignment/issue210617.php", options); } + public void testIssue210617_TabSize8() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.GROUP_ALIGNMENT_ARRAY_INIT, true); + options.put(FmtOptions.GROUP_ALIGNMENT_ASSIGNMENT, true); + options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false); + options.put(FmtOptions.TAB_SIZE, 8); + options.put(FmtOptions.INDENT_SIZE, 8); + options.put(FmtOptions.ITEMS_IN_ARRAY_DECLARATION_INDENT_SIZE, 8); + options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 8); + reformatFileContents("testfiles/formatting/alignment/issue210617.php", options, false, true); + } + public void testIssue181624_01() throws Exception { HashMap options = new HashMap(FmtOptions.getDefaults()); reformatFileContents("testfiles/formatting/spaces/issue181624_01.php", options);