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 268920
Collapse All | Expand All

(-)a/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java (-1 / +1 lines)
Lines 466-472 Link Here
466
466
467
            boolean indentationIncluded = false;
467
            boolean indentationIncluded = false;
468
            while (ts.moveNext() && (ts.token().id() == PHPTokenId.WHITESPACE && countOfNewLines(ts.token().text()) == 0)
468
            while (ts.moveNext() && (ts.token().id() == PHPTokenId.WHITESPACE && countOfNewLines(ts.token().text()) == 0)
469
                    || isComment(ts.token())) {
469
                    || (lastIndex < ts.index() && isComment(ts.token()))) { // #268920 check lastIndex to prevent an infinite loop
470
                if (ts.token().id() == PHPTokenId.PHP_LINE_COMMENT && !indentationIncluded) {
470
                if (ts.token().id() == PHPTokenId.PHP_LINE_COMMENT && !indentationIncluded) {
471
                    formatTokens.add(new FormatToken.IndentToken(ts.offset(), options.indentSize));
471
                    formatTokens.add(new FormatToken.IndentToken(ts.offset(), options.indentSize));
472
                    indentationIncluded = true;
472
                    indentationIncluded = true;
(-)a/php.editor/src/org/netbeans/modules/php/editor/parser/GSFPHPParser.java (+10 lines)
Lines 87-92 Link Here
87
    private ParserResult result = null;
87
    private ParserResult result = null;
88
    private boolean projectPropertiesListenerAdded = false;
88
    private boolean projectPropertiesListenerAdded = false;
89
89
90
    // it's for testing
91
    private static int unitTestCaretPosition = -1;
92
93
    public static void setUnitTestCaretPosition(int unitTestCaretPosition) {
94
        GSFPHPParser.unitTestCaretPosition = unitTestCaretPosition;
95
    }
96
90
    static {
97
    static {
91
        LOGGER.log(Level.INFO, "Parsing of big PHP files enabled: {0} (max size: {1})", new Object[] {PARSE_BIG_FILES, BIG_FILE_SIZE});
98
        LOGGER.log(Level.INFO, "Parsing of big PHP files enabled: {0} (max size: {1})", new Object[] {PARSE_BIG_FILES, BIG_FILE_SIZE});
92
    }
99
    }
Lines 163-168 Link Here
163
        aspTags = languageProperties.areAspTagsEnabled();
170
        aspTags = languageProperties.areAspTagsEnabled();
164
        try {
171
        try {
165
            int caretOffset = GsfUtilities.getLastKnownCaretOffset(snapshot, event);
172
            int caretOffset = GsfUtilities.getLastKnownCaretOffset(snapshot, event);
173
            if (caretOffset < 0 && unitTestCaretPosition >= 0) {
174
                caretOffset = unitTestCaretPosition;
175
            }
166
            LOGGER.log(Level.FINE, "caretOffset: {0}", caretOffset); //NOI18N
176
            LOGGER.log(Level.FINE, "caretOffset: {0}", caretOffset); //NOI18N
167
            Context context = new Context(snapshot, caretOffset);
177
            Context context = new Context(snapshot, caretOffset);
168
            result = parseBuffer(context, Sanitize.NONE, null);
178
            result = parseBuffer(context, Sanitize.NONE, null);
(-)a/php.editor/test/unit/data/testfiles/formatting/issue268920.php (+15 lines)
Line 0 Link Here
1
<?php
2
3
class Example {
4
5
}
6
7
$closure = (static function ($examples) {
8
    $i = 0;
9
    foreach ($examples as $example) { /* @var $example /*FORMAT_START*/Example/*FORMAT_END*/
10
        $i++;
11
?>
12
<?php
13
    }
14
});
15
?>
(-)a/php.editor/test/unit/data/testfiles/formatting/issue268920.php.formatted (+15 lines)
Line 0 Link Here
1
<?php
2
3
class Example {
4
5
}
6
7
$closure = (static function ($examples) {
8
    $i = 0;
9
    foreach ($examples as $example) { /* @var $example Example
10
        $i++;
11
?>
12
<?php
13
    }
14
});
15
?>
(-)a/php.editor/test/unit/data/testfiles/formatting/templates/issue268920.php (+15 lines)
Line 0 Link Here
1
<?php
2
3
class Example {
4
5
}
6
7
$closure = (static function ($examples) {
8
    $i = 0;
9
    foreach ($examples as $example) { /* @var $example /*FORMAT_START*/Example/*FORMAT_END*/
10
        $i++;
11
?>
12
<?php
13
    }
14
});
15
?>
(-)a/php.editor/test/unit/data/testfiles/formatting/templates/issue268920.php.formatted (+15 lines)
Line 0 Link Here
1
<?php
2
3
class Example {
4
5
}
6
7
$closure = (static function ($examples) {
8
    $i = 0;
9
    foreach ($examples as $example) { /* @var $example Example
10
        $i++;
11
?>
12
<?php
13
    }
14
});
15
?>
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTemplateTest.java (+5 lines)
Lines 553-556 Link Here
553
        reformatFileContents("testfiles/formatting/templates/issue262205_04.php", options, true);
553
        reformatFileContents("testfiles/formatting/templates/issue262205_04.php", options, true);
554
    }
554
    }
555
555
556
    public void testIssue268920() throws Exception {
557
        HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
558
        reformatFileContents("testfiles/formatting/templates/issue268920.php", options, true);
559
    }
560
556
}
561
}
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java (+4 lines)
Lines 764-767 Link Here
764
        reformatFileContents("testfiles/formatting/issue268171.php", options);
764
        reformatFileContents("testfiles/formatting/issue268171.php", options);
765
    }
765
    }
766
766
767
    public void testIssue268920() throws Exception {
768
        HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
769
        reformatFileContents("testfiles/formatting/issue268920.php", options);
770
    }
767
}
771
}
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTestBase.java (+8 lines)
Lines 52-57 Link Here
52
import org.netbeans.modules.html.editor.lib.api.HtmlVersion;
52
import org.netbeans.modules.html.editor.lib.api.HtmlVersion;
53
import org.netbeans.modules.php.editor.PHPTestBase;
53
import org.netbeans.modules.php.editor.PHPTestBase;
54
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
54
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
55
import org.netbeans.modules.php.editor.parser.GSFPHPParser;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
56
57
57
/**
58
/**
Lines 84-89 Link Here
84
        HtmlVersion.DEFAULT_VERSION_UNIT_TESTS_OVERRIDE = HtmlVersion.HTML41_TRANSATIONAL;
85
        HtmlVersion.DEFAULT_VERSION_UNIT_TESTS_OVERRIDE = HtmlVersion.HTML41_TRANSATIONAL;
85
    }
86
    }
86
87
88
    @Override
89
    protected void tearDown() throws Exception {
90
        super.tearDown();
91
        GSFPHPParser.setUnitTestCaretPosition(-1);
92
    }
93
87
    protected void reformatFileContents(String file, IndentPrefs indentPrefs, int initialIndent) throws Exception {
94
    protected void reformatFileContents(String file, IndentPrefs indentPrefs, int initialIndent) throws Exception {
88
        FileObject fo = getTestFile(file);
95
        FileObject fo = getTestFile(file);
89
        assertNotNull(fo);
96
        assertNotNull(fo);
Lines 184-189 Link Here
184
            }
191
            }
185
192
186
            TokenFormatter.setUnitTestCarretPosition(carretPosition);
193
            TokenFormatter.setUnitTestCarretPosition(carretPosition);
194
            GSFPHPParser.setUnitTestCaretPosition(carretPosition);
187
            doc.remove(0, doc.getLength());
195
            doc.remove(0, doc.getLength());
188
            doc.insertString(0, text, null);
196
            doc.insertString(0, text, null);
189
            doc.putProperty(TokenFormatter.TEMPLATE_HANDLER_PROPERTY, new Object());
197
            doc.putProperty(TokenFormatter.TEMPLATE_HANDLER_PROPERTY, new Object());

Return to bug 268920