]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaMarkerAnnotation.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / javaeditor / JavaMarkerAnnotation.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.resources.IMarker;
16
17import org.eclipse.ui.texteditor.MarkerAnnotation;
18import org.eclipse.ui.texteditor.MarkerUtilities;
19
20import org.eclipse.jdt.core.CorrectionEngine;
21import org.eclipse.jdt.core.ICompilationUnit;
22import org.eclipse.jdt.core.IJavaElement;
23import org.eclipse.jdt.core.IJavaModelMarker;
24import org.eclipse.jdt.core.JavaCore;
25
26import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.CompilationUnitAnnotationModel;
27import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.ProblemAnnotation;
28
29
30public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
31
32 public static final String ERROR_ANNOTATION_TYPE= "org.eclipse.jdt.ui.error"; //$NON-NLS-1$
33 public static final String WARNING_ANNOTATION_TYPE= "org.eclipse.jdt.ui.warning"; //$NON-NLS-1$
34 public static final String INFO_ANNOTATION_TYPE= "org.eclipse.jdt.ui.info"; //$NON-NLS-1$
35 public static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
36
37
38 /**
39 * Tells whether the given marker can be treated as a Java annotation
40 * which will later be update by JDT Core problems.
41 *
42 * @param marker the marker
43 * @return <code>true</code> if the marker can be treated as a Java annotation
44 * @since 3.3.2
45 */
46 static final boolean isJavaAnnotation(IMarker marker) {
47 // Performance
48 String markerType= MarkerUtilities.getMarkerType(marker);
49 if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType) ||
50 IJavaModelMarker.TASK_MARKER.equals(markerType) ||
51 IJavaModelMarker.TRANSIENT_PROBLEM.equals(markerType) ||
52 IJavaModelMarker.BUILDPATH_PROBLEM_MARKER.equals(markerType))
53 return true;
54
55
56 return MarkerUtilities.isMarkerType(marker, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
57 }
58
59 private IJavaAnnotation fOverlay;
60
61
62 public JavaMarkerAnnotation(IMarker marker) {
63 super(marker);
64 }
65
66 /*
67 * @see IJavaAnnotation#getArguments()
68 */
69 public String[] getArguments() {
70 IMarker marker= getMarker();
71 if (marker != null && marker.exists() && isProblem())
72 return CorrectionEngine.getProblemArguments(marker);
73 return null;
74 }
75
76 /*
77 * @see IJavaAnnotation#getId()
78 */
79 public int getId() {
80 IMarker marker= getMarker();
81 if (marker == null || !marker.exists())
82 return -1;
83
84 if (isProblem())
85 return marker.getAttribute(IJavaModelMarker.ID, -1);
86
87// if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
88// try {
89// if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
90// return IProblem.Task;
91// }
92// } catch (CoreException e) {
93// JavaPlugin.log(e); // should no happen, we test for marker.exists
94// }
95// }
96
97 return -1;
98 }
99
100 /*
101 * @see IJavaAnnotation#isProblem()
102 */
103 public boolean isProblem() {
104 String type= getType();
105 return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
106 }
107
108 /**
109 * Overlays this annotation with the given javaAnnotation.
110 *
111 * @param javaAnnotation annotation that is overlaid by this annotation
112 */
113 public void setOverlay(IJavaAnnotation javaAnnotation) {
114 if (fOverlay != null)
115 fOverlay.removeOverlaid(this);
116
117 fOverlay= javaAnnotation;
118 if (!isMarkedDeleted())
119 markDeleted(fOverlay != null);
120
121 if (fOverlay != null)
122 fOverlay.addOverlaid(this);
123 }
124
125 /*
126 * @see IJavaAnnotation#hasOverlay()
127 */
128 public boolean hasOverlay() {
129 return fOverlay != null;
130 }
131
132 /*
133 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
134 */
135 public IJavaAnnotation getOverlay() {
136 return fOverlay;
137 }
138
139 /*
140 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
141 */
142 public void addOverlaid(IJavaAnnotation annotation) {
143 // not supported
144 }
145
146 /*
147 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
148 */
149 public void removeOverlaid(IJavaAnnotation annotation) {
150 // not supported
151 }
152
153 /*
154 * @see IJavaAnnotation#getOverlaidIterator()
155 */
156 public Iterator<IJavaAnnotation> getOverlaidIterator() {
157 // not supported
158 return null;
159 }
160
161 /*
162 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
163 */
164 public ICompilationUnit getCompilationUnit() {
165 IJavaElement element= JavaCore.create(getMarker().getResource());
166 if (element instanceof ICompilationUnit) {
167 return (ICompilationUnit)element;
168 }
169 return null;
170 }
171
172 /*
173 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getMarkerType()
174 */
175 public String getMarkerType() {
176 IMarker marker= getMarker();
177 if (marker == null || !marker.exists())
178 return null;
179
180 return MarkerUtilities.getMarkerType(getMarker());
181 }
182
183 public void generated_6101923095272565830(ProblemAnnotation problemAnnotation, CompilationUnitAnnotationModel compilationunitannotationmodel) {
184 if (isProblem()) {
185 setOverlay(problemAnnotation);
186 compilationunitannotationmodel.fPreviouslyOverlaid.remove(this);
187 compilationunitannotationmodel.fCurrentlyOverlaid.add(this);
188 }
189 }
190}