X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ProblemAnnotationIterator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ProblemAnnotationIterator.java new file mode 100644 index 0000000..7895116 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ProblemAnnotationIterator.java @@ -0,0 +1,73 @@ +package net.sourceforge.phpeclipse.phpeditor; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.util.Iterator; + +import org.eclipse.jface.text.source.IAnnotationModel; + +/** + * Filters problems based on their types. + */ +public class ProblemAnnotationIterator implements Iterator { + + private Iterator fIterator; + + private IProblemAnnotation fNext; + + private boolean fSkipIrrelevants; + + public ProblemAnnotationIterator(IAnnotationModel model, + boolean skipIrrelevants) { + fIterator = model.getAnnotationIterator(); + fSkipIrrelevants = skipIrrelevants; + skip(); + } + + private void skip() { + while (fIterator.hasNext()) { + Object next = fIterator.next(); + if (next instanceof IProblemAnnotation) { + IProblemAnnotation a = (IProblemAnnotation) next; + if (fSkipIrrelevants) { + if (a.isRelevant()) { + fNext = a; + return; + } + } else { + fNext = a; + return; + } + } + } + fNext = null; + } + + /* + * @see Iterator#hasNext() + */ + public boolean hasNext() { + return fNext != null; + } + + /* + * @see Iterator#next() + */ + public Object next() { + try { + return fNext; + } finally { + skip(); + } + } + + /* + * @see Iterator#remove() + */ + public void remove() { + throw new UnsupportedOperationException(); + } +}