1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.javaeditor;
13 import java.util.Iterator;
15 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.resources.IMarker;
19 import org.eclipse.jface.text.source.Annotation;
21 import org.eclipse.ui.texteditor.MarkerAnnotation;
25 * Filters problems based on their types.
27 public class JavaAnnotationIterator implements Iterator<Annotation> {
29 private Iterator<Annotation> fIterator;
30 private Annotation fNext;
31 private boolean fReturnAllAnnotations;
35 * Returns a new JavaAnnotationIterator.
36 * @param parent the parent iterator to iterate over annotations
37 * @param returnAllAnnotations whether to return all annotations or just problem annotations
39 public JavaAnnotationIterator(Iterator<Annotation> parent, boolean returnAllAnnotations) {
40 fReturnAllAnnotations= returnAllAnnotations;
46 while (fIterator.hasNext()) {
47 Annotation next= fIterator.next();
49 if (next.isMarkedDeleted())
52 if (fReturnAllAnnotations || next instanceof IJavaAnnotation || isProblemMarkerAnnotation(next)) {
60 private static boolean isProblemMarkerAnnotation(Annotation annotation) {
61 if (!(annotation instanceof MarkerAnnotation))
64 return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM));
65 } catch (CoreException e) {
71 * @see Iterator#hasNext()
73 public boolean hasNext() {
78 * @see Iterator#next()
80 public Annotation next() {
89 * @see Iterator#remove()
91 public void remove() {
92 throw new UnsupportedOperationException();