KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > text > XMLAnnotationIterator


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 org.eclipse.ant.internal.ui.editor.text;
12
13 import java.util.Iterator JavaDoc;
14 import org.eclipse.jface.text.source.IAnnotationModel;
15
16
17 /**
18  * Filters problems based on their types.
19  */

20 public class XMLAnnotationIterator implements Iterator JavaDoc {
21             
22     private Iterator JavaDoc fIterator;
23     private IXMLAnnotation fNext;
24     private boolean fSkipIrrelevants;
25     
26     public XMLAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants) {
27         fIterator= model.getAnnotationIterator();
28         fSkipIrrelevants= skipIrrelevants;
29         skip();
30     }
31     
32     private void skip() {
33         while (fIterator.hasNext()) {
34             Object JavaDoc next= fIterator.next();
35             if (next instanceof IXMLAnnotation) {
36                 IXMLAnnotation a= (IXMLAnnotation) next;
37                 if (fSkipIrrelevants) {
38                     if (a.isRelevant()) {
39                         fNext= a;
40                         return;
41                     }
42                 } else {
43                     fNext= a;
44                     return;
45                 }
46             }
47         }
48         fNext= null;
49     }
50     
51     /*
52      * @see Iterator#hasNext()
53      */

54     public boolean hasNext() {
55         return fNext != null;
56     }
57
58     /*
59      * @see Iterator#next()
60      */

61     public Object JavaDoc next() {
62         try {
63             return fNext;
64         } finally {
65             skip();
66         }
67     }
68
69     /*
70      * @see Iterator#remove()
71      */

72     public void remove() {
73         throw new UnsupportedOperationException JavaDoc();
74     }
75 }
76
Popular Tags