1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 import java.util.Collections ; 14 import java.util.Iterator ; 15 16 import org.eclipse.jface.text.source.Annotation; 17 import org.eclipse.jface.text.source.IAnnotationModel; 18 19 20 23 public class JavaAnnotationIterator implements Iterator { 24 25 private Iterator fIterator; 26 private Annotation fNext; 27 private boolean fSkipIrrelevants; 28 private boolean fReturnAllAnnotations; 29 30 33 public JavaAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants) { 34 this(model, skipIrrelevants, false); 35 } 36 37 43 public JavaAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants, boolean returnAllAnnotations) { 44 fReturnAllAnnotations= returnAllAnnotations; 45 if (model != null) 46 fIterator= model.getAnnotationIterator(); 47 else 48 fIterator= Collections.EMPTY_LIST.iterator(); 49 fSkipIrrelevants= skipIrrelevants; 50 skip(); 51 } 52 53 private void skip() { 54 while (fIterator.hasNext()) { 55 Annotation next= (Annotation) fIterator.next(); 56 if (next instanceof IJavaAnnotation) { 57 if (fSkipIrrelevants) { 58 if (!next.isMarkedDeleted()) { 59 fNext= next; 60 return; 61 } 62 } else { 63 fNext= next; 64 return; 65 } 66 } else if (fReturnAllAnnotations) { 67 fNext= next; 68 return; 69 } 70 } 71 fNext= null; 72 } 73 74 77 public boolean hasNext() { 78 return fNext != null; 79 } 80 81 84 public Object next() { 85 try { 86 return fNext; 87 } finally { 88 skip(); 89 } 90 } 91 92 95 public void remove() { 96 throw new UnsupportedOperationException (); 97 } 98 } 99 | Popular Tags |