bugfix 1198893, syntax coloring gets confused after single line comment with question...
[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
11 import org.eclipse.jface.text.source.IAnnotationModel;
12
13
14 /**
15  * Filters problems based on their types.
16  */
17 public class ProblemAnnotationIterator implements Iterator {
18                         
19         private Iterator fIterator;
20         private IProblemAnnotation fNext;
21         private boolean fSkipIrrelevants;
22         
23         public ProblemAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants) {
24                 fIterator= model.getAnnotationIterator();
25                 fSkipIrrelevants= skipIrrelevants;
26                 skip();
27         }
28         
29         private void skip() {
30                 while (fIterator.hasNext()) {
31                         Object next= fIterator.next();
32                         if (next instanceof IProblemAnnotation) {
33                                 IProblemAnnotation a= (IProblemAnnotation) next;
34                                 if (fSkipIrrelevants) {
35                                         if (a.isRelevant()) {
36                                                 fNext= a;
37                                                 return;
38                                         }
39                                 } else {
40                                         fNext= a;
41                                         return;
42                                 }
43                         }
44                 }
45                 fNext= null;
46         }
47         
48         /*
49          * @see Iterator#hasNext()
50          */
51         public boolean hasNext() {
52                 return fNext != null;
53         }
54
55         /*
56          * @see Iterator#next()
57          */
58         public Object next() {
59                 try {
60                         return fNext;
61                 } finally {
62                         skip();
63                 }
64         }
65
66         /*
67          * @see Iterator#remove()
68          */
69         public void remove() {
70                 throw new UnsupportedOperationException();
71         }
72 }