]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationIterator.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / javaeditor / JavaAnnotationIterator.java
CommitLineData
1b2798f6
EK
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
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.javaeditor;
12
13import java.util.Iterator;
14
15import org.eclipse.core.runtime.CoreException;
16
17import org.eclipse.core.resources.IMarker;
18
19import org.eclipse.jface.text.source.Annotation;
20
21import org.eclipse.ui.texteditor.MarkerAnnotation;
22
23
24/**
25 * Filters problems based on their types.
26 */
27public class JavaAnnotationIterator implements Iterator<Annotation> {
28
29 private Iterator<Annotation> fIterator;
30 private Annotation fNext;
31 private boolean fReturnAllAnnotations;
32
33
34 /**
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
38 */
39 public JavaAnnotationIterator(Iterator<Annotation> parent, boolean returnAllAnnotations) {
40 fReturnAllAnnotations= returnAllAnnotations;
41 fIterator= parent;
42 skip();
43 }
44
45 private void skip() {
46 while (fIterator.hasNext()) {
47 Annotation next= fIterator.next();
48
49 if (next.isMarkedDeleted())
50 continue;
51
52 if (fReturnAllAnnotations || next instanceof IJavaAnnotation || isProblemMarkerAnnotation(next)) {
53 fNext= next;
54 return;
55 }
56 }
57 fNext= null;
58 }
59
60 private static boolean isProblemMarkerAnnotation(Annotation annotation) {
61 if (!(annotation instanceof MarkerAnnotation))
62 return false;
63 try {
64 return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM));
65 } catch (CoreException e) {
66 return false;
67 }
68 }
69
70 /*
71 * @see Iterator#hasNext()
72 */
73 public boolean hasNext() {
74 return fNext != null;
75 }
76
77 /*
78 * @see Iterator#next()
79 */
80 public Annotation next() {
81 try {
82 return fNext;
83 } finally {
84 skip();
85 }
86 }
87
88 /*
89 * @see Iterator#remove()
90 */
91 public void remove() {
92 throw new UnsupportedOperationException();
93 }
94}