*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / text / XMLAnnotationIterator.java
1 /*
2  * Copyright (c) 2002-2004 Widespace, OU 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  *     Igor Malinin - initial contribution
10  *
11  * $Id: XMLAnnotationIterator.java,v 1.1 2004-09-02 18:28:03 jsurfer Exp $
12  */
13 package net.sourceforge.phpeclipse.xml.ui.internal.text;
14
15 import java.util.Iterator;
16
17 import org.eclipse.jface.text.source.Annotation;
18 import org.eclipse.jface.text.source.IAnnotationModel;
19
20
21 /**
22  * @author Igor Malinin
23  */
24 public class XMLAnnotationIterator implements Iterator {
25         private boolean skipIrrelevants;
26
27         private Iterator iterator;
28         private Annotation next;
29
30         public XMLAnnotationIterator(
31                 IAnnotationModel model, boolean skipIrrelevants
32         ) {
33                 this.skipIrrelevants = skipIrrelevants;
34
35                 iterator = model.getAnnotationIterator();
36                 skip();
37         }
38
39         private void skip() {
40                 while (iterator.hasNext()) {
41                         Annotation next = (Annotation) iterator.next();
42                         if (next instanceof XMLAnnotation) {
43                                 if (skipIrrelevants) {
44                                         if (!next.isMarkedDeleted()) {
45                                                 this.next = next;
46                                                 return;
47                                         }
48                                 } else {
49                                         this.next = next;
50                                         return;
51                                 }
52                         }
53                 }
54
55                 this.next = null;
56         }
57
58         /*
59          * @see java.util.Iterator#hasNext()
60          */
61         public boolean hasNext() {
62                 return (next != null);
63         }
64
65         /*
66          * @see java.util.Iterator#next()
67          */
68         public Object next() {
69                 try {
70                         return next;
71                 } finally {
72                         skip();
73                 }
74         }
75
76         /*
77          * @see java.util.Iterator#remove()
78          */
79         public void remove() {
80                 throw new UnsupportedOperationException();
81         }
82 }