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

(-)a/php.editor/src/org/netbeans/modules/php/editor/csl/FoldingScanner.java (+63 lines)
Lines 51-59 Link Here
51
import javax.swing.text.Document;
51
import javax.swing.text.Document;
52
import org.netbeans.api.editor.fold.FoldTemplate;
52
import org.netbeans.api.editor.fold.FoldTemplate;
53
import org.netbeans.api.editor.fold.FoldType;
53
import org.netbeans.api.editor.fold.FoldType;
54
import org.netbeans.api.lexer.Token;
55
import org.netbeans.api.lexer.TokenSequence;
56
import org.netbeans.api.lexer.TokenUtilities;
57
import org.netbeans.editor.BaseDocument;
54
import org.netbeans.modules.csl.api.OffsetRange;
58
import org.netbeans.modules.csl.api.OffsetRange;
55
import org.netbeans.modules.csl.spi.ParserResult;
59
import org.netbeans.modules.csl.spi.ParserResult;
56
import org.netbeans.modules.parsing.api.Source;
60
import org.netbeans.modules.parsing.api.Source;
61
import org.netbeans.modules.php.editor.lexer.LexUtilities;
62
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
57
import org.netbeans.modules.php.editor.model.FileScope;
63
import org.netbeans.modules.php.editor.model.FileScope;
58
import org.netbeans.modules.php.editor.model.FunctionScope;
64
import org.netbeans.modules.php.editor.model.FunctionScope;
59
import org.netbeans.modules.php.editor.model.MethodScope;
65
import org.netbeans.modules.php.editor.model.MethodScope;
Lines 126-131 Link Here
126
            "array",
132
            "array",
127
            Bundle.FT_Arrays(), new FoldTemplate(0, 0, "[...]")); // NOI18N
133
            Bundle.FT_Arrays(), new FoldTemplate(0, 0, "[...]")); // NOI18N
128
134
135
    /**
136
     * PHP tags (<?php...?> blocks).
137
     *
138
     * <b>NOTE:</b> &lt;?=...?&gt; blocks are not folded.
139
     */
140
    @NbBundle.Messages("FT_PHPTag=<?php ?> blocks")
141
    public static final FoldType TYPE_PHPTAG = FoldType.CODE_BLOCK.derive(
142
            "phptag", // NOI18N
143
            Bundle.FT_PHPTag(),
144
            new FoldTemplate(0, 0, "...") // NOI18N
145
    );
146
129
    private static final String LAST_CORRECT_FOLDING_PROPERTY = "LAST_CORRECT_FOLDING_PROPERY"; //NOI18N
147
    private static final String LAST_CORRECT_FOLDING_PROPERTY = "LAST_CORRECT_FOLDING_PROPERY"; //NOI18N
130
148
131
    public static FoldingScanner create() {
149
    public static FoldingScanner create() {
Lines 166-171 Link Here
166
            Source source = phpParseResult.getSnapshot().getSource();
184
            Source source = phpParseResult.getSnapshot().getSource();
167
            assert source != null : "source was null";
185
            assert source != null : "source was null";
168
            Document doc = source.getDocument(false);
186
            Document doc = source.getDocument(false);
187
            processPHPTags(folds, doc);
169
            setFoldingProperty(doc, folds);
188
            setFoldingProperty(doc, folds);
170
            return folds;
189
            return folds;
171
        }
190
        }
Lines 210-215 Link Here
210
        }
229
        }
211
    }
230
    }
212
231
232
    private void processPHPTags(Map<String, List<OffsetRange>> folds, Document document) {
233
        if (document instanceof BaseDocument) {
234
            BaseDocument doc = (BaseDocument) document;
235
            doc.readLock();
236
            try {
237
                TokenSequence<PHPTokenId> ts = LexUtilities.getPHPTokenSequence(doc, 0);
238
                if (ts == null) {
239
                    return;
240
                }
241
                ts.move(0);
242
                int startOffset = -1;
243
                int endOffset = -1;
244
                int shortTagBalance = 0; // for <?= ... ?>
245
                while (ts.moveNext()) {
246
                    Token<PHPTokenId> token = ts.token();
247
                    if (token != null) {
248
                        PHPTokenId id = token.id();
249
                        switch (id) {
250
                            case PHP_OPENTAG:
251
                                startOffset = ts.offset() + token.length();
252
                                break;
253
                            case PHP_CLOSETAG:
254
                                if (shortTagBalance == 0) {
255
                                    assert startOffset != -1;
256
                                    endOffset = ts.offset();
257
                                    getRanges(folds, TYPE_PHPTAG).add(new OffsetRange(startOffset, endOffset));
258
                                } else {
259
                                    shortTagBalance--;
260
                                }
261
                                break;
262
                            case T_OPEN_TAG_WITH_ECHO:
263
                                shortTagBalance++;
264
                                break;
265
                            default:
266
                                break;
267
                        }
268
                    }
269
                }
270
            } finally {
271
                doc.readUnlock();
272
            }
273
        }
274
    }
275
213
    private void processScopes(Map<String, List<OffsetRange>> folds, List<Scope> scopes) {
276
    private void processScopes(Map<String, List<OffsetRange>> folds, List<Scope> scopes) {
214
        for (Scope scope : scopes) {
277
        for (Scope scope : scopes) {
215
            OffsetRange offsetRange = scope.getBlockRange();
278
            OffsetRange offsetRange = scope.getBlockRange();
(-)a/php.editor/src/org/netbeans/modules/php/editor/csl/PHPFoldingProvider.java (-1 / +2 lines)
Lines 53-59 Link Here
53
 */
53
 */
54
@MimeRegistration(mimeType = "text/x-php5", service = FoldTypeProvider.class, position = 1000)
54
@MimeRegistration(mimeType = "text/x-php5", service = FoldTypeProvider.class, position = 1000)
55
public class PHPFoldingProvider implements FoldTypeProvider {
55
public class PHPFoldingProvider implements FoldTypeProvider {
56
    private static final Collection<FoldType> TYPES = new ArrayList<>(6);
56
    private static final Collection<FoldType> TYPES = new ArrayList<>(7);
57
57
58
    static {
58
    static {
59
        TYPES.add(FoldingScanner.TYPE_CLASS);
59
        TYPES.add(FoldingScanner.TYPE_CLASS);
Lines 62-67 Link Here
62
        TYPES.add(FoldingScanner.TYPE_COMMENT);
62
        TYPES.add(FoldingScanner.TYPE_COMMENT);
63
        TYPES.add(FoldingScanner.TYPE_PHPDOC);
63
        TYPES.add(FoldingScanner.TYPE_PHPDOC);
64
        TYPES.add(FoldingScanner.TYPE_ARRAY);
64
        TYPES.add(FoldingScanner.TYPE_ARRAY);
65
        TYPES.add(FoldingScanner.TYPE_PHPTAG);
65
    }
66
    }
66
67
67
    @Override
68
    @Override
(-)a/php.editor/test/unit/data/testfiles/finally_01.php.folds (-4 / +4 lines)
Lines 1-5 Link Here
1
  <?php
1
+ <?php
2
  
2
| 
3
+ try {
3
+ try {
4
|     echo "";
4
|     echo "";
5
+ } catch (Exception $ex) {
5
+ } catch (Exception $ex) {
Lines 7-11 Link Here
7
+ } finally {
7
+ } finally {
8
|     echo "";
8
|     echo "";
9
- }
9
- }
10
  
10
| 
11
  ?>
11
- ?>
(-)a/php.editor/test/unit/data/testfiles/finally_02.php.folds (-4 / +4 lines)
Lines 1-9 Link Here
1
  <?php
1
+ <?php
2
  
2
| 
3
+ try {
3
+ try {
4
|     echo "";
4
|     echo "";
5
+ } catch (Exception $ex) {
5
+ } catch (Exception $ex) {
6
|     echo "";
6
|     echo "";
7
- }
7
- }
8
  
8
| 
9
  ?>
9
- ?>
(-)a/php.editor/test/unit/data/testfiles/foldingConditionalStatements.php.folds (-1 lines)
Lines 40-43 Link Here
40
| 
40
| 
41
- }
41
- }
42
  
42
  
43
  ?>
(-)a/php.editor/test/unit/data/testfiles/foldingConditionalStatements_1.php.folds (-1 lines)
Lines 52-55 Link Here
52
| 
52
| 
53
- }
53
- }
54
  
54
  
55
  ?>
(-)a/php.editor/test/unit/data/testfiles/foldingCycles.php.folds (-1 lines)
Lines 60-63 Link Here
60
| 
60
| 
61
- }
61
- }
62
  
62
  
63
  ?>
(-)a/php.editor/test/unit/data/testfiles/foldingCycles_1.php.folds (-1 lines)
Lines 76-79 Link Here
76
| 
76
| 
77
- }
77
- }
78
  
78
  
79
  ?>
(-)a/php.editor/test/unit/data/testfiles/foldingMethod.php.folds (-1 lines)
Lines 20-23 Link Here
20
|     
20
|     
21
- }
21
- }
22
  
22
  
23
  ?>
(-)a/php.editor/test/unit/data/testfiles/foldingMethod_1.php.folds (-1 lines)
Lines 25-28 Link Here
25
| 
25
| 
26
- }
26
- }
27
  
27
  
28
  ?>
(-)a/php.editor/test/unit/data/testfiles/foldingPHPTags.php.folds (+19 lines)
Line 0 Link Here
1
  <html>
2
      <body>
3
          <h2>Test</h2>
4
          <?= "test" ?>
5
+         <?php echo "test" ?>
6
          <?= "test" ?>
7
  
8
          <h2>Test</h2>
9
+         <?php
10
+         /**
11
|          * Get date.
12
|          *
13
|          * Description.
14
-          */
15
|         $date = getdate();
16
|         echo $date; // comment
17
-         ?>
18
      </body>
19
  </html>
(-)a/php.editor/test/unit/data/testfiles/issue213616.php.folds (-1 lines)
Lines 7-10 Link Here
7
- 	}
7
- 	}
8
- }
8
- }
9
  
9
  
10
  ?>
(-)a/php.editor/test/unit/data/testfiles/issue216088.php.folds (-1 lines)
Lines 4-7 Link Here
4
+     echo "";
4
+     echo "";
5
  else
5
  else
6
+     echo "";
6
+     echo "";
7
  ?>
(-)a/php.editor/test/unit/data/testfiles/issue232884.php.folds (-1 lines)
Lines 3-6 Link Here
3
  if (TRUE):
3
  if (TRUE):
4
  
4
  
5
  endif;
5
  endif;
6
  ?>
(-)a/php.editor/test/unit/data/testfiles/parser/foldingConditionalStatements.php (-2 lines)
Lines 39-43 Link Here
39
} else {
39
} else {
40
40
41
}
41
}
42
43
?>
(-)a/php.editor/test/unit/data/testfiles/parser/foldingConditionalStatements_1.php (-2 lines)
Lines 51-55 Link Here
51
{
51
{
52
52
53
}
53
}
54
55
?>
(-)a/php.editor/test/unit/data/testfiles/parser/foldingCycles.php (-2 lines)
Lines 59-63 Link Here
59
foreach ($array as $value) {
59
foreach ($array as $value) {
60
60
61
}
61
}
62
63
?>
(-)a/php.editor/test/unit/data/testfiles/parser/foldingCycles_1.php (-2 lines)
Lines 75-79 Link Here
75
{
75
{
76
76
77
}
77
}
78
79
?>
(-)a/php.editor/test/unit/data/testfiles/parser/foldingMethod.php (-2 lines)
Lines 19-23 Link Here
19
    }
19
    }
20
    
20
    
21
}
21
}
22
23
?>
(-)a/php.editor/test/unit/data/testfiles/parser/foldingMethod_1.php (-2 lines)
Lines 24-28 Link Here
24
    }
24
    }
25
25
26
}
26
}
27
28
?>
(-)a/php.editor/test/unit/data/testfiles/parser/foldingPHPTags.php (+19 lines)
Line 0 Link Here
1
<html>
2
    <body>
3
        <h2>Test</h2>
4
        <?= "test" ?>
5
        <?php echo "test" ?>
6
        <?= "test" ?>
7
8
        <h2>Test</h2>
9
        <?php
10
        /**
11
         * Get date.
12
         *
13
         * Description.
14
         */
15
        $date = getdate();
16
        echo $date; // comment
17
        ?>
18
    </body>
19
</html>
(-)a/php.editor/test/unit/data/testfiles/parser/issue213616.php (-2 lines)
Lines 6-10 Link Here
6
6
7
	}
7
	}
8
}
8
}
9
10
?>
(-)a/php.editor/test/unit/data/testfiles/parser/issue216088.php (-1 lines)
Lines 4-7 Link Here
4
    echo "";
4
    echo "";
5
else
5
else
6
    echo "";
6
    echo "";
7
?>
(-)a/php.editor/test/unit/data/testfiles/parser/issue232884.php (-1 lines)
Lines 3-6 Link Here
3
if (TRUE):
3
if (TRUE):
4
4
5
endif;
5
endif;
6
?>
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/FoldingTest.java (+5 lines)
Lines 106-109 Link Here
106
        checkFolds("testfiles/parser/foldingArrays.php");
106
        checkFolds("testfiles/parser/foldingArrays.php");
107
    }
107
    }
108
108
109
    // #232600
110
    public void testPHPTags() throws Exception {
111
        checkFolds("testfiles/parser/foldingPHPTags.php");
112
    }
113
109
}
114
}

Return to bug 232600