Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2006 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 14-24
Link Here
|
14 |
* IBM Corporation - allow initializers to provide a readable description |
14 |
* IBM Corporation - allow initializers to provide a readable description |
15 |
* of a container reference, ahead of actual resolution. |
15 |
* of a container reference, ahead of actual resolution. |
16 |
* - getDescription(IPath, IJavaProject) |
16 |
* - getDescription(IPath, IJavaProject) |
|
|
17 |
* IBM Corporation - added support for validating updates of some attributes of a particular |
18 |
* container attribute for generic container operations. |
19 |
* - validateAccessRules(IPath, IJavaProject, IAccessRule[], boolean) |
20 |
* - validateExtraAttribute(IPath, IJavaProject, IClasspathAttribute, boolean) |
21 |
* - validateSourceAttachement(IPath, IJavaProject, IPath, boolean) |
17 |
*******************************************************************************/ |
22 |
*******************************************************************************/ |
18 |
package org.eclipse.jdt.core; |
23 |
package org.eclipse.jdt.core; |
19 |
|
24 |
|
20 |
import org.eclipse.core.runtime.CoreException; |
25 |
import org.eclipse.core.runtime.CoreException; |
21 |
import org.eclipse.core.runtime.IPath; |
26 |
import org.eclipse.core.runtime.IPath; |
|
|
27 |
import org.eclipse.core.runtime.IStatus; |
28 |
import org.eclipse.core.runtime.Status; |
29 |
import org.eclipse.jdt.internal.core.JavaModelStatus; |
22 |
|
30 |
|
23 |
/** |
31 |
/** |
24 |
* Abstract base implementation of all classpath container initializer. |
32 |
* Abstract base implementation of all classpath container initializer. |
Lines 42-49
Link Here
|
42 |
* @since 2.0 |
50 |
* @since 2.0 |
43 |
*/ |
51 |
*/ |
44 |
public abstract class ClasspathContainerInitializer { |
52 |
public abstract class ClasspathContainerInitializer { |
45 |
|
53 |
|
46 |
/** |
54 |
public static final int ATTRIBUTE_NOT_SUPPORTED= 1; |
|
|
55 |
public static final int ATTRIBUTE_NOT_MODIFIABLE= 2; |
56 |
public static final int INVALID_ATTRIBUTE_VALUE= 3; |
57 |
|
58 |
/** |
47 |
* Creates a new classpath container initializer. |
59 |
* Creates a new classpath container initializer. |
48 |
*/ |
60 |
*/ |
49 |
public ClasspathContainerInitializer() { |
61 |
public ClasspathContainerInitializer() { |
Lines 51-56
Link Here
|
51 |
} |
63 |
} |
52 |
|
64 |
|
53 |
/** |
65 |
/** |
|
|
66 |
* Returns <code>true</code> if this container initializer can be requested to perform updates |
67 |
* on its own container values. If so, then an update request will be performed using |
68 |
* {@link #requestClasspathContainerUpdate(IPath, IJavaProject, IClasspathContainer)}. |
69 |
* <p> |
70 |
* @param containerPath the path of the container which requires to be updated |
71 |
* @param project the project for which the container is to be updated |
72 |
* @return returns <code>true</code> if the container can be updated |
73 |
* @since 2.1 |
74 |
*/ |
75 |
public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) { |
76 |
|
77 |
// By default, classpath container initializers do not accept updating containers |
78 |
return false; |
79 |
} |
80 |
|
81 |
/** |
54 |
* Binds a classpath container to a <code>IClasspathContainer</code> for a given project, |
82 |
* Binds a classpath container to a <code>IClasspathContainer</code> for a given project, |
55 |
* or silently fails if unable to do so. |
83 |
* or silently fails if unable to do so. |
56 |
* <p> |
84 |
* <p> |
Lines 108-162
Link Here
|
108 |
* @see IClasspathContainer |
136 |
* @see IClasspathContainer |
109 |
*/ |
137 |
*/ |
110 |
public abstract void initialize(IPath containerPath, IJavaProject project) throws CoreException; |
138 |
public abstract void initialize(IPath containerPath, IJavaProject project) throws CoreException; |
111 |
|
|
|
112 |
/** |
113 |
* Returns <code>true</code> if this container initializer can be requested to perform updates |
114 |
* on its own container values. If so, then an update request will be performed using |
115 |
* <code>ClasspathContainerInitializer#requestClasspathContainerUpdate</code>/ |
116 |
* <p> |
117 |
* @param containerPath the path of the container which requires to be updated |
118 |
* @param project the project for which the container is to be updated |
119 |
* @return returns <code>true</code> if the container can be updated |
120 |
* @since 2.1 |
121 |
*/ |
122 |
public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) { |
123 |
|
124 |
// By default, classpath container initializers do not accept updating containers |
125 |
return false; |
126 |
} |
127 |
|
139 |
|
128 |
/** |
140 |
/** |
129 |
* Request a registered container definition to be updated according to a container suggestion. The container suggestion |
141 |
* Returns an object which identifies a container for comparison purpose. This allows |
130 |
* only acts as a place-holder to pass along the information to update the matching container definition(s) held by the |
142 |
* to eliminate redundant containers when accumulating classpath entries (e.g. |
131 |
* container initializer. In particular, it is not expected to store the container suggestion as is, but rather adjust |
143 |
* runtime classpath computation). When requesting a container comparison ID, one |
132 |
* the actual container definition based on suggested changes. |
144 |
* should ensure using its corresponding container initializer. Indeed, a random container |
133 |
* <p> |
145 |
* initializer cannot be held responsible for determining comparison IDs for arbitrary |
134 |
* IMPORTANT: In reaction to receiving an update request, a container initializer will update the corresponding |
146 |
* containers. |
135 |
* container definition (after reconciling changes) at its earliest convenience, using |
|
|
136 |
* <code>JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor)</code>. |
137 |
* Until it does so, the update will not be reflected in the Java Model. |
138 |
* <p> |
139 |
* In order to anticipate whether the container initializer allows to update its containers, the predicate |
140 |
* <code>JavaCore#canUpdateClasspathContainer</code> should be used. |
141 |
* <p> |
147 |
* <p> |
142 |
* @param containerPath the path of the container which requires to be updated |
148 |
* @param containerPath the path of the container which is being checked |
143 |
* @param project the project for which the container is to be updated |
149 |
* @param project the project for which the container is to being checked |
144 |
* @param containerSuggestion a suggestion to update the corresponding container definition |
150 |
* @return returns an Object identifying the container for comparison |
145 |
* @throws CoreException when <code>JavaCore#setClasspathContainer</code> would throw any. |
151 |
* @since 3.0 |
146 |
* @see JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], org.eclipse.core.runtime.IProgressMonitor) |
|
|
147 |
* @see ClasspathContainerInitializer#canUpdateClasspathContainer(IPath, IJavaProject) |
148 |
* @since 2.1 |
149 |
*/ |
152 |
*/ |
150 |
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { |
153 |
public Object getComparisonID(IPath containerPath, IJavaProject project) { |
151 |
|
154 |
|
152 |
// By default, classpath container initializers do not accept updating containers |
155 |
// By default, containers are identical if they have the same containerPath first segment, |
153 |
} |
156 |
// but this may be refined by other container initializer implementations. |
|
|
157 |
if (containerPath == null) { |
158 |
return null; |
159 |
} else { |
160 |
return containerPath.segment(0); |
161 |
} |
162 |
} |
154 |
|
163 |
|
155 |
/** |
164 |
/** |
156 |
* Returns a readable description for a container path. A readable description for a container path can be |
165 |
* Returns a readable description for a container path. A readable description for a container path can be |
157 |
* used for improving the display of references to container, without actually needing to resolve them. |
166 |
* used for improving the display of references to container, without actually needing to resolve them. |
158 |
* A good implementation should answer a description consistent with the description of the associated |
167 |
* A good implementation should answer a description consistent with the description of the associated |
159 |
* target container (see <code>IClasspathContainer.getDescription()</code>). |
168 |
* target container (see {@link IClasspathContainer#getDescription()}). |
160 |
* |
169 |
* |
161 |
* @param containerPath the path of the container which requires a readable description |
170 |
* @param containerPath the path of the container which requires a readable description |
162 |
* @param project the project from which the container is referenced |
171 |
* @param project the project from which the container is referenced |
Lines 171-177
Link Here
|
171 |
|
180 |
|
172 |
/** |
181 |
/** |
173 |
* Returns a classpath container that is used after this initializer failed to bind a classpath container |
182 |
* Returns a classpath container that is used after this initializer failed to bind a classpath container |
174 |
* to a <code>IClasspathContainer</code> for the given project. A non-<code>null</code> |
183 |
* to a {@link IClasspathContainer} for the given project. A non-<code>null</code> |
175 |
* failure container indicates that there will be no more request to initialize the given container |
184 |
* failure container indicates that there will be no more request to initialize the given container |
176 |
* for the given project. |
185 |
* for the given project. |
177 |
* <p> |
186 |
* <p> |
Lines 208-234
Link Here
|
208 |
} |
217 |
} |
209 |
|
218 |
|
210 |
/** |
219 |
/** |
211 |
* Returns an object which identifies a container for comparison purpose. This allows |
220 |
* Request a registered container definition to be updated according to a container suggestion. The container suggestion |
212 |
* to eliminate redundant containers when accumulating classpath entries (e.g. |
221 |
* only acts as a place-holder to pass along the information to update the matching container definition(s) held by the |
213 |
* runtime classpath computation). When requesting a container comparison ID, one |
222 |
* container initializer. In particular, it is not expected to store the container suggestion as is, but rather adjust |
214 |
* should ensure using its corresponding container initializer. Indeed, a random container |
223 |
* the actual container definition based on suggested changes. |
215 |
* initializer cannot be held responsible for determining comparison IDs for arbitrary |
|
|
216 |
* containers. |
217 |
* <p> |
224 |
* <p> |
218 |
* @param containerPath the path of the container which is being checked |
225 |
* IMPORTANT: In reaction to receiving an update request, a container initializer will update the corresponding |
219 |
* @param project the project for which the container is to being checked |
226 |
* container definition (after reconciling changes) at its earliest convenience, using |
220 |
* @return returns an Object identifying the container for comparison |
227 |
* {@link JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], org.eclipse.core.runtime.IProgressMonitor)}. |
221 |
* @since 3.0 |
228 |
* Until it does so, the update will not be reflected in the Java Model. |
|
|
229 |
* <p> |
230 |
* In order to anticipate whether the container initializer allows to update its containers, the predicate |
231 |
* {@link #canUpdateClasspathContainer(IPath, IJavaProject)} should be used. |
232 |
* <p> |
233 |
* @param containerPath the path of the container which requires to be updated |
234 |
* @param project the project for which the container is to be updated |
235 |
* @param containerSuggestion a suggestion to update the corresponding container definition |
236 |
* @throws CoreException when <code>JavaCore#setClasspathContainer</code> would throw any. |
237 |
* @see JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], org.eclipse.core.runtime.IProgressMonitor) |
238 |
* @see ClasspathContainerInitializer#canUpdateClasspathContainer(IPath, IJavaProject) |
239 |
* @since 2.1 |
222 |
*/ |
240 |
*/ |
223 |
public Object getComparisonID(IPath containerPath, IJavaProject project) { |
241 |
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { |
224 |
|
242 |
|
225 |
// By default, containers are identical if they have the same containerPath first segment, |
243 |
// By default, classpath container initializers do not accept updating containers |
226 |
// but this may be refined by other container initializer implementations. |
244 |
} |
227 |
if (containerPath == null) { |
245 |
|
228 |
return null; |
246 |
/** |
229 |
} else { |
247 |
* Returns whether access rules may be updated on a container or not. |
230 |
return containerPath.segment(0); |
248 |
* <p> |
|
|
249 |
* The returned status is {@link IStatus#OK} if the access rules |
250 |
* attribute is modifiable and optionally have a valid value.<br> |
251 |
* Otherwise (i.e. if {@link IStatus#ERROR} is returned), then the |
252 |
* {@link IStatus#getCode()} can have one of the following value: |
253 |
* <ul> |
254 |
* <li>{@link #ATTRIBUTE_NOT_MODIFIABLE}: the access rule |
255 |
* attribute is not modifiable</li> |
256 |
* <li>{@link #INVALID_ATTRIBUTE_VALUE}: the access rule |
257 |
* attribute is modifiable but the given value is invalid.</li> |
258 |
* </ul> |
259 |
* The status message can contain more information. |
260 |
* </p><p> |
261 |
* If the subclass does not override this method, then default behavior is |
262 |
* to return {@link IStatus#OK} if the classpath container can be updated |
263 |
* (see {@link #canUpdateClasspathContainer(IPath, IJavaProject)}). |
264 |
* Otherwise it returns {@link IStatus#ERROR} with |
265 |
* {@link #ATTRIBUTE_NOT_MODIFIABLE} code. |
266 |
* </p> |
267 |
* |
268 |
* @param containerPath the path of the container which requires to be |
269 |
* updated |
270 |
* @param project the project for which the container is to be updated |
271 |
* @param rules the access rule to validate |
272 |
* @param checkValue check if the value also need to be tested |
273 |
* @return returns the resulting status for all tested attributes |
274 |
* |
275 |
* @since 3.3 |
276 |
*/ |
277 |
public IStatus validateAccessRules(IPath containerPath, |
278 |
IJavaProject project, |
279 |
IAccessRule[] rules, |
280 |
boolean checkValue) { |
281 |
|
282 |
if (canUpdateClasspathContainer(containerPath, project)) { |
283 |
return Status.OK_STATUS; |
231 |
} |
284 |
} |
|
|
285 |
return new JavaModelStatus(ATTRIBUTE_NOT_MODIFIABLE); |
232 |
} |
286 |
} |
233 |
} |
|
|
234 |
|
287 |
|
|
|
288 |
/** |
289 |
* Returns whether an extra attribute may be updated on a container or not. |
290 |
* <p> |
291 |
* The returned status is {@link IStatus#OK} if the extra |
292 |
* attribute is modifiable and optionally have a valid value.<br> |
293 |
* Otherwise (i.e. if {@link IStatus#ERROR} is returned), then the |
294 |
* {@link IStatus#getCode()} can have one of the following value: |
295 |
* <ul> |
296 |
* <li>{@link #ATTRIBUTE_NOT_SUPPORTED}: |
297 |
* at least one attribute is not supported</li> |
298 |
* <li>{@link #ATTRIBUTE_NOT_MODIFIABLE}: the access rule |
299 |
* attribute is not modifiable</li> |
300 |
* <li>{@link #INVALID_ATTRIBUTE_VALUE}: the access rule |
301 |
* attribute is modifiable but the given value is invalid.</li> |
302 |
* </ul> |
303 |
* The status message can contain more information. |
304 |
* </p><p> |
305 |
* If the subclass does not override this method, then default behavior is |
306 |
* to return {@link IStatus#OK} if the classpath container can be updated |
307 |
* (see {@link #canUpdateClasspathContainer(IPath, IJavaProject)}). |
308 |
* Otherwise it returns {@link IStatus#ERROR} with |
309 |
* {@link #ATTRIBUTE_NOT_MODIFIABLE} code. |
310 |
* </p> |
311 |
* |
312 |
* @param containerPath the path of the container which requires to be |
313 |
* updated |
314 |
* @param project the project for which the container is to be updated |
315 |
* @param extraAttribute the extra attribute to validate |
316 |
* @param checkValue check if the value also need to be tested |
317 |
* @return returns the resulting status for all tested attributes |
318 |
* |
319 |
* @since 3.3 |
320 |
*/ |
321 |
public IStatus validateExtraAttribute(IPath containerPath, |
322 |
IJavaProject project, |
323 |
IClasspathAttribute extraAttribute, |
324 |
boolean checkValue) { |
325 |
|
326 |
if (canUpdateClasspathContainer(containerPath, project)) { |
327 |
return Status.OK_STATUS; |
328 |
} |
329 |
return new JavaModelStatus(ATTRIBUTE_NOT_MODIFIABLE); |
330 |
} |
331 |
|
332 |
/** |
333 |
* Returns whether a source attachment may be updated |
334 |
* on a container or not. |
335 |
* <p> |
336 |
* The returned status is {@link IStatus#OK} if the source attachment |
337 |
* attribute is modifiable and optionally have a valid value.<br> |
338 |
* Otherwise (i.e. if {@link IStatus#ERROR} is returned), then the |
339 |
* {@link IStatus#getCode()} can have one of the following value: |
340 |
* <ul> |
341 |
* <li>{@link #ATTRIBUTE_NOT_MODIFIABLE}: the access rule |
342 |
* attribute is not modifiable</li> |
343 |
* <li>{@link #INVALID_ATTRIBUTE_VALUE}: the access rule |
344 |
* attribute is modifiable but the given value is invalid.</li> |
345 |
* </ul> |
346 |
* The status message can contain more information. |
347 |
* </p><p> |
348 |
* If the subclass does not override this method, then default behavior is |
349 |
* to return {@link IStatus#OK} if the classpath container can be updated |
350 |
* (see {@link #canUpdateClasspathContainer(IPath, IJavaProject)}). |
351 |
* Otherwise it returns {@link IStatus#ERROR} with |
352 |
* {@link #ATTRIBUTE_NOT_MODIFIABLE} code. |
353 |
* </p> |
354 |
* |
355 |
* @param containerPath the path of the container which requires to be |
356 |
* updated |
357 |
* @param project the project for which the container is to be updated |
358 |
* @param path the source attachment path to validate |
359 |
* @param checkValue check if the value also need to be tested |
360 |
* @return returns the resulting status for all tested attributes |
361 |
* |
362 |
* @since 3.3 |
363 |
*/ |
364 |
public IStatus validateSourceAttachment(IPath containerPath, |
365 |
IJavaProject project, |
366 |
IPath path, |
367 |
boolean checkValue) { |
368 |
|
369 |
if (canUpdateClasspathContainer(containerPath, project)) { |
370 |
return Status.OK_STATUS; |
371 |
} |
372 |
return new JavaModelStatus(ATTRIBUTE_NOT_MODIFIABLE); |
373 |
} |
374 |
} |