-
Notifications
You must be signed in to change notification settings - Fork 82
/
JavaMarkerAnnotation.java
194 lines (162 loc) · 5.11 KB
/
JavaMarkerAnnotation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javaeditor;
import java.util.Iterator;
import org.eclipse.core.resources.IMarker;
import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.jdt.core.CorrectionEngine;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelMarker;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.ui.text.correction.ProblemLocation;
public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
public static final String ERROR_ANNOTATION_TYPE= ProblemLocation.ERROR_ANNOTATION_TYPE;
public static final String WARNING_ANNOTATION_TYPE= "org.eclipse.jdt.ui.warning"; //$NON-NLS-1$
public static final String INFO_ANNOTATION_TYPE= "org.eclipse.jdt.ui.info"; //$NON-NLS-1$
public static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
/**
* Tells whether the given marker can be treated as a Java annotation
* which will later be update by JDT Core problems.
*
* @param marker the marker
* @return <code>true</code> if the marker can be treated as a Java annotation
* @since 3.3.2
*/
static final boolean isJavaAnnotation(IMarker marker) {
// Performance
String markerType= MarkerUtilities.getMarkerType(marker);
if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType) ||
IJavaModelMarker.TASK_MARKER.equals(markerType) ||
IJavaModelMarker.TRANSIENT_PROBLEM.equals(markerType) ||
IJavaModelMarker.BUILDPATH_PROBLEM_MARKER.equals(markerType))
return true;
return MarkerUtilities.isMarkerType(marker, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
}
private IJavaAnnotation fOverlay;
public JavaMarkerAnnotation(IMarker marker) {
super(marker);
}
/*
* @see IJavaAnnotation#getArguments()
*/
@Override
public String[] getArguments() {
IMarker marker= getMarker();
if (marker != null && marker.exists() && isProblem())
return CorrectionEngine.getProblemArguments(marker);
return null;
}
/*
* @see IJavaAnnotation#getId()
*/
@Override
public int getId() {
IMarker marker= getMarker();
if (marker == null || !marker.exists())
return -1;
if (isProblem())
return marker.getAttribute(IJavaModelMarker.ID, -1);
// if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
// try {
// if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
// return IProblem.Task;
// }
// } catch (CoreException e) {
// JavaPlugin.log(e); // should no happen, we test for marker.exists
// }
// }
return -1;
}
/*
* @see IJavaAnnotation#isProblem()
*/
@Override
public boolean isProblem() {
String type= getType();
return INFO_ANNOTATION_TYPE.equals(type) || WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
}
/**
* Overlays this annotation with the given javaAnnotation.
*
* @param javaAnnotation annotation that is overlaid by this annotation
*/
public void setOverlay(IJavaAnnotation javaAnnotation) {
if (fOverlay != null)
fOverlay.removeOverlaid(this);
fOverlay= javaAnnotation;
if (!isMarkedDeleted())
markDeleted(fOverlay != null);
if (fOverlay != null)
fOverlay.addOverlaid(this);
}
/*
* @see IJavaAnnotation#hasOverlay()
*/
@Override
public boolean hasOverlay() {
return fOverlay != null;
}
/*
* @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
*/
@Override
public IJavaAnnotation getOverlay() {
return fOverlay;
}
/*
* @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
*/
@Override
public void addOverlaid(IJavaAnnotation annotation) {
// not supported
}
/*
* @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
*/
@Override
public void removeOverlaid(IJavaAnnotation annotation) {
// not supported
}
/*
* @see IJavaAnnotation#getOverlaidIterator()
*/
@Override
public Iterator<IJavaAnnotation> getOverlaidIterator() {
// not supported
return null;
}
/*
* @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
*/
@Override
public ICompilationUnit getCompilationUnit() {
IJavaElement element= JavaCore.create(getMarker().getResource());
if (element instanceof ICompilationUnit) {
return (ICompilationUnit)element;
}
return null;
}
/*
* @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getMarkerType()
*/
@Override
public String getMarkerType() {
IMarker marker= getMarker();
if (marker == null || !marker.exists())
return null;
return MarkerUtilities.getMarkerType(getMarker());
}
}