formatted source code
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / ProblemAnnotationIterator.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /*
4  * (c) Copyright IBM Corp. 2000, 2001.
5  * All Rights Reserved.
6  */
7
8
9 import java.util.Iterator;
10 import org.eclipse.jface.text.source.IAnnotationModel;
11
12
13 /**
14  * Filters problems based on their types.
15  */
16 public class ProblemAnnotationIterator implements Iterator {
17                         
18         private Iterator fIterator;
19         private IProblemAnnotation fNext;
20         private boolean fSkipIrrelevants;
21         
22         public ProblemAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants) {
23                 fIterator= model.getAnnotationIterator();
24                 fSkipIrrelevants= skipIrrelevants;
25                 skip();
26         }
27         
28         private void skip() {
29                 while (fIterator.hasNext()) {
30                         Object next= fIterator.next();
31                         if (next instanceof IProblemAnnotation) {
32                                 IProblemAnnotation a= (IProblemAnnotation) next;
33                                 if (fSkipIrrelevants) {
34                                         if (a.isRelevant()) {
35                                                 fNext= a;
36                                                 return;
37                                         }
38                                 } else {
39                                         fNext= a;
40                                         return;
41                                 }
42                         }
43                 }
44                 fNext= null;
45         }
46         
47         /*
48          * @see Iterator#hasNext()
49          */
50         public boolean hasNext() {
51                 return fNext != null;
52         }
53
54         /*
55          * @see Iterator#next()
56          */
57         public Object next() {
58                 try {
59                         return fNext;
60                 } finally {
61                         skip();
62                 }
63         }
64
65         /*
66          * @see Iterator#remove()
67          */
68         public void remove() {
69                 throw new UnsupportedOperationException();
70         }
71 }