Updating feature.xml with new version number.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaAnnotationIterator.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
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  * Filters problems based on their types.
21  */
22 public class JavaAnnotationIterator implements Iterator {
23
24         private Iterator fIterator;
25
26         private Annotation fNext;
27
28         private boolean fSkipIrrelevants;
29
30         private boolean fReturnAllAnnotations;
31
32         /**
33          * Equivalent to
34          * <code>JavaAnnotationIterator(model, skipIrrelevants, false)</code>.
35          */
36         public JavaAnnotationIterator(IAnnotationModel model,
37                         boolean skipIrrelevants) {
38                 this(model, skipIrrelevants, false);
39         }
40
41         /**
42          * Returns a new JavaAnnotationIterator.
43          * 
44          * @param model
45          *            the annotation model
46          * @param skipIrrelevants
47          *            whether to skip irrelevant annotations
48          * @param returnAllAnnotations
49          *            Whether to return non IJavaAnnotations as well
50          */
51         public JavaAnnotationIterator(IAnnotationModel model,
52                         boolean skipIrrelevants, boolean returnAllAnnotations) {
53                 fReturnAllAnnotations = returnAllAnnotations;
54                 if (model != null)
55                         fIterator = model.getAnnotationIterator();
56                 else
57                         fIterator = Collections.EMPTY_LIST.iterator();
58                 fSkipIrrelevants = skipIrrelevants;
59                 skip();
60         }
61
62         private void skip() {
63                 while (fIterator.hasNext()) {
64                         Annotation next = (Annotation) fIterator.next();
65                         if (next instanceof IJavaAnnotation) {
66                                 if (fSkipIrrelevants) {
67                                         if (!next.isMarkedDeleted()) {
68                                                 fNext = next;
69                                                 return;
70                                         }
71                                 } else {
72                                         fNext = next;
73                                         return;
74                                 }
75                         } else if (fReturnAllAnnotations) {
76                                 fNext = next;
77                                 return;
78                         }
79                 }
80                 fNext = null;
81         }
82
83         /*
84          * @see Iterator#hasNext()
85          */
86         public boolean hasNext() {
87                 return fNext != null;
88         }
89
90         /*
91          * @see Iterator#next()
92          */
93         public Object next() {
94                 try {
95                         return fNext;
96                 } finally {
97                         skip();
98                 }
99         }
100
101         /*
102          * @see Iterator#remove()
103          */
104         public void remove() {
105                 throw new UnsupportedOperationException();
106         }
107 }