OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 237 } |
238 | 238 |
239 private ASTNode getFirstRef() { | 239 private ASTNode getFirstRef() { |
240 return firstRef; | 240 return firstRef; |
241 } | 241 } |
242 | 242 |
243 private ProjectionAnnotationModel getModel() { | 243 private ProjectionAnnotationModel getModel() { |
244 return model; | 244 return model; |
245 } | 245 } |
246 | 246 |
247 private TokenStream getScanner() { | 247 private TokenStream getScanner(int start) throws InvalidSourceException { |
248 return getScanner(0); | |
249 } | |
250 | |
251 private TokenStream getScanner(int start) { | |
252 tokenStream.begin(start); | 248 tokenStream.begin(start); |
253 return tokenStream; | 249 return tokenStream; |
254 } | 250 } |
255 | 251 |
256 private boolean hasHeaderComment() { | 252 private boolean hasHeaderComment() { |
257 return hasHeaderComment; | 253 return hasHeaderComment; |
258 } | 254 } |
259 | 255 |
260 private void setFirstRef(ASTNode type) { | 256 private void setFirstRef(ASTNode type) { |
261 if (hasFirstRef()) { | 257 if (hasFirstRef()) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 scanner = new StringScanner(null, source, listener); | 554 scanner = new StringScanner(null, source, listener); |
559 if (errorFound[0]) { | 555 if (errorFound[0]) { |
560 throw new InvalidSourceException(); | 556 throw new InvalidSourceException(); |
561 } else { | 557 } else { |
562 firstToken = scanner.tokenize(); | 558 firstToken = scanner.tokenize(); |
563 currentToken = firstToken; | 559 currentToken = firstToken; |
564 begin = 0; | 560 begin = 0; |
565 } | 561 } |
566 } | 562 } |
567 | 563 |
568 void begin(int start) { | 564 void begin(int start) throws InvalidSourceException { |
569 if (start == begin) { | 565 if (start == begin) { |
570 return; | 566 return; |
571 } | 567 } |
572 if (start < begin) { | 568 if (start < begin) { |
573 begin = 0; | 569 begin = 0; |
574 currentToken = firstToken; | 570 currentToken = firstToken; |
575 } | 571 } |
| 572 Token prev = currentToken; |
576 while (begin < start) { | 573 while (begin < start) { |
577 currentToken = currentToken.getNext(); | 574 currentToken = currentToken.getNext(); |
| 575 if (currentToken == prev) { |
| 576 throw new InvalidSourceException(); |
| 577 } |
| 578 prev = currentToken; |
578 begin = currentToken.getOffset(); | 579 begin = currentToken.getOffset(); |
579 } | 580 } |
580 } | 581 } |
581 | 582 |
582 Token next() { | 583 Token next() { |
583 Token next = currentToken; | 584 Token next = currentToken; |
584 currentToken = currentToken.getNext(); | 585 currentToken = currentToken.getNext(); |
585 return next; | 586 return next; |
586 } | 587 } |
587 } | 588 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 List<IRegion> regions = new ArrayList<IRegion>(); | 813 List<IRegion> regions = new ArrayList<IRegion>(); |
813 if (!ctx.hasFirstRef()) { | 814 if (!ctx.hasFirstRef()) { |
814 ctx.setFirstRef(reference); | 815 ctx.setFirstRef(reference); |
815 IRegion headerComment = computeHeaderComment(ctx); | 816 IRegion headerComment = computeHeaderComment(ctx); |
816 if (headerComment != null) { | 817 if (headerComment != null) { |
817 regions.add(headerComment); | 818 regions.add(headerComment); |
818 ctx.setHasHeaderComment(); | 819 ctx.setHasHeaderComment(); |
819 } | 820 } |
820 } | 821 } |
821 int shift = range.getOffset(); | 822 int shift = range.getOffset(); |
822 TokenStream scanner = ctx.getScanner(shift); | 823 TokenStream scanner; |
| 824 try { |
| 825 scanner = ctx.getScanner(shift); |
| 826 } catch (InvalidSourceException ex) { |
| 827 return new IRegion[0]; |
| 828 } |
823 int start = shift; | 829 int start = shift; |
824 Token token = scanner.next(); | 830 Token token = scanner.next(); |
825 start = token.getOffset(); | 831 start = token.getOffset(); |
826 Token comment = token.getPrecedingComments(); | 832 Token comment = token.getPrecedingComments(); |
827 IDocument doc = dartEditor.getDocumentProvider().getDocument(dartEditor.getE
ditorInput()); | 833 IDocument doc = dartEditor.getDocumentProvider().getDocument(dartEditor.getE
ditorInput()); |
828 while (comment != null) { | 834 while (comment != null) { |
829 int s = comment.getOffset(); | 835 int s = comment.getOffset(); |
830 int l = comment.getLength(); | 836 int l = comment.getLength(); |
831 if (comment.getLexeme().startsWith("//")) { | 837 if (comment.getLexeme().startsWith("//")) { |
832 Token nextComment = comment.getNext(); | 838 Token nextComment = comment.getNext(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 } | 973 } |
968 }; | 974 }; |
969 v.visitAllNodes(parent); | 975 v.visitAllNodes(parent); |
970 } catch (InvalidSourceException x) { | 976 } catch (InvalidSourceException x) { |
971 DartToolsPlugin.log(x); | 977 DartToolsPlugin.log(x); |
972 } | 978 } |
973 } | 979 } |
974 | 980 |
975 private IRegion computeHeaderComment(FoldingStructureComputationContext ctx) { | 981 private IRegion computeHeaderComment(FoldingStructureComputationContext ctx) { |
976 // search at most up to the first element | 982 // search at most up to the first element |
977 TokenStream scanner = ctx.getScanner(); | 983 TokenStream scanner; |
| 984 try { |
| 985 scanner = ctx.getScanner(0); |
| 986 } catch (InvalidSourceException ex) { |
| 987 return null; |
| 988 } |
978 int headerStart = -1; | 989 int headerStart = -1; |
979 int headerEnd = -1; | 990 int headerEnd = -1; |
980 boolean foundComment = false; | 991 boolean foundComment = false; |
981 Token terminal = scanner.next(); | 992 Token terminal = scanner.next(); |
982 Token comment = terminal.getPrecedingComments(); | 993 Token comment = terminal.getPrecedingComments(); |
983 while (comment != null) { | 994 while (comment != null) { |
984 if (!foundComment) { | 995 if (!foundComment) { |
985 headerStart = comment.getOffset(); | 996 headerStart = comment.getOffset(); |
986 } | 997 } |
987 headerEnd = comment.getEnd(); | 998 headerEnd = comment.getEnd(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 match(deletions, additions, updates, ctx); | 1280 match(deletions, additions, updates, ctx); |
1270 Annotation[] deletedArray = deletions.toArray(new Annotation[deletions.size(
)]); | 1281 Annotation[] deletedArray = deletions.toArray(new Annotation[deletions.size(
)]); |
1271 Annotation[] changedArray = updates.toArray(new Annotation[updates.size()]); | 1282 Annotation[] changedArray = updates.toArray(new Annotation[updates.size()]); |
1272 ctx.getModel().modifyAnnotations(deletedArray, additions, changedArray); | 1283 ctx.getModel().modifyAnnotations(deletedArray, additions, changedArray); |
1273 try { | 1284 try { |
1274 ctx.setScannerSource(""); // clear token stream | 1285 ctx.setScannerSource(""); // clear token stream |
1275 } catch (InvalidSourceException e1) { | 1286 } catch (InvalidSourceException e1) { |
1276 } | 1287 } |
1277 } | 1288 } |
1278 } | 1289 } |
OLD | NEW |