View | Details | Raw Unified | Return to bug 168077 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/core/ClasspathContainerInitializer.java (-46 / +178 lines)
Lines 17-24 Link Here
17
 *******************************************************************************/
17
 *******************************************************************************/
18
package org.eclipse.jdt.core;
18
package org.eclipse.jdt.core;
19
19
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.*;
21
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.jdt.internal.core.JavaModelStatus;
22
22
23
/**
23
/**
24
 * Abstract base implementation of all classpath container initializer.
24
 * Abstract base implementation of all classpath container initializer.
Lines 27-48 Link Here
27
 * <p>
27
 * <p>
28
 * Clients should subclass this class to implement a specific classpath
28
 * Clients should subclass this class to implement a specific classpath
29
 * container initializer. The subclass must have a public 0-argument
29
 * container initializer. The subclass must have a public 0-argument
30
 * constructor and a concrete implementation of <code>initialize</code>.
30
 * constructor and a concrete implementation of {@link #initialize(IPath, IJavaProject)}.
31
 * <p>
31
 * <p>
32
 * Multiple classpath containers can be registered, each of them declares
32
 * Multiple classpath containers can be registered, each of them declares
33
 * the container ID they can handle, so as to narrow the set of containers they
33
 * the container ID they can handle, so as to narrow the set of containers they
34
 * can resolve, in other words, a container initializer is guaranteed to only be 
34
 * can resolve, in other words, a container initializer is guaranteed to only be
35
 * activated to resolve containers which match the ID they registered onto.
35
 * activated to resolve containers which match the ID they registered onto.
36
 * <p>
36
 * <p>
37
 * In case multiple container initializers collide on the same container ID, the first
37
 * In case multiple container initializers collide on the same container ID, the first
38
 * registered one will be invoked.
38
 * registered one will be invoked.
39
 * 
39
 *
40
 * @see IClasspathEntry
40
 * @see IClasspathEntry
41
 * @see IClasspathContainer
41
 * @see IClasspathContainer
42
 * @since 2.0
42
 * @since 2.0
43
 */
43
 */
44
public abstract class ClasspathContainerInitializer {
44
public abstract class ClasspathContainerInitializer {
45
	
45
46
	/**
47
	 * Status code indicating that an attribute is not supported.
48
	 *
49
	 * @see #getAccessRulesStatus(IPath, IJavaProject)
50
	 * @see #getAttributeStatus(IPath, IJavaProject, String)
51
	 * @see #getSourceAttachmentStatus(IPath, IJavaProject)
52
	 *
53
	 * @since 3.3
54
	 */
55
	public static final int ATTRIBUTE_NOT_SUPPORTED= 1;
56
57
	/**
58
	 * Status code indicating that an attribute is not modifiable.
59
	 *
60
	 * @see #getAccessRulesStatus(IPath, IJavaProject)
61
	 * @see #getAttributeStatus(IPath, IJavaProject, String)
62
	 * @see #getSourceAttachmentStatus(IPath, IJavaProject)
63
	 *
64
	 * @since 3.3
65
	 */
66
	public static final int ATTRIBUTE_READ_ONLY= 2;
67
46
   /**
68
   /**
47
     * Creates a new classpath container initializer.
69
     * Creates a new classpath container initializer.
48
     */
70
     */
Lines 59-65 Link Here
59
     * the second segment can be used as an additional hint when performing the resolution.
81
     * the second segment can be used as an additional hint when performing the resolution.
60
     * <p>
82
     * <p>
61
     * The initializer is invoked if a container path needs to be resolved for a given project, and no
83
     * The initializer is invoked if a container path needs to be resolved for a given project, and no
62
     * value for it was recorded so far. The implementation of the initializer would typically set the 
84
     * value for it was recorded so far. The implementation of the initializer would typically set the
63
     * corresponding container using <code>JavaCore#setClasspathContainer</code>.
85
     * corresponding container using <code>JavaCore#setClasspathContainer</code>.
64
     * <p>
86
     * <p>
65
     * A container initialization can be indirectly performed while attempting to resolve a project
87
     * A container initialization can be indirectly performed while attempting to resolve a project
Lines 69-78 Link Here
69
     * infinite regression of initializations.
91
     * infinite regression of initializations.
70
     * <p>
92
     * <p>
71
     * A container initialization may also occur indirectly when setting a project classpath, as the operation
93
     * A container initialization may also occur indirectly when setting a project classpath, as the operation
72
     * needs to resolve the classpath for validation purpose. While the operation is in progress, a referenced 
94
     * needs to resolve the classpath for validation purpose. While the operation is in progress, a referenced
73
     * container initializer may be invoked. If the initializer further tries to access the referring project classpath, 
95
     * container initializer may be invoked. If the initializer further tries to access the referring project classpath,
74
     * it will not see the new assigned classpath until the operation has completed. Note that once the Java 
96
     * it will not see the new assigned classpath until the operation has completed. Note that once the Java
75
     * change notification occurs (at the end of the operation), the model has been updated, and the project 
97
     * change notification occurs (at the end of the operation), the model has been updated, and the project
76
     * classpath can be queried normally.
98
     * classpath can be queried normally.
77
	 * <p>
99
	 * <p>
78
	 * This method is called by the Java model to give the party that defined
100
	 * This method is called by the Java model to give the party that defined
Lines 96-118 Link Here
96
	 * </ul>
118
	 * </ul>
97
	 * The effects of using other Java model APIs are unspecified.
119
	 * The effects of using other Java model APIs are unspecified.
98
	 * </p>
120
	 * </p>
99
	 * 
121
	 *
100
     * @param containerPath a two-segment path (ID/hint) identifying the container that needs 
122
     * @param containerPath a two-segment path (ID/hint) identifying the container that needs
101
     * 	to be resolved
123
     * 	to be resolved
102
     * @param project the Java project in which context the container is to be resolved.
124
     * @param project the Java project in which context the container is to be resolved.
103
     *    This allows generic containers to be bound with project specific values.
125
     *    This allows generic containers to be bound with project specific values.
104
     * @throws CoreException if an exception occurs during the initialization
126
     * @throws CoreException if an exception occurs during the initialization
105
     * 
127
     *
106
     * @see JavaCore#getClasspathContainer(IPath, IJavaProject)
128
     * @see JavaCore#getClasspathContainer(IPath, IJavaProject)
107
     * @see JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], org.eclipse.core.runtime.IProgressMonitor)
129
     * @see JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], org.eclipse.core.runtime.IProgressMonitor)
108
     * @see IClasspathContainer
130
     * @see IClasspathContainer
109
     */
131
     */
110
    public abstract void initialize(IPath containerPath, IJavaProject project) throws CoreException;
132
    public abstract void initialize(IPath containerPath, IJavaProject project) throws CoreException;
111
    
133
112
    /**
134
    /**
113
     * Returns <code>true</code> if this container initializer can be requested to perform updates 
135
     * 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
136
     * on its own container values. If so, then an update request will be performed using
115
     * <code>ClasspathContainerInitializer#requestClasspathContainerUpdate</code>/
137
     * {@link #requestClasspathContainerUpdate(IPath, IJavaProject, IClasspathContainer)}.
116
     * <p>
138
     * <p>
117
     * @param containerPath the path of the container which requires to be updated
139
     * @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
140
     * @param project the project for which the container is to be updated
Lines 120-143 Link Here
120
     * @since 2.1
142
     * @since 2.1
121
     */
143
     */
122
    public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) {
144
    public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) {
123
    	
145
124
		// By default, classpath container initializers do not accept updating containers
146
		// By default, classpath container initializers do not accept updating containers
125
    	return false; 
147
    	return false;
126
    }
148
    }
127
149
128
	/**
150
	/**
129
	 * Request a registered container definition to be updated according to a container suggestion. The container suggestion 
151
	 * Request a registered container definition to be updated according to a container suggestion. The container suggestion
130
	 * only acts as a place-holder to pass along the information to update the matching container definition(s) held by the 
152
	 * only acts as a place-holder to pass along the information to update the matching container definition(s) held by the
131
	 * container initializer. In particular, it is not expected to store the container suggestion as is, but rather adjust 
153
	 * container initializer. In particular, it is not expected to store the container suggestion as is, but rather adjust
132
	 * the actual container definition based on suggested changes.
154
	 * the actual container definition based on suggested changes.
133
	 * <p>
155
	 * <p>
134
	 * IMPORTANT: In reaction to receiving an update request, a container initializer will update the corresponding
156
	 * IMPORTANT: In reaction to receiving an update request, a container initializer will update the corresponding
135
	 * container definition (after reconciling changes) at its earliest convenience, using 
157
	 * container definition (after reconciling changes) at its earliest convenience, using
136
	 * <code>JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor)</code>. 
158
	 * {@link JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor)}.
137
	 * Until it does so, the update will not be reflected in the Java Model.
159
	 * Until it does so, the update will not be reflected in the Java Model.
138
	 * <p>
160
	 * <p>
139
	 * In order to anticipate whether the container initializer allows to update its containers, the predicate
161
	 * In order to anticipate whether the container initializer allows to update its containers, the predicate
140
	 * <code>JavaCore#canUpdateClasspathContainer</code> should be used.
162
	 * {@link #canUpdateClasspathContainer(IPath, IJavaProject)} should be used.
141
	 * <p>
163
	 * <p>
142
	 * @param containerPath the path of the container which requires to be updated
164
	 * @param containerPath the path of the container which requires to be updated
143
     * @param project the project for which the container is to be updated
165
     * @param project the project for which the container is to be updated
Lines 147-152 Link Here
147
	 * @see ClasspathContainerInitializer#canUpdateClasspathContainer(IPath, IJavaProject)
169
	 * @see ClasspathContainerInitializer#canUpdateClasspathContainer(IPath, IJavaProject)
148
	 * @since 2.1
170
	 * @since 2.1
149
	 */
171
	 */
172
150
    public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
173
    public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
151
174
152
		// By default, classpath container initializers do not accept updating containers
175
		// By default, classpath container initializers do not accept updating containers
Lines 155-177 Link Here
155
	/**
178
	/**
156
	 * Returns a readable description for a container path. A readable description for a container path can be
179
	 * 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.
180
	 * 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 
181
	 * A good implementation should answer a description consistent with the description of the associated
159
	 * target container (see <code>IClasspathContainer.getDescription()</code>).
182
	 * target container (see {@link IClasspathContainer#getDescription()}).
160
	 * 
183
	 *
161
	 * @param containerPath the path of the container which requires a readable description
184
	 * @param containerPath the path of the container which requires a readable description
162
	 * @param project the project from which the container is referenced
185
	 * @param project the project from which the container is referenced
163
	 * @return a string description of the container
186
	 * @return a string description of the container
164
	 * @since 2.1
187
	 * @since 2.1
165
	 */    
188
	 */
166
    public String getDescription(IPath containerPath, IJavaProject project) {
189
    public String getDescription(IPath containerPath, IJavaProject project) {
167
    	
190
168
    	// By default, a container path is the only available description
191
    	// By default, a container path is the only available description
169
    	return containerPath.makeRelative().toString();
192
    	return containerPath.makeRelative().toString();
170
    }
193
    }
171
    
194
172
    /**
195
    /**
173
     * Returns a classpath container that is used after this initializer failed to bind a classpath container 
196
     * 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>
197
     * 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
198
     * failure container indicates that there will be no more request to initialize the given container
176
     * for the given project.
199
     * for the given project.
177
     * <p>
200
     * <p>
Lines 179-185 Link Here
179
     * Clients wishing to get a chance to run the initializer again should override this method
202
     * Clients wishing to get a chance to run the initializer again should override this method
180
     * and return <code>null</code>.
203
     * and return <code>null</code>.
181
     * </p>
204
     * </p>
182
     * 
205
     *
183
 	 * @param containerPath the path of the container which failed to initialize
206
 	 * @param containerPath the path of the container which failed to initialize
184
	 * @param project the project from which the container is referenced
207
	 * @param project the project from which the container is referenced
185
	 * @return the default failure container, or <code>null</code> if wishing to run the initializer again
208
	 * @return the default failure container, or <code>null</code> if wishing to run the initializer again
Lines 187-218 Link Here
187
     */
210
     */
188
    public IClasspathContainer getFailureContainer(final IPath containerPath, IJavaProject project) {
211
    public IClasspathContainer getFailureContainer(final IPath containerPath, IJavaProject project) {
189
    	final String description = getDescription(containerPath, project);
212
    	final String description = getDescription(containerPath, project);
190
    	return 
213
    	return
191
    		new IClasspathContainer() {
214
    		new IClasspathContainer() {
192
				public IClasspathEntry[] getClasspathEntries() { 
215
				public IClasspathEntry[] getClasspathEntries() {
193
					return new IClasspathEntry[0]; 
216
					return new IClasspathEntry[0];
194
				}
217
				}
195
				public String getDescription() { 
218
				public String getDescription() {
196
					return description;
219
					return description;
197
				}
220
				}
198
				public int getKind() { 
221
				public int getKind() {
199
					return 0; 
222
					return 0;
200
				}
223
				}
201
				public IPath getPath() { 
224
				public IPath getPath() {
202
					return containerPath; 
225
					return containerPath;
203
				}
226
				}
204
				public String toString() { 
227
				public String toString() {
205
					return getDescription(); 
228
					return getDescription();
206
				}
229
				}
207
			};
230
			};
208
	}
231
	}
209
232
210
	/**
233
	/**
211
	 * Returns an object which identifies a container for comparison purpose. This allows
234
	 * Returns an object which identifies a container for comparison purpose. This allows
212
	 * to eliminate redundant containers when accumulating classpath entries (e.g. 
235
	 * to eliminate redundant containers when accumulating classpath entries (e.g.
213
	 * runtime classpath computation). When requesting a container comparison ID, one
236
	 * runtime classpath computation). When requesting a container comparison ID, one
214
	 * should ensure using its corresponding container initializer. Indeed, a random container
237
	 * should ensure using its corresponding container initializer. Indeed, a random container
215
	 * initializer cannot be held responsible for determining comparison IDs for arbitrary 
238
	 * initializer cannot be held responsible for determining comparison IDs for arbitrary
216
	 * containers.
239
	 * containers.
217
	 * <p>
240
	 * <p>
218
	 * @param containerPath the path of the container which is being checked
241
	 * @param containerPath the path of the container which is being checked
Lines 230-234 Link Here
230
			return containerPath.segment(0);
253
			return containerPath.segment(0);
231
		}
254
		}
232
	}
255
	}
256
257
	/**
258
	 * Returns the access rules attribute status according to this initializer.
259
	 * <p>
260
	 * The returned {@link IStatus status} can have one of the following severities:
261
	 * <ul>
262
	 * <li>{@link IStatus#OK OK}: means that the attribute is supported
263
	 * 	<strong>and</strong> is modifiable</li>
264
	 * <li>{@link IStatus#ERROR ERROR}: means that either the attribute
265
	 * 	is not supported or is not modifiable.<br>
266
	 * 	In this case, the {@link IStatus#getCode() code}will have
267
	 * 	respectively the {@link #ATTRIBUTE_NOT_SUPPORTED} value
268
	 * 	or the {@link #ATTRIBUTE_READ_ONLY} value.</li>
269
	 * </ul>
270
	 * </p><p>
271
	 * The status message can contain more information.
272
	 * </p><p>
273
	 * If the subclass does not override this method, then the default behavior is
274
	 * to return {@link IStatus#OK OK} if and only if the classpath container can
275
	 * be updated (see {@link #canUpdateClasspathContainer(IPath, IJavaProject)}).
276
	 * </p>
277
	 *
278
	 * @param containerPath the path of the container which requires to be
279
	 * 	updated
280
	 * @param project the project for which the container is to be updated
281
	 * @return returns the source attachment attirbute status
282
	 *
283
	 * @since 3.3
284
	 */
285
	public IStatus getAccessRulesStatus(IPath containerPath, IJavaProject project) {
286
287
		if (canUpdateClasspathContainer(containerPath, project)) {
288
			return Status.OK_STATUS;
289
		}
290
		return new JavaModelStatus(ATTRIBUTE_READ_ONLY);
291
	}
292
293
	/**
294
	 * Returns an extra attribute status according to this initializer.
295
	 * <p>
296
	 * The returned {@link IStatus status} can have one of the following severities:
297
	 * <ul>
298
	 * <li>{@link IStatus#OK OK}: means that the attribute is supported
299
	 * 	<strong>and</strong> is modifiable</li>
300
	 * <li>{@link IStatus#ERROR ERROR}: means that either the attribute
301
	 * 	is not supported or is not modifiable.<br>
302
	 * 	In this case, the {@link IStatus#getCode() code}will have
303
	 * 	respectively the {@link #ATTRIBUTE_NOT_SUPPORTED} value
304
	 * 	or the {@link #ATTRIBUTE_READ_ONLY} value.</li>
305
	 * </ul>
306
	 * </p><p>
307
	 * The status message can contain more information.
308
	 * </p><p>
309
	 * If the subclass does not override this method, then the default behavior is
310
	 * to return {@link IStatus#OK OK} if and only if the classpath container can
311
	 * be updated (see {@link #canUpdateClasspathContainer(IPath, IJavaProject)}).
312
	 * </p>
313
	 *
314
	 * @param containerPath the path of the container which requires to be
315
	 * 	updated
316
	 * @param project the project for which the container is to be updated
317
	 * @param attributeKey the key of the extra attribute
318
	 * @return returns the source attachment attirbute status
319
	 *
320
	 * @since 3.3
321
	 */
322
	public IStatus getAttributeStatus(IPath containerPath, IJavaProject project, String attributeKey) {
323
324
		if (canUpdateClasspathContainer(containerPath, project)) {
325
			return Status.OK_STATUS;
326
		}
327
		return new JavaModelStatus(ATTRIBUTE_READ_ONLY);
328
	}
329
330
	/**
331
	 * Returns the source attachment attribute status according to this initializer.
332
	 * <p>
333
	 * The returned {@link IStatus status} can have one of the following severities:
334
	 * <ul>
335
	 * <li>{@link IStatus#OK OK}: means that the attribute is supported
336
	 * 	<strong>and</strong> is modifiable</li>
337
	 * <li>{@link IStatus#ERROR ERROR}: means that either the attribute
338
	 * 	is not supported or is not modifiable.<br>
339
	 * 	In this case, the {@link IStatus#getCode() code}will have
340
	 * 	respectively the {@link #ATTRIBUTE_NOT_SUPPORTED} value
341
	 * 	or the {@link #ATTRIBUTE_READ_ONLY} value.</li>
342
	 * </ul>
343
	 * </p><p>
344
	 * The status message can contain more information.
345
	 * </p><p>
346
	 * If the subclass does not override this method, then the default behavior is
347
	 * to return {@link IStatus#OK OK} if and only if the classpath container can
348
	 * be updated (see {@link #canUpdateClasspathContainer(IPath, IJavaProject)}).
349
	 * </p>
350
	 *
351
	 * @param containerPath the path of the container which requires to be
352
	 * 	updated
353
	 * @param project the project for which the container is to be updated
354
	 * @return returns the source attachment attirbute status
355
	 *
356
	 * @since 3.3
357
	 */
358
	public IStatus getSourceAttachmentStatus(IPath containerPath, IJavaProject project) {
359
360
		if (canUpdateClasspathContainer(containerPath, project)) {
361
			return Status.OK_STATUS;
362
		}
363
		return new JavaModelStatus(ATTRIBUTE_READ_ONLY);
364
	}
233
}
365
}
234
366

Return to bug 168077