This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 247047
Collapse All | Expand All

(-)a/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java (-5 / +6 lines)
Lines 133-139 Link Here
133
    private boolean isMethodInvocationShifted; // is continual indentation already included ?
133
    private boolean isMethodInvocationShifted; // is continual indentation already included ?
134
    private boolean isFirstUseStatementPart;
134
    private boolean isFirstUseStatementPart;
135
    private boolean isFirstUseTraitStatementPart;
135
    private boolean isFirstUseTraitStatementPart;
136
    private boolean inArray;
136
    private int inArrayBalance;
137
137
138
    public FormatVisitor(BaseDocument document, DocumentOptions documentOptions, final int caretOffset, final int startOffset, final int endOffset) {
138
    public FormatVisitor(BaseDocument document, DocumentOptions documentOptions, final int caretOffset, final int startOffset, final int endOffset) {
139
        this.document = document;
139
        this.document = document;
Lines 148-153 Link Here
148
        formatTokens.add(new FormatToken.InitToken());
148
        formatTokens.add(new FormatToken.InitToken());
149
        isMethodInvocationShifted = false;
149
        isMethodInvocationShifted = false;
150
        groupAlignmentTokenHolders = new Stack<>();
150
        groupAlignmentTokenHolders = new Stack<>();
151
        inArrayBalance = 0;
151
    }
152
    }
152
153
153
    public List<FormatToken> getFormatTokens() {
154
    public List<FormatToken> getFormatTokens() {
Lines 256-262 Link Here
256
257
257
    @Override
258
    @Override
258
    public void visit(ArrayCreation node) {
259
    public void visit(ArrayCreation node) {
259
        inArray = true;
260
        inArrayBalance++;
260
        int delta = options.indentArrayItems - options.continualIndentSize;
261
        int delta = options.indentArrayItems - options.continualIndentSize;
261
        if (ts.token().id() != PHPTokenId.PHP_ARRAY && lastIndex <= ts.index() // it's possible that the expression starts with array
262
        if (ts.token().id() != PHPTokenId.PHP_ARRAY && lastIndex <= ts.index() // it's possible that the expression starts with array
262
                && !ts.token().text().toString().equals("[")) {  //NOI18N
263
                && !ts.token().text().toString().equals("[")) {  //NOI18N
Lines 305-311 Link Here
305
        formatTokens.add(new FormatToken.IndentToken(ts.offset() + ts.token().length(), -1 * delta));
306
        formatTokens.add(new FormatToken.IndentToken(ts.offset() + ts.token().length(), -1 * delta));
306
        addAllUntilOffset(node.getEndOffset());
307
        addAllUntilOffset(node.getEndOffset());
307
        resetGroupAlignment();
308
        resetGroupAlignment();
308
        inArray = false;
309
        inArrayBalance--;
309
    }
310
    }
310
311
311
    private int modifyDeltaForEnclosingFunctionInvocations(int delta) {
312
    private int modifyDeltaForEnclosingFunctionInvocations(int delta) {
Lines 1077-1087 Link Here
1077
        Block body = node.getBody();
1078
        Block body = node.getBody();
1078
        if (body != null) {
1079
        if (body != null) {
1079
            addAllUntilOffset(body.getStartOffset());
1080
            addAllUntilOffset(body.getStartOffset());
1080
            if (!inArray) {
1081
            if (inArrayBalance == 0) {
1081
                formatTokens.add(new FormatToken.IndentToken(body.getStartOffset(), -1 * options.continualIndentSize));
1082
                formatTokens.add(new FormatToken.IndentToken(body.getStartOffset(), -1 * options.continualIndentSize));
1082
            }
1083
            }
1083
            scan(body);
1084
            scan(body);
1084
            if (!inArray) {
1085
            if (inArrayBalance == 0) {
1085
                formatTokens.add(new FormatToken.IndentToken(body.getEndOffset(), options.continualIndentSize));
1086
                formatTokens.add(new FormatToken.IndentToken(body.getEndOffset(), options.continualIndentSize));
1086
            }
1087
            }
1087
        }
1088
        }
(-)a/php.editor/test/unit/data/testfiles/formatting/issue247047.php (+22 lines)
Line 0 Link Here
1
<?php
2
3
$foo = array(
4
    "foo" => function ($args) {
5
        print_r(array(1, 2, 3));
6
    },
7
        "foo" => function ($args) {
8
        echo "";
9
    },
10
    );
11
12
class A {
13
14
    public function func() {
15
        [
16
            'func' => function() {
17
                $array = [];
18
            }
19
            ];
20
        }
21
22
    }
(-)a/php.editor/test/unit/data/testfiles/formatting/issue247047.php.formatted (+22 lines)
Line 0 Link Here
1
<?php
2
3
$foo = array(
4
    "foo" => function ($args) {
5
        print_r(array(1, 2, 3));
6
    },
7
    "foo" => function ($args) {
8
        echo "";
9
    },
10
);
11
12
class A {
13
14
    public function func() {
15
        [
16
            'func' => function() {
17
                $array = [];
18
            }
19
        ];
20
    }
21
22
}
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java (+5 lines)
Lines 666-669 Link Here
666
        HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
666
        HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
667
        reformatFileContents("testfiles/formatting/issue257241.php", options);
667
        reformatFileContents("testfiles/formatting/issue257241.php", options);
668
    }
668
    }
669
670
    public void testIssue247047() throws Exception {
671
        HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
672
        reformatFileContents("testfiles/formatting/issue247047.php", options);
673
    }
669
}
674
}

Return to bug 247047