Mercurial > projects > dwt-addons
comparison dwtx/jface/text/TextUtilities.d @ 136:6dcb0baaa031
Regex removal of throws decls, some instanceof
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 02:20:40 +0200 |
parents | 51e6e63f930e |
children | 75302ef3f92f |
comparison
equal
deleted
inserted
replaced
135:65801ad2b265 | 136:6dcb0baaa031 |
---|---|
178 public class TextUtilities { | 178 public class TextUtilities { |
179 | 179 |
180 /** | 180 /** |
181 * Default line delimiters used by the text functions of this class. | 181 * Default line delimiters used by the text functions of this class. |
182 */ | 182 */ |
183 public final static String[] DELIMITERS= new String[] { "\n", "\r", "\r\n" }; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ | 183 public final static String[] DELIMITERS= [ "\n", "\r", "\r\n" ]; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ |
184 | 184 |
185 /** | 185 /** |
186 * Default line delimiters used by these text functions. | 186 * Default line delimiters used by these text functions. |
187 * | 187 * |
188 * @deprecated use DELIMITERS instead | 188 * @deprecated use DELIMITERS instead |
325 * @param unprocessedDocument the document to which the document events would be applied | 325 * @param unprocessedDocument the document to which the document events would be applied |
326 * @param documentEvents the list of document events to merge | 326 * @param documentEvents the list of document events to merge |
327 * @return returns the merged document event | 327 * @return returns the merged document event |
328 * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events | 328 * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events |
329 */ | 329 */ |
330 public static DocumentEvent mergeUnprocessedDocumentEvents(IDocument unprocessedDocument, List documentEvents) throws BadLocationException { | 330 public static DocumentEvent mergeUnprocessedDocumentEvents(IDocument unprocessedDocument, List documentEvents) { |
331 | 331 |
332 if (documentEvents.size() is 0) | 332 if (documentEvents.size() is 0) |
333 return null; | 333 return null; |
334 | 334 |
335 final Iterator iterator= documentEvents.iterator(); | 335 final Iterator iterator= documentEvents.iterator(); |
390 * | 390 * |
391 * @param documentEvents the list of document events to merge | 391 * @param documentEvents the list of document events to merge |
392 * @return returns the merged document event | 392 * @return returns the merged document event |
393 * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events | 393 * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events |
394 */ | 394 */ |
395 public static DocumentEvent mergeProcessedDocumentEvents(List documentEvents) throws BadLocationException { | 395 public static DocumentEvent mergeProcessedDocumentEvents(List documentEvents) { |
396 | 396 |
397 if (documentEvents.size() is 0) | 397 if (documentEvents.size() is 0) |
398 return null; | 398 return null; |
399 | 399 |
400 final ListIterator iterator= documentEvents.listIterator(documentEvents.size()); | 400 final ListIterator iterator= documentEvents.listIterator(documentEvents.size()); |
450 * @param document the document | 450 * @param document the document |
451 * @return the map containing the removed partitioners | 451 * @return the map containing the removed partitioners |
452 */ | 452 */ |
453 public static Map removeDocumentPartitioners(IDocument document) { | 453 public static Map removeDocumentPartitioners(IDocument document) { |
454 Map partitioners= new HashMap(); | 454 Map partitioners= new HashMap(); |
455 if (document instanceof IDocumentExtension3) { | 455 if (cast(IDocumentExtension3)document ) { |
456 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; | 456 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; |
457 String[] partitionings= extension3.getPartitionings(); | 457 String[] partitionings= extension3.getPartitionings(); |
458 for (int i= 0; i < partitionings.length; i++) { | 458 for (int i= 0; i < partitionings.length; i++) { |
459 IDocumentPartitioner partitioner= extension3.getDocumentPartitioner(partitionings[i]); | 459 IDocumentPartitioner partitioner= extension3.getDocumentPartitioner(partitionings[i]); |
460 if (partitioner !is null) { | 460 if (partitioner !is null) { |
481 * @param document the document | 481 * @param document the document |
482 * @param partitioners the map containing the partitioners to be connected | 482 * @param partitioners the map containing the partitioners to be connected |
483 * @since 3.0 | 483 * @since 3.0 |
484 */ | 484 */ |
485 public static void addDocumentPartitioners(IDocument document, Map partitioners) { | 485 public static void addDocumentPartitioners(IDocument document, Map partitioners) { |
486 if (document instanceof IDocumentExtension3) { | 486 if (cast(IDocumentExtension3)document ) { |
487 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; | 487 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; |
488 Iterator e= partitioners.keySet().iterator(); | 488 Iterator e= partitioners.keySet().iterator(); |
489 while (e.hasNext()) { | 489 while (e.hasNext()) { |
490 String partitioning= cast(String) e.next(); | 490 String partitioning= cast(String) e.next(); |
491 IDocumentPartitioner partitioner= cast(IDocumentPartitioner) partitioners.get(partitioning); | 491 IDocumentPartitioner partitioner= cast(IDocumentPartitioner) partitioners.get(partitioning); |
511 * closed partition starting at <code>offset</code> | 511 * closed partition starting at <code>offset</code> |
512 * @return the content type at the given offset of the document | 512 * @return the content type at the given offset of the document |
513 * @throws BadLocationException if offset is invalid in the document | 513 * @throws BadLocationException if offset is invalid in the document |
514 * @since 3.0 | 514 * @since 3.0 |
515 */ | 515 */ |
516 public static String getContentType(IDocument document, String partitioning, int offset, bool preferOpenPartitions) throws BadLocationException { | 516 public static String getContentType(IDocument document, String partitioning, int offset, bool preferOpenPartitions) { |
517 if (document instanceof IDocumentExtension3) { | 517 if (cast(IDocumentExtension3)document ) { |
518 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; | 518 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; |
519 try { | 519 try { |
520 return extension3.getContentType(partitioning, offset, preferOpenPartitions); | 520 return extension3.getContentType(partitioning, offset, preferOpenPartitions); |
521 } catch (BadPartitioningException x) { | 521 } catch (BadPartitioningException x) { |
522 return IDocument.DEFAULT_CONTENT_TYPE; | 522 return IDocument.DEFAULT_CONTENT_TYPE; |
538 * @return the content type at the given offset of this viewer's input | 538 * @return the content type at the given offset of this viewer's input |
539 * document | 539 * document |
540 * @throws BadLocationException if offset is invalid in the given document | 540 * @throws BadLocationException if offset is invalid in the given document |
541 * @since 3.0 | 541 * @since 3.0 |
542 */ | 542 */ |
543 public static ITypedRegion getPartition(IDocument document, String partitioning, int offset, bool preferOpenPartitions) throws BadLocationException { | 543 public static ITypedRegion getPartition(IDocument document, String partitioning, int offset, bool preferOpenPartitions) { |
544 if (document instanceof IDocumentExtension3) { | 544 if (cast(IDocumentExtension3)document ) { |
545 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; | 545 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; |
546 try { | 546 try { |
547 return extension3.getPartition(partitioning, offset, preferOpenPartitions); | 547 return extension3.getPartition(partitioning, offset, preferOpenPartitions); |
548 } catch (BadPartitioningException x) { | 548 } catch (BadPartitioningException x) { |
549 return new TypedRegion(0, document.getLength(), IDocument.DEFAULT_CONTENT_TYPE); | 549 return new TypedRegion(0, document.getLength(), IDocument.DEFAULT_CONTENT_TYPE); |
566 * the given partitioning name | 566 * the given partitioning name |
567 * @throws BadLocationException if the given region is invalid for the given | 567 * @throws BadLocationException if the given region is invalid for the given |
568 * document | 568 * document |
569 * @since 3.0 | 569 * @since 3.0 |
570 */ | 570 */ |
571 public static ITypedRegion[] computePartitioning(IDocument document, String partitioning, int offset, int length, bool includeZeroLengthPartitions) throws BadLocationException { | 571 public static ITypedRegion[] computePartitioning(IDocument document, String partitioning, int offset, int length, bool includeZeroLengthPartitions) { |
572 if (document instanceof IDocumentExtension3) { | 572 if (cast(IDocumentExtension3)document ) { |
573 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; | 573 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; |
574 try { | 574 try { |
575 return extension3.computePartitioning(partitioning, offset, length, includeZeroLengthPartitions); | 575 return extension3.computePartitioning(partitioning, offset, length, includeZeroLengthPartitions); |
576 } catch (BadPartitioningException x) { | 576 } catch (BadPartitioningException x) { |
577 return new ITypedRegion[0]; | 577 return new ITypedRegion[0]; |
588 * @param document the document | 588 * @param document the document |
589 * @return the partition managing position categories or <code>null</code> | 589 * @return the partition managing position categories or <code>null</code> |
590 * @since 3.0 | 590 * @since 3.0 |
591 */ | 591 */ |
592 public static String[] computePartitionManagingCategories(IDocument document) { | 592 public static String[] computePartitionManagingCategories(IDocument document) { |
593 if (document instanceof IDocumentExtension3) { | 593 if (cast(IDocumentExtension3)document ) { |
594 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; | 594 IDocumentExtension3 extension3= cast(IDocumentExtension3) document; |
595 String[] partitionings= extension3.getPartitionings(); | 595 String[] partitionings= extension3.getPartitionings(); |
596 if (partitionings !is null) { | 596 if (partitionings !is null) { |
597 Set categories= new HashSet(); | 597 Set categories= new HashSet(); |
598 for (int i= 0; i < partitionings.length; i++) { | 598 for (int i= 0; i < partitionings.length; i++) { |
599 IDocumentPartitioner p= extension3.getDocumentPartitioner(partitionings[i]); | 599 IDocumentPartitioner p= extension3.getDocumentPartitioner(partitionings[i]); |
600 if (p instanceof IDocumentPartitionerExtension2) { | 600 if (cast(IDocumentPartitionerExtension2)p ) { |
601 IDocumentPartitionerExtension2 extension2= cast(IDocumentPartitionerExtension2) p; | 601 IDocumentPartitionerExtension2 extension2= cast(IDocumentPartitionerExtension2) p; |
602 String[] c= extension2.getManagingPositionCategories(); | 602 String[] c= extension2.getManagingPositionCategories(); |
603 if (c !is null) { | 603 if (c !is null) { |
604 for (int j= 0; j < c.length; j++) | 604 for (int j= 0; j < c.length; j++) |
605 categories.add(c[j]); | 605 categories.add(c[j]); |
623 * @return the document's default line delimiter | 623 * @return the document's default line delimiter |
624 * @since 3.0 | 624 * @since 3.0 |
625 */ | 625 */ |
626 public static String getDefaultLineDelimiter(IDocument document) { | 626 public static String getDefaultLineDelimiter(IDocument document) { |
627 | 627 |
628 if (document instanceof IDocumentExtension4) | 628 if (cast(IDocumentExtension4)document ) |
629 return (cast(IDocumentExtension4)document).getDefaultLineDelimiter(); | 629 return (cast(IDocumentExtension4)document).getDefaultLineDelimiter(); |
630 | 630 |
631 String lineDelimiter= null; | 631 String lineDelimiter= null; |
632 | 632 |
633 try { | 633 try { |
634 lineDelimiter= document.getLineDelimiter(0); | 634 lineDelimiter= document.getLineDelimiter(0); |
635 } catch (BadLocationException x) { | 635 } catch (BadLocationException x) { |
636 } | 636 } |
637 | 637 |
638 if (lineDelimiter !is null) | 638 if (lineDelimiter !is null) |
639 return lineDelimiter; | 639 return lineDelimiter; |
640 | 640 |
641 String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$ | 641 String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$ |
642 String[] delimiters= document.getLegalLineDelimiters(); | 642 String[] delimiters= document.getLegalLineDelimiters(); |
643 Assert.isTrue(delimiters.length > 0); | 643 Assert.isTrue(delimiters.length > 0); |
644 for (int i= 0; i < delimiters.length; i++) { | 644 for (int i= 0; i < delimiters.length; i++) { |
645 if (delimiters[i].equals(sysLineDelimiter)) { | 645 if (delimiters[i].equals(sysLineDelimiter)) { |
646 lineDelimiter= sysLineDelimiter; | 646 lineDelimiter= sysLineDelimiter; |
647 break; | 647 break; |
648 } | 648 } |
649 } | 649 } |
650 | 650 |
651 if (lineDelimiter is null) | 651 if (lineDelimiter is null) |
652 lineDelimiter= delimiters[0]; | 652 lineDelimiter= delimiters[0]; |
653 | 653 |
654 return lineDelimiter; | 654 return lineDelimiter; |
655 } | 655 } |