comparison dwtx/jface/text/source/AnnotationModel.d @ 134:51e6e63f930e

Regex fix for casts
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 01:46:20 +0200
parents 7d818bd32d63
children 65801ad2b265
comparison
equal deleted inserted replaced
133:7d818bd32d63 134:51e6e63f930e
173 throw new UnsupportedOperationException(); 173 throw new UnsupportedOperationException();
174 } 174 }
175 175
176 private Object findNext() { 176 private Object findNext() {
177 while (fParentIterator.hasNext()) { 177 while (fParentIterator.hasNext()) {
178 Annotation next= (Annotation) fParentIterator.next(); 178 Annotation next= cast(Annotation) fParentIterator.next();
179 Position position= fModel.getPosition(next); 179 Position position= fModel.getPosition(next);
180 if (position !is null) { 180 if (position !is null) {
181 int offset= position.getOffset(); 181 int offset= position.getOffset();
182 if (isWithinRegion(offset, position.getLength())) 182 if (isWithinRegion(offset, position.getLength()))
183 return next; 183 return next;
272 private Object fCurrentElement; 272 private Object fCurrentElement;
273 273
274 274
275 public this(Iterator iterator) { 275 public this(Iterator iterator) {
276 fSuperIterator= iterator; 276 fSuperIterator= iterator;
277 fCurrent= (Iterator) fSuperIterator.next(); // there is at least one. 277 fCurrent= cast(Iterator) fSuperIterator.next(); // there is at least one.
278 } 278 }
279 279
280 public void remove() { 280 public void remove() {
281 throw new UnsupportedOperationException(); 281 throw new UnsupportedOperationException();
282 } 282 }
287 287
288 if (fCurrent.hasNext()) { 288 if (fCurrent.hasNext()) {
289 fCurrentElement= fCurrent.next(); 289 fCurrentElement= fCurrent.next();
290 return true; 290 return true;
291 } else if (fSuperIterator.hasNext()) { 291 } else if (fSuperIterator.hasNext()) {
292 fCurrent= (Iterator) fSuperIterator.next(); 292 fCurrent= cast(Iterator) fSuperIterator.next();
293 return hasNext(); 293 return hasNext();
294 } else 294 } else
295 return false; 295 return false;
296 } 296 }
297 297
394 * 394 *
395 * @return the annotation map internally used by this annotation model 395 * @return the annotation map internally used by this annotation model
396 * @since 3.0 396 * @since 3.0
397 */ 397 */
398 protected IAnnotationMap getAnnotationMap() { 398 protected IAnnotationMap getAnnotationMap() {
399 return (IAnnotationMap) fAnnotations; 399 return cast(IAnnotationMap) fAnnotations;
400 } 400 }
401 401
402 /* 402 /*
403 * @see dwtx.jface.text.ISynchronizable#getLockObject() 403 * @see dwtx.jface.text.ISynchronizable#getLockObject()
404 * @since 3.0 404 * @since 3.0
476 476
477 if (annotationsToAdd !is null) { 477 if (annotationsToAdd !is null) {
478 Iterator iter= annotationsToAdd.entrySet().iterator(); 478 Iterator iter= annotationsToAdd.entrySet().iterator();
479 while (iter.hasNext()) { 479 while (iter.hasNext()) {
480 Map.Entry mapEntry= (Map.Entry) iter.next(); 480 Map.Entry mapEntry= (Map.Entry) iter.next();
481 Annotation annotation= (Annotation) mapEntry.getKey(); 481 Annotation annotation= cast(Annotation) mapEntry.getKey();
482 Position position= (Position) mapEntry.getValue(); 482 Position position= cast(Position) mapEntry.getValue();
483 addAnnotation(annotation, position, false); 483 addAnnotation(annotation, position, false);
484 } 484 }
485 } 485 }
486 486
487 if (fireModelChanged) 487 if (fireModelChanged)
519 */ 519 */
520 public void addAnnotationModelListener(IAnnotationModelListener listener) { 520 public void addAnnotationModelListener(IAnnotationModelListener listener) {
521 if (!fAnnotationModelListeners.contains(listener)) { 521 if (!fAnnotationModelListeners.contains(listener)) {
522 fAnnotationModelListeners.add(listener); 522 fAnnotationModelListeners.add(listener);
523 if (listener instanceof IAnnotationModelListenerExtension) { 523 if (listener instanceof IAnnotationModelListenerExtension) {
524 IAnnotationModelListenerExtension extension= (IAnnotationModelListenerExtension) listener; 524 IAnnotationModelListenerExtension extension= cast(IAnnotationModelListenerExtension) listener;
525 AnnotationModelEvent event= createAnnotationModelEvent(); 525 AnnotationModelEvent event= createAnnotationModelEvent();
526 event.markSealed(); 526 event.markSealed();
527 extension.modelChanged(event); 527 extension.modelChanged(event);
528 } else 528 } else
529 listener.modelChanged(this); 529 listener.modelChanged(this);
566 if (fDocument is null) { 566 if (fDocument is null) {
567 fDocument= document; 567 fDocument= document;
568 Iterator e= getAnnotationMap().valuesIterator(); 568 Iterator e= getAnnotationMap().valuesIterator();
569 while (e.hasNext()) 569 while (e.hasNext())
570 try { 570 try {
571 addPosition(fDocument, (Position) e.next()); 571 addPosition(fDocument, cast(Position) e.next());
572 } catch (BadLocationException x) { 572 } catch (BadLocationException x) {
573 // ignore invalid position 573 // ignore invalid position
574 } 574 }
575 } 575 }
576 576
579 fDocument.addDocumentListener(fDocumentListener); 579 fDocument.addDocumentListener(fDocumentListener);
580 connected(); 580 connected();
581 } 581 }
582 582
583 for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) { 583 for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) {
584 IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next()); 584 IAnnotationModel model= cast(IAnnotationModel) fAttachments.get(it.next());
585 model.connect(document); 585 model.connect(document);
586 } 586 }
587 } 587 }
588 588
589 /** 589 /**
606 public void disconnect(IDocument document) { 606 public void disconnect(IDocument document) {
607 607
608 Assert.isTrue(fDocument is document); 608 Assert.isTrue(fDocument is document);
609 609
610 for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) { 610 for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) {
611 IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next()); 611 IAnnotationModel model= cast(IAnnotationModel) fAttachments.get(it.next());
612 model.disconnect(document); 612 model.disconnect(document);
613 } 613 }
614 614
615 -- fOpenConnections; 615 -- fOpenConnections;
616 if (fOpenConnections is 0) { 616 if (fOpenConnections is 0) {
619 fDocument.removeDocumentListener(fDocumentListener); 619 fDocument.removeDocumentListener(fDocumentListener);
620 620
621 if (fDocument !is null) { 621 if (fDocument !is null) {
622 Iterator e= getAnnotationMap().valuesIterator(); 622 Iterator e= getAnnotationMap().valuesIterator();
623 while (e.hasNext()) { 623 while (e.hasNext()) {
624 Position p= (Position) e.next(); 624 Position p= cast(Position) e.next();
625 removePosition(fDocument, p); 625 removePosition(fDocument, p);
626 } 626 }
627 fDocument= null; 627 fDocument= null;
628 } 628 }
629 } 629 }
673 return; 673 return;
674 674
675 ArrayList v= new ArrayList(fAnnotationModelListeners); 675 ArrayList v= new ArrayList(fAnnotationModelListeners);
676 Iterator e= v.iterator(); 676 Iterator e= v.iterator();
677 while (e.hasNext()) { 677 while (e.hasNext()) {
678 IAnnotationModelListener l= (IAnnotationModelListener) e.next(); 678 IAnnotationModelListener l= cast(IAnnotationModelListener) e.next();
679 if (l instanceof IAnnotationModelListenerExtension) 679 if (l instanceof IAnnotationModelListenerExtension)
680 ((IAnnotationModelListenerExtension) l).modelChanged(event); 680 (cast(IAnnotationModelListenerExtension) l).modelChanged(event);
681 else if (l !is null) 681 else if (l !is null)
682 l.modelChanged(this); 682 l.modelChanged(this);
683 } 683 }
684 } 684 }
685 685
695 */ 695 */
696 protected void removeAnnotations(List annotations, bool fireModelChanged, bool modelInitiated) { 696 protected void removeAnnotations(List annotations, bool fireModelChanged, bool modelInitiated) {
697 if (annotations.size() > 0) { 697 if (annotations.size() > 0) {
698 Iterator e= annotations.iterator(); 698 Iterator e= annotations.iterator();
699 while (e.hasNext()) 699 while (e.hasNext())
700 removeAnnotation((Annotation) e.next(), false); 700 removeAnnotation(cast(Annotation) e.next(), false);
701 701
702 if (fireModelChanged) 702 if (fireModelChanged)
703 fireModelChanged(); 703 fireModelChanged();
704 } 704 }
705 } 705 }
728 fDocumentChanged= false; 728 fDocumentChanged= false;
729 729
730 ArrayList deleted= new ArrayList(); 730 ArrayList deleted= new ArrayList();
731 Iterator e= getAnnotationMap().keySetIterator(); 731 Iterator e= getAnnotationMap().keySetIterator();
732 while (e.hasNext()) { 732 while (e.hasNext()) {
733 Annotation a= (Annotation) e.next(); 733 Annotation a= cast(Annotation) e.next();
734 Position p= (Position) fAnnotations.get(a); 734 Position p= cast(Position) fAnnotations.get(a);
735 if (p is null || p.isDeleted()) 735 if (p is null || p.isDeleted())
736 deleted.add(a); 736 deleted.add(a);
737 } 737 }
738 738
739 if (fireModelChanged && forkNotification) { 739 if (fireModelChanged && forkNotification) {
771 771
772 List iterators= new ArrayList(fAttachments.size() + 1); 772 List iterators= new ArrayList(fAttachments.size() + 1);
773 iterators.add(regionIterator); 773 iterators.add(regionIterator);
774 Iterator it= fAttachments.keySet().iterator(); 774 Iterator it= fAttachments.keySet().iterator();
775 while (it.hasNext()) { 775 while (it.hasNext()) {
776 IAnnotationModel attachment= (IAnnotationModel) fAttachments.get(it.next()); 776 IAnnotationModel attachment= cast(IAnnotationModel) fAttachments.get(it.next());
777 if (attachment instanceof IAnnotationModelExtension2) 777 if (attachment instanceof IAnnotationModelExtension2)
778 iterators.add(((IAnnotationModelExtension2) attachment).getAnnotationIterator(offset, length, canStartBefore, canEndAfter)); 778 iterators.add((cast(IAnnotationModelExtension2) attachment).getAnnotationIterator(offset, length, canStartBefore, canEndAfter));
779 else 779 else
780 iterators.add(new RegionIterator(attachment.getAnnotationIterator(), attachment, offset, length, canStartBefore, canEndAfter)); 780 iterators.add(new RegionIterator(attachment.getAnnotationIterator(), attachment, offset, length, canStartBefore, canEndAfter));
781 } 781 }
782 782
783 return new MetaIterator(iterators.iterator()); 783 return new MetaIterator(iterators.iterator());
796 */ 796 */
797 private Iterator getRegionAnnotationIterator(int offset, int length, bool canStartBefore, bool canEndAfter) { 797 private Iterator getRegionAnnotationIterator(int offset, int length, bool canStartBefore, bool canEndAfter) {
798 if (!(fDocument instanceof AbstractDocument)) 798 if (!(fDocument instanceof AbstractDocument))
799 return new RegionIterator(getAnnotationIterator(true), this, offset, length, canStartBefore, canEndAfter); 799 return new RegionIterator(getAnnotationIterator(true), this, offset, length, canStartBefore, canEndAfter);
800 800
801 AbstractDocument document= (AbstractDocument) fDocument; 801 AbstractDocument document= cast(AbstractDocument) fDocument;
802 cleanup(true); 802 cleanup(true);
803 803
804 try { 804 try {
805 Position[] positions= document.getPositions(IDocument.DEFAULT_CATEGORY, offset, length, canStartBefore, canEndAfter); 805 Position[] positions= document.getPositions(IDocument.DEFAULT_CATEGORY, offset, length, canStartBefore, canEndAfter);
806 return new AnnotationsInterator(positions, fPositions); 806 return new AnnotationsInterator(positions, fPositions);
829 829
830 List iterators= new ArrayList(fAttachments.size() + 1); 830 List iterators= new ArrayList(fAttachments.size() + 1);
831 iterators.add(iter); 831 iterators.add(iter);
832 Iterator it= fAttachments.keySet().iterator(); 832 Iterator it= fAttachments.keySet().iterator();
833 while (it.hasNext()) 833 while (it.hasNext())
834 iterators.add(((IAnnotationModel) fAttachments.get(it.next())).getAnnotationIterator()); 834 iterators.add((cast(IAnnotationModel) fAttachments.get(it.next())).getAnnotationIterator());
835 835
836 return new MetaIterator(iterators.iterator()); 836 return new MetaIterator(iterators.iterator());
837 } 837 }
838 838
839 /** 839 /**
853 853
854 /* 854 /*
855 * @see dwtx.jface.text.source.IAnnotationModel#getPosition(dwtx.jface.text.source.Annotation) 855 * @see dwtx.jface.text.source.IAnnotationModel#getPosition(dwtx.jface.text.source.Annotation)
856 */ 856 */
857 public Position getPosition(Annotation annotation) { 857 public Position getPosition(Annotation annotation) {
858 Position position= (Position) fAnnotations.get(annotation); 858 Position position= cast(Position) fAnnotations.get(annotation);
859 if (position !is null) 859 if (position !is null)
860 return position; 860 return position;
861 861
862 Iterator it= fAttachments.values().iterator(); 862 Iterator it= fAttachments.values().iterator();
863 while (position is null && it.hasNext()) 863 while (position is null && it.hasNext())
864 position= ((IAnnotationModel) it.next()).getPosition(annotation); 864 position= (cast(IAnnotationModel) it.next()).getPosition(annotation);
865 return position; 865 return position;
866 } 866 }
867 867
868 /* 868 /*
869 * @see dwtx.jface.text.source.IAnnotationModelExtension#removeAllAnnotations() 869 * @see dwtx.jface.text.source.IAnnotationModelExtension#removeAllAnnotations()
882 protected void removeAllAnnotations(bool fireModelChanged) { 882 protected void removeAllAnnotations(bool fireModelChanged) {
883 883
884 if (fDocument !is null) { 884 if (fDocument !is null) {
885 Iterator e= getAnnotationMap().keySetIterator(); 885 Iterator e= getAnnotationMap().keySetIterator();
886 while (e.hasNext()) { 886 while (e.hasNext()) {
887 Annotation a= (Annotation) e.next(); 887 Annotation a= cast(Annotation) e.next();
888 Position p= (Position) fAnnotations.get(a); 888 Position p= cast(Position) fAnnotations.get(a);
889 removePosition(fDocument, p); 889 removePosition(fDocument, p);
890 // p.delete(); 890 // p.delete();
891 synchronized (getLockObject()) { 891 synchronized (getLockObject()) {
892 getAnnotationModelEvent().annotationRemoved(a, p); 892 getAnnotationModelEvent().annotationRemoved(a, p);
893 } 893 }
917 */ 917 */
918 protected void removeAnnotation(Annotation annotation, bool fireModelChanged) { 918 protected void removeAnnotation(Annotation annotation, bool fireModelChanged) {
919 if (fAnnotations.containsKey(annotation)) { 919 if (fAnnotations.containsKey(annotation)) {
920 920
921 Position p= null; 921 Position p= null;
922 p= (Position) fAnnotations.get(annotation); 922 p= cast(Position) fAnnotations.get(annotation);
923 if (fDocument !is null) { 923 if (fDocument !is null) {
924 removePosition(fDocument, p); 924 removePosition(fDocument, p);
925 // p.delete(); 925 // p.delete();
926 } 926 }
927 927
962 */ 962 */
963 protected void modifyAnnotationPosition(Annotation annotation, Position position, bool fireModelChanged) { 963 protected void modifyAnnotationPosition(Annotation annotation, Position position, bool fireModelChanged) {
964 if (position is null) { 964 if (position is null) {
965 removeAnnotation(annotation, fireModelChanged); 965 removeAnnotation(annotation, fireModelChanged);
966 } else { 966 } else {
967 Position p= (Position) fAnnotations.get(annotation); 967 Position p= cast(Position) fAnnotations.get(annotation);
968 if (p !is null) { 968 if (p !is null) {
969 969
970 if (position.getOffset() !is p.getOffset() || position.getLength() !is p.getLength()) { 970 if (position.getOffset() !is p.getOffset() || position.getLength() !is p.getLength()) {
971 fDocument.removePosition(p); 971 fDocument.removePosition(p);
972 p.setOffset(position.getOffset()); 972 p.setOffset(position.getOffset());
1038 /* 1038 /*
1039 * @see dwtx.jface.text.source.IAnnotationModelExtension#get(java.lang.Object) 1039 * @see dwtx.jface.text.source.IAnnotationModelExtension#get(java.lang.Object)
1040 * @since 3.0 1040 * @since 3.0
1041 */ 1041 */
1042 public IAnnotationModel getAnnotationModel(Object key) { 1042 public IAnnotationModel getAnnotationModel(Object key) {
1043 return (IAnnotationModel) fAttachments.get(key); 1043 return cast(IAnnotationModel) fAttachments.get(key);
1044 } 1044 }
1045 1045
1046 /* 1046 /*
1047 * @see dwtx.jface.text.source.IAnnotationModelExtension#detach(java.lang.Object) 1047 * @see dwtx.jface.text.source.IAnnotationModelExtension#detach(java.lang.Object)
1048 * @since 3.0 1048 * @since 3.0
1049 */ 1049 */
1050 public IAnnotationModel removeAnnotationModel(Object key) { 1050 public IAnnotationModel removeAnnotationModel(Object key) {
1051 IAnnotationModel ret= (IAnnotationModel) fAttachments.remove(key); 1051 IAnnotationModel ret= cast(IAnnotationModel) fAttachments.remove(key);
1052 if (ret !is null) { 1052 if (ret !is null) {
1053 for (int i= 0; i < fOpenConnections; i++) 1053 for (int i= 0; i < fOpenConnections; i++)
1054 ret.disconnect(fDocument); 1054 ret.disconnect(fDocument);
1055 ret.removeAnnotationModelListener(fModelListener); 1055 ret.removeAnnotationModelListener(fModelListener);
1056 } 1056 }