Added externaltools plugin
[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 /**
21  * Filters problems based on their types.
22  */
23 public class JavaAnnotationIterator implements Iterator {
24                         
25         private Iterator fIterator;
26         private Annotation fNext;
27         private boolean fSkipIrrelevants;
28         private boolean fReturnAllAnnotations;
29         
30         /**
31          * Equivalent to <code>JavaAnnotationIterator(model, skipIrrelevants, false)</code>.
32          */
33         public JavaAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants) {
34                 this(model, skipIrrelevants, false);
35         }
36         
37         /**
38          * Returns a new JavaAnnotationIterator. 
39          * @param model the annotation model
40          * @param skipIrrelevants whether to skip irrelevant annotations
41          * @param returnAllAnnotations Whether to return non IJavaAnnotations as well
42          */
43         public JavaAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants, boolean returnAllAnnotations) {
44                 fReturnAllAnnotations= returnAllAnnotations;
45                 if (model != null)
46                         fIterator= model.getAnnotationIterator();
47                 else
48                         fIterator= Collections.EMPTY_LIST.iterator();
49                 fSkipIrrelevants= skipIrrelevants;
50                 skip();
51         }
52         
53         private void skip() {
54                 while (fIterator.hasNext()) {
55                         Annotation next= (Annotation) fIterator.next();
56                         if (next instanceof IJavaAnnotation) {
57                                 if (fSkipIrrelevants) {
58                                         if (!next.isMarkedDeleted()) {
59                                                 fNext= next;
60                                                 return;
61                                         }
62                                 } else {
63                                         fNext= next;
64                                         return;
65                                 }
66                         } else if (fReturnAllAnnotations) {
67                                 fNext= next;
68                                 return;
69                         }
70                 }
71                 fNext= null;
72         }
73         
74         /*
75          * @see Iterator#hasNext()
76          */
77         public boolean hasNext() {
78                 return fNext != null;
79         }
80
81         /*
82          * @see Iterator#next()
83          */
84         public Object next() {
85                 try {
86                         return fNext;
87                 } finally {
88                         skip();
89                 }
90         }
91
92         /*
93          * @see Iterator#remove()
94          */
95         public void remove() {
96                 throw new UnsupportedOperationException();
97         }
98 }