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> <?=...?> 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(); |