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