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
    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 (+9 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;
56
import org.netbeans.modules.php.editor.parser.GSFPHPParserTestUtil;
55
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.FileObject;
56
58
57
/**
59
/**
Lines 84-89 Link Here
84
        HtmlVersion.DEFAULT_VERSION_UNIT_TESTS_OVERRIDE = HtmlVersion.HTML41_TRANSATIONAL;
86
        HtmlVersion.DEFAULT_VERSION_UNIT_TESTS_OVERRIDE = HtmlVersion.HTML41_TRANSATIONAL;
85
    }
87
    }
86
88
89
    @Override
90
    protected void tearDown() throws Exception {
91
        super.tearDown();
92
        GSFPHPParserTestUtil.setUnitTestCaretPosition(-1);
93
    }
94
87
    protected void reformatFileContents(String file, IndentPrefs indentPrefs, int initialIndent) throws Exception {
95
    protected void reformatFileContents(String file, IndentPrefs indentPrefs, int initialIndent) throws Exception {
88
        FileObject fo = getTestFile(file);
96
        FileObject fo = getTestFile(file);
89
        assertNotNull(fo);
97
        assertNotNull(fo);
Lines 184-189 Link Here
184
            }
192
            }
185
193
186
            TokenFormatter.setUnitTestCarretPosition(carretPosition);
194
            TokenFormatter.setUnitTestCarretPosition(carretPosition);
195
            GSFPHPParserTestUtil.setUnitTestCaretPosition(carretPosition);
187
            doc.remove(0, doc.getLength());
196
            doc.remove(0, doc.getLength());
188
            doc.insertString(0, text, null);
197
            doc.insertString(0, text, null);
189
            doc.putProperty(TokenFormatter.TEMPLATE_HANDLER_PROPERTY, new Object());
198
            doc.putProperty(TokenFormatter.TEMPLATE_HANDLER_PROPERTY, new Object());
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/parser/GSFPHPParserTestUtil.java (+50 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 */
40
package org.netbeans.modules.php.editor.parser;
41
42
public final class GSFPHPParserTestUtil {
43
44
    private GSFPHPParserTestUtil() {
45
    }
46
47
    public static void setUnitTestCaretPosition(int caretPosition) {
48
        GSFPHPParser.setUnitTestCaretPosition(caretPosition);
49
    }
50
}

Return to bug 268920