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

Collapse All | Expand All

(-)model/org/eclipse/jdt/core/IWorkingCopy.java (-1 / +1 lines)
Lines 277-283 Link Here
277
	 * the buffer, or this element if this element is already a working copy
277
	 * the buffer, or this element if this element is already a working copy
278
	 * @since 2.0
278
	 * @since 2.0
279
	 * 
279
	 * 
280
	 * @deprecated Use {@link ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)} instead.
280
	 * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead.
281
	 */
281
	 */
282
	IJavaElement getWorkingCopy(
282
	IJavaElement getWorkingCopy(
283
		IProgressMonitor monitor,
283
		IProgressMonitor monitor,
(-)model/org/eclipse/jdt/core/ICompilationUnit.java (-57 / +97 lines)
Lines 30-36 Link Here
30
 * This interface is not intended to be implemented by clients.
30
 * This interface is not intended to be implemented by clients.
31
 * </p>
31
 * </p>
32
 */
32
 */
33
public interface ICompilationUnit extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation, ICodeAssist {
33
public interface ICompilationUnit extends IJavaFile, IWorkingCopy, ISourceManipulation {
34
/**
34
/**
35
 * Constant indicating that a reconcile operation should not return an AST.
35
 * Constant indicating that a reconcile operation should not return an AST.
36
 * @since 3.0
36
 * @since 3.0
Lines 67-74 Link Here
67
 * @throws JavaModelException if this compilation unit could not become a working copy.
67
 * @throws JavaModelException if this compilation unit could not become a working copy.
68
 * @see #discardWorkingCopy()
68
 * @see #discardWorkingCopy()
69
 * @since 3.0
69
 * @since 3.0
70
 * 
71
 * @deprecated Use {@link #becomeWorkingCopy(IProgressMonitor)} instead which uses the
72
 * {@link IProblemRequestor problem requestor} defined by this compilation units working copy owner 
73
 * (see {@link WorkingCopyOwner#getProblemRequestor()}).
70
 */
74
 */
71
void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
75
void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
76
77
/**
78
 * Makes sure this compilation unit handle is in a working copy mode, say an {@link IBuffer} is
79
 * created using this compilation units working copy owner.
80
 * This method only has an effect if the compilation is a primary compilation unit ({@link ICompilationUnit#isPrimary()}
81
 * as only primary working copies can be in a non-working copy state.
82
 * <p>
83
 * For each call to this API, regardless if this compilation unit was already a working copy or not,
84
 * an internal reference counter is incremented. As long as this reference counter is not 0, the buffer is kept in memory.
85
 * </p>
86
 * <p>
87
 * To bring this compilation unit back into the original mode (where it reflects the underlying resource) and to
88
 * to release the buffer, {@link #discardWorkingCopy} must be called as many 
89
 * times as {@link #becomeWorkingCopy(IProgressMonitor)}.
90
 * </p>
91
 * <p>
92
 * Once in working copy mode, changes to this compilation unit or its children are done in memory.
93
 * Only the buffer is affected. Using {@link #commitWorkingCopy(boolean, IProgressMonitor)}
94
 * will bring the underlying resource in sync with this compilation unit. {@link #commitWorkingCopy(boolean, IProgressMonitor)}
95
 * does not modify the internal reference counter.
96
 * </p>
97
 * 
98
 * @param monitor a progress monitor used to report progress while opening this compilation unit
99
 * 	or <code>null</code> if no progress should be reported 
100
 * @throws JavaModelException if this compilation unit could not become a working copy.
101
 * @see #discardWorkingCopy()
102
 * 
103
 * @since 3.3
104
 */
105
void becomeWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
106
72
/**
107
/**
73
 * Commits the contents of this working copy to its underlying resource.
108
 * Commits the contents of this working copy to its underlying resource.
74
 *
109
 *
Lines 99-127 Link Here
99
 */
134
 */
100
void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException;
135
void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException;
101
/**
136
/**
102
 * Creates and returns an non-static import declaration in this compilation unit
103
 * with the given name. This method is equivalent to 
104
 * <code>createImport(name, Flags.AccDefault, sibling, monitor)</code>.
105
 *
106
 * @param name the name of the import declaration to add as defined by JLS2 7.5. (For example: <code>"java.io.File"</code> or
107
 *  <code>"java.awt.*"</code>)
108
 * @param sibling the existing element which the import declaration will be inserted immediately before (if
109
 *	<code> null </code>, then this import will be inserted as the last import declaration.
110
 * @param monitor the progress monitor to notify
111
 * @return the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
112
 *
113
 * @throws JavaModelException if the element could not be created. Reasons include:
114
 * <ul>
115
 * <li> This Java element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)</li>
116
 * <li> A {@link org.eclipse.core.runtime.CoreException} occurred while updating an underlying resource
117
 * <li> The specified sibling is not a child of this compilation unit (INVALID_SIBLING)
118
 * <li> The name is not a valid import name (INVALID_NAME)
119
 * </ul>
120
 * @see #createImport(String, IJavaElement, int, IProgressMonitor)
121
 */
122
IImportDeclaration createImport(String name, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException;
123
124
/**
125
 * Creates and returns an import declaration in this compilation unit
137
 * Creates and returns an import declaration in this compilation unit
126
 * with the given name.
138
 * with the given name.
127
 * <p>
139
 * <p>
Lines 164-170 Link Here
164
 * @since 3.0
176
 * @since 3.0
165
 */
177
 */
166
IImportDeclaration createImport(String name, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException;
178
IImportDeclaration createImport(String name, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException;
167
179
/**
180
 * Creates and returns an non-static import declaration in this compilation unit
181
 * with the given name. This method is equivalent to 
182
 * <code>createImport(name, Flags.AccDefault, sibling, monitor)</code>.
183
 *
184
 * @param name the name of the import declaration to add as defined by JLS2 7.5. (For example: <code>"java.io.File"</code> or
185
 *  <code>"java.awt.*"</code>)
186
 * @param sibling the existing element which the import declaration will be inserted immediately before (if
187
 *	<code> null </code>, then this import will be inserted as the last import declaration.
188
 * @param monitor the progress monitor to notify
189
 * @return the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
190
 *
191
 * @throws JavaModelException if the element could not be created. Reasons include:
192
 * <ul>
193
 * <li> This Java element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)</li>
194
 * <li> A {@link org.eclipse.core.runtime.CoreException} occurred while updating an underlying resource
195
 * <li> The specified sibling is not a child of this compilation unit (INVALID_SIBLING)
196
 * <li> The name is not a valid import name (INVALID_NAME)
197
 * </ul>
198
 * @see #createImport(String, IJavaElement, int, IProgressMonitor)
199
 */
200
IImportDeclaration createImport(String name, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException;
168
/**
201
/**
169
 * Creates and returns a package declaration in this compilation unit
202
 * Creates and returns a package declaration in this compilation unit
170
 * with the given package name.
203
 * with the given package name.
Lines 223-235 Link Here
223
 * This has no effect if this compilation unit was not in working copy mode.
256
 * This has no effect if this compilation unit was not in working copy mode.
224
 * </p>
257
 * </p>
225
 * <p>
258
 * <p>
226
 * If {@link #becomeWorkingCopy} was called several times on this
259
 * If {@link #becomeWorkingCopy(IProgressMonitor)} was called several times on this
227
 * compilation unit, {@link #discardWorkingCopy} must be called as 
260
 * compilation unit, {@link #discardWorkingCopy} must be called as 
228
 * many times before it switches back to the original mode.
261
 * many times before it switches back to the original mode.
229
 * </p>
262
 * </p>
263
 * <p>{@link #discardWorkingCopy} also has to be called on each compilation unit returned by
264
 * {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}.
265
 * </p>
230
 * 
266
 * 
231
 * @throws JavaModelException if this working copy could not return in its original mode.
267
 * @throws JavaModelException if this working copy could not return in its original mode.
232
 * @see #becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
268
 * @see #becomeWorkingCopy(IProgressMonitor)
269
 * @see #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)
233
 * @since 3.0
270
 * @since 3.0
234
 */
271
 */
235
void discardWorkingCopy() throws JavaModelException;
272
void discardWorkingCopy() throws JavaModelException;
Lines 286-305 Link Here
286
 */
323
 */
287
IType[] getAllTypes() throws JavaModelException;
324
IType[] getAllTypes() throws JavaModelException;
288
/**
325
/**
289
 * Returns the smallest element within this compilation unit that 
290
 * includes the given source position (that is, a method, field, etc.), or
291
 * <code>null</code> if there is no element other than the compilation
292
 * unit itself at the given position, or if the given position is not
293
 * within the source range of this compilation unit.
294
 *
295
 * @param position a source position inside the compilation unit
296
 * @return the innermost Java element enclosing a given source position or <code>null</code>
297
 *	if none (excluding the compilation unit).
298
 * @throws JavaModelException if the compilation unit does not exist or if an
299
 *		exception occurs while accessing its corresponding resource
300
 */
301
IJavaElement getElementAt(int position) throws JavaModelException;
302
/**
303
 * Returns the first import declaration in this compilation unit with the given name.
326
 * Returns the first import declaration in this compilation unit with the given name.
304
 * This is a handle-only method. The import declaration may or may not exist. This
327
 * This is a handle-only method. The import declaration may or may not exist. This
305
 * is a convenience method - imports can also be accessed from a compilation unit's
328
 * is a convenience method - imports can also be accessed from a compilation unit's
Lines 331-351 Link Here
331
 */
354
 */
332
IImportDeclaration[] getImports() throws JavaModelException;
355
IImportDeclaration[] getImports() throws JavaModelException;
333
/**
356
/**
334
 * Returns the primary compilation unit (whose owner is the primary owner)
357
 * Returns the working copy owner of this working copy or <code>null</code> if this compilation unit is managed by the
335
 * this working copy was created from, or this compilation unit if this a primary
358
 * primary owner.
336
 * compilation unit.
337
 * <p>
338
 * Note that the returned primary compilation unit can be in working copy mode.
339
 * </p>
340
 * 
341
 * @return the primary compilation unit this working copy was created from,
342
 * or this compilation unit if it is primary
343
 * @since 3.0
344
 */
345
ICompilationUnit getPrimary();
346
/**
347
 * Returns the working copy owner of this working copy.
348
 * Returns null if it is not a working copy or if it has no owner.
349
 * 
359
 * 
350
 * @return WorkingCopyOwner the owner of this working copy or <code>null</code>
360
 * @return WorkingCopyOwner the owner of this working copy or <code>null</code>
351
 * @since 3.0
361
 * @since 3.0
Lines 372-377 Link Here
372
 */
382
 */
373
IPackageDeclaration[] getPackageDeclarations() throws JavaModelException;
383
IPackageDeclaration[] getPackageDeclarations() throws JavaModelException;
374
/**
384
/**
385
 * Returns the primary compilation unit (whose owner is the primary owner)
386
 * this working copy was created from, or this compilation unit if this a primary
387
 * compilation unit.
388
 * <p>
389
 * Note that the returned primary compilation unit can be in working copy mode.
390
 * </p>
391
 * 
392
 * @return the primary compilation unit this working copy was created from,
393
 * or this compilation unit if it is primary
394
 * @since 3.0
395
 */
396
ICompilationUnit getPrimary();
397
/**
375
 * Returns the top-level type declared in this compilation unit with the given simple type name.
398
 * Returns the top-level type declared in this compilation unit with the given simple type name.
376
 * The type name has to be a valid compilation unit name.
399
 * The type name has to be a valid compilation unit name.
377
 * This is a handle-only method. The type may or may not exist.
400
 * This is a handle-only method. The type may or may not exist.
Lines 415-420 Link Here
415
 * @return a new working copy of this element if this element is not
438
 * @return a new working copy of this element if this element is not
416
 * a working copy, or this element if this element is already a working copy
439
 * a working copy, or this element if this element is already a working copy
417
 * @since 3.0
440
 * @since 3.0
441
 * 
442
 * @deprecated use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead with a own instance of a working copy
443
 * owner.
418
 */
444
 */
419
ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
445
ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
420
/**
446
/**
Lines 457-462 Link Here
457
 * @return a new working copy of this element using the given factory to create
483
 * @return a new working copy of this element using the given factory to create
458
 * the buffer, or this element if this element is already a working copy
484
 * the buffer, or this element if this element is already a working copy
459
 * @since 3.0
485
 * @since 3.0
486
 * 
487
 * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
460
 */
488
 */
461
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
489
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
462
/**
490
/**
Lines 469-475 Link Here
469
 */
497
 */
470
public boolean hasResourceChanged();
498
public boolean hasResourceChanged();
471
/**
499
/**
472
 * Returns whether this element is a working copy.
500
 * Returns whether this compilation is managed by the primary owner. The primary owner
501
 * typically contains the elements as seen in the file system or by the shared buffer.
502
 * All non-primary files belong to a custom woking copy owner that typically contains some
503
 * selected elements in a working state and inherits all other elements from the primary buffer.
504
 *
505
 * @return returns true if this compilation is managed by the primary owner
506
 * 
507
 * @since 3.3
508
 */
509
boolean isPrimary();
510
/**
511
 * Returns whether this element is a working copy. A woking copy is either a compilation unit with a non-primary
512
 * working copy woner, or a primary compilation unit in buffered state.
473
 * 
513
 * 
474
 * @return true if this element is a working copy, false otherwise
514
 * @return true if this element is a working copy, false otherwise
475
 * @since 3.0
515
 * @since 3.0
(-)model/org/eclipse/jdt/core/IMember.java (+8 lines)
Lines 49-54 Link Here
49
 */
49
 */
50
ICompilationUnit getCompilationUnit();
50
ICompilationUnit getCompilationUnit();
51
/**
51
/**
52
 * Returns the Java file in which this member is declared.
53
 * This is a handle-only method.
54
 * 
55
 * @return the Java file in which this member is declared
56
 * @since 3.3
57
 */
58
IJavaFile getJavaFile();
59
/**
52
 * Returns the type in which this member is declared, or <code>null</code>
60
 * Returns the type in which this member is declared, or <code>null</code>
53
 * if this member is not declared in a type (for example, a top-level type).
61
 * if this member is not declared in a type (for example, a top-level type).
54
 * This is a handle-only method.
62
 * This is a handle-only method.
(-)model/org/eclipse/jdt/core/IClassFile.java (-41 / +5 lines)
Lines 32-38 Link Here
32
 * @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, IProgressMonitor)
32
 * @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, IProgressMonitor)
33
 */
33
 */
34
 
34
 
35
public interface IClassFile extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist {
35
public interface IClassFile extends IJavaFile {
36
	
36
	
37
/**
37
/**
38
 * Changes this class file handle into a working copy. A new {@link IBuffer} is
38
 * Changes this class file handle into a working copy. A new {@link IBuffer} is
Lines 66-72 Link Here
66
 * The resource of a class file's working copy is <code>null</code> if the class file is in an external jar file.
66
 * The resource of a class file's working copy is <code>null</code> if the class file is in an external jar file.
67
 * </p>
67
 * </p>
68
 * 
68
 * 
69
 * @param problemRequestor a requestor which will get notified of problems detected during
69
* @param problemRequestor a requestor which will get notified of problems detected during
70
 * 	reconciling as they are discovered. The requestor can be set to <code>null</code> indicating
70
 * 	reconciling as they are discovered. The requestor can be set to <code>null</code> indicating
71
 * 	that the client is not interested in problems.
71
 * 	that the client is not interested in problems.
72
 * @param owner the given {@link WorkingCopyOwner}, or <code>null</code> for the primary owner
72
 * @param owner the given {@link WorkingCopyOwner}, or <code>null</code> for the primary owner
Lines 76-100 Link Here
76
 * @throws JavaModelException if this compilation unit could not become a working copy.
76
 * @throws JavaModelException if this compilation unit could not become a working copy.
77
 * @see ICompilationUnit#discardWorkingCopy()
77
 * @see ICompilationUnit#discardWorkingCopy()
78
 * @since 3.2
78
 * @since 3.2
79
 *
80
 * @deprecated use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}
79
 */
81
 */
80
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
82
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
81
83
82
/**
84
/**
83
 * Returns the smallest element within this class file that 
84
 * includes the given source position (a method, field, etc.), or
85
 * <code>null</code> if there is no element other than the class file
86
 * itself at the given position, or if the given position is not
87
 * within the source range of this class file.
88
 *
89
 * @param position a source position inside the class file
90
 * @return the innermost Java element enclosing a given source position or <code>null</code>
91
 *  if none (excluding the class file).
92
 *
93
 * @exception JavaModelException if this element does not exist or if an
94
 *      exception occurs while accessing its corresponding resource
95
 */
96
IJavaElement getElementAt(int position) throws JavaModelException;
97
/**
98
 * Returns the type contained in this class file.
85
 * Returns the type contained in this class file.
99
 *
86
 *
100
 * @return the type contained in this class file
87
 * @return the type contained in this class file
Lines 105-133 Link Here
105
IType getType() throws JavaModelException;
92
IType getType() throws JavaModelException;
106
/**
93
/**
107
 * Returns a working copy on the source associated with this class file using the given 
94
 * Returns a working copy on the source associated with this class file using the given 
108
 * owner to create the buffer, or <code>null</code> if there is no source associated
109
 * with the class file.
110
 * <p>
111
 * The buffer will be automatically initialized with the source of the class file
112
 * upon creation.
113
 * <p>
114
 * The only valid operations on this working copy are <code>getBuffer()</code> or <code>getPrimary()</code>.
115
 *
116
 * @param owner the owner that creates a buffer that is used to get the content of the working copy
117
 *                 or <code>null</code> if the primary owner should be used
118
 * @param monitor a progress monitor used to report progress while opening this compilation unit
119
 *                 or <code>null</code> if no progress should be reported 
120
 * @return a  a working copy on the source associated with this class file
121
 * @exception JavaModelException if the source of this class file can
122
 *   not be determined. Reasons include:
123
 * <ul>
124
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
125
 * </ul>
126
 * @since 3.0
127
 */
128
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
129
/**
130
 * Returns a working copy on the source associated with this class file using the given 
131
 * factory to create the buffer, or <code>null</code> if there is no source associated
95
 * factory to create the buffer, or <code>null</code> if there is no source associated
132
 * with the class file.
96
 * with the class file.
133
 * <p>
97
 * <p>
Lines 147-153 Link Here
147
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
111
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
148
 * </ul>
112
 * </ul>
149
 * @since 2.0
113
 * @since 2.0
150
 * @deprecated Use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
114
 * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
151
 */
115
 */
152
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
116
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
153
/**
117
/**
(-)model/org/eclipse/jdt/internal/core/SourceRefElement.java (+6 lines)
Lines 151-156 Link Here
151
	String token = memento.nextToken();
151
	String token = memento.nextToken();
152
	return getHandleFromMemento(token, memento, owner);
152
	return getHandleFromMemento(token, memento, owner);
153
}
153
}
154
/**
155
 * @see IMember
156
 */
157
public IJavaFile getJavaFile() {
158
	return ((JavaElement)getParent()).getJavaFile();
159
}
154
/*
160
/*
155
 * @see IMember#getOccurrenceCount()
161
 * @see IMember#getOccurrenceCount()
156
 */
162
 */
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-143 / +164 lines)
Lines 54-60 Link Here
54
	this.name = name;
54
	this.name = name;
55
	this.owner = owner;
55
	this.owner = owner;
56
}
56
}
57
/*
57
/* (non-Javadoc)
58
 * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
58
 * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
59
 */
59
 */
60
public void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
60
public void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
Lines 68-73 Link Here
68
		operation.runOperation(monitor);
68
		operation.runOperation(monitor);
69
	}
69
	}
70
}
70
}
71
/* (non-Javadoc)
72
 * @see org.eclipse.jdt.core.ICompilationUnit#becomeWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
73
 */
74
public void becomeWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
75
	becomeWorkingCopy(this.owner.getProblemRequestor(), monitor);
76
}
71
protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
77
protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
72
78
73
	// check if this compilation unit can be opened
79
	// check if this compilation unit can be opened
Lines 196-222 Link Here
196
	
202
	
197
	return unitInfo.isStructureKnown();
203
	return unitInfo.isStructureKnown();
198
}
204
}
199
/*
205
/* (non-Javadoc)
200
 * @see Openable#canBeRemovedFromCache
206
 * @see Openable#canBeRemovedFromCache
201
 */
207
 */
202
public boolean canBeRemovedFromCache() {
208
public boolean canBeRemovedFromCache() {
203
	if (getPerWorkingCopyInfo() != null) return false; // working copies should remain in the cache until they are destroyed
209
	if (getPerWorkingCopyInfo() != null) return false; // working copies should remain in the cache until they are destroyed
204
	return super.canBeRemovedFromCache();
210
	return super.canBeRemovedFromCache();
205
}
211
}
206
/*
212
/* (non-Javadoc)
207
 * @see Openable#canBufferBeRemovedFromCache
213
 * @see Openable#canBufferBeRemovedFromCache
208
 */
214
 */
209
public boolean canBufferBeRemovedFromCache(IBuffer buffer) {
215
public boolean canBufferBeRemovedFromCache(IBuffer buffer) {
210
	if (getPerWorkingCopyInfo() != null) return false; // working copy buffers should remain in the cache until working copy is destroyed
216
	if (getPerWorkingCopyInfo() != null) return false; // working copy buffers should remain in the cache until working copy is destroyed
211
	return super.canBufferBeRemovedFromCache(buffer);
217
	return super.canBufferBeRemovedFromCache(buffer);
212
}/*
218
}
219
/* (non-Javadoc)
213
 * @see IOpenable#close
220
 * @see IOpenable#close
214
 */
221
 */
215
public void close() throws JavaModelException {
222
public void close() throws JavaModelException {
216
	if (getPerWorkingCopyInfo() != null) return; // a working copy must remain opened until it is discarded
223
	if (getPerWorkingCopyInfo() != null) return; // a working copy must remain opened until it is discarded
217
	super.close();
224
	super.close();
218
}
225
}
219
/*
226
/* (non-Javadoc)
220
 * @see Openable#closing
227
 * @see Openable#closing
221
 */
228
 */
222
protected void closing(Object info) {
229
protected void closing(Object info) {
Lines 224-239 Link Here
224
		super.closing(info);
231
		super.closing(info);
225
	} // else the buffer of a working copy must remain open for the lifetime of the working copy
232
	} // else the buffer of a working copy must remain open for the lifetime of the working copy
226
}
233
}
234
235
/* (non-Javadoc)
236
 * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor)
237
 */
238
public void codeComplete(int offset, CompletionRequestor requestor) throws JavaModelException {
239
	codeComplete(offset, requestor, DefaultWorkingCopyOwner.PRIMARY);
240
}
241
242
/* (non-Javadoc)
243
 * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner)
244
 */
245
public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
246
	codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, offset, requestor, workingCopyOwner);
247
}
248
227
/**
249
/**
228
 * @see ICodeAssist#codeComplete(int, ICompletionRequestor)
250
 * @see ICodeAssist#codeComplete(int, ICompletionRequestor)
229
 * @deprecated
251
 * @deprecated As it use deprecated requestor
230
 */
252
 */
231
public void codeComplete(int offset, ICompletionRequestor requestor) throws JavaModelException {
253
public void codeComplete(int offset, ICompletionRequestor requestor) throws JavaModelException {
232
	codeComplete(offset, requestor, DefaultWorkingCopyOwner.PRIMARY);
254
	codeComplete(offset, requestor, DefaultWorkingCopyOwner.PRIMARY);
233
}
255
}
234
/**
256
/**
235
 * @see ICodeAssist#codeComplete(int, ICompletionRequestor, WorkingCopyOwner)
257
 * @see ICodeAssist#codeComplete(int, ICompletionRequestor, WorkingCopyOwner)
236
 * @deprecated
258
 * @deprecated As it use deprecated requestor
237
 */
259
 */
238
public void codeComplete(int offset, ICompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
260
public void codeComplete(int offset, ICompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
239
	if (requestor == null) {
261
	if (requestor == null) {
Lines 243-249 Link Here
243
}
265
}
244
/**
266
/**
245
 * @see ICodeAssist#codeComplete(int, ICodeCompletionRequestor)
267
 * @see ICodeAssist#codeComplete(int, ICodeCompletionRequestor)
246
 * @deprecated - use codeComplete(int, ICompletionRequestor)
268
 * @deprecated As it use deprecated requestor
247
 */
269
 */
248
public void codeComplete(int offset, final ICodeCompletionRequestor requestor) throws JavaModelException {
270
public void codeComplete(int offset, final ICodeCompletionRequestor requestor) throws JavaModelException {
249
	
271
	
Lines 301-346 Link Here
301
}
323
}
302
324
303
/* (non-Javadoc)
325
/* (non-Javadoc)
304
 * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor)
305
 */
306
public void codeComplete(int offset, CompletionRequestor requestor) throws JavaModelException {
307
	codeComplete(offset, requestor, DefaultWorkingCopyOwner.PRIMARY);
308
}
309
310
/* (non-Javadoc)
311
 * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner)
312
 */
313
public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
314
	codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, offset, requestor, workingCopyOwner);
315
}
316
317
/**
318
 * @see ICodeAssist#codeSelect(int, int)
326
 * @see ICodeAssist#codeSelect(int, int)
319
 */
327
 */
320
public IJavaElement[] codeSelect(int offset, int length) throws JavaModelException {
328
public IJavaElement[] codeSelect(int offset, int length) throws JavaModelException {
321
	return codeSelect(offset, length, DefaultWorkingCopyOwner.PRIMARY);
329
	return codeSelect(offset, length, DefaultWorkingCopyOwner.PRIMARY);
322
}
330
}
323
/**
331
/* (non-Javadoc)
324
 * @see ICodeAssist#codeSelect(int, int, WorkingCopyOwner)
332
 * @see ICodeAssist#codeSelect(int, int, WorkingCopyOwner)
325
 */
333
 */
326
public IJavaElement[] codeSelect(int offset, int length, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
334
public IJavaElement[] codeSelect(int offset, int length, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
327
	return super.codeSelect(this, offset, length, workingCopyOwner);
335
	return super.codeSelect(this, offset, length, workingCopyOwner);
328
}
336
}
329
/**
337
/* (non-Javadoc)
330
 * @see IWorkingCopy#commit(boolean, IProgressMonitor)
338
 * @see IWorkingCopy#commit(boolean, IProgressMonitor)
331
 * @deprecated
332
 */
339
 */
333
public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException {
340
public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException {
334
	commitWorkingCopy(force, monitor);
341
	commitWorkingCopy(force, monitor);
335
}
342
}
336
/**
343
/* (non-Javadoc)
337
 * @see ICompilationUnit#commitWorkingCopy(boolean, IProgressMonitor)
344
 * @see ICompilationUnit#commitWorkingCopy(boolean, IProgressMonitor)
338
 */
345
 */
339
public void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException {
346
public void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException {
340
	CommitWorkingCopyOperation op= new CommitWorkingCopyOperation(this, force);
347
	CommitWorkingCopyOperation op= new CommitWorkingCopyOperation(this, force);
341
	op.runOperation(monitor);
348
	op.runOperation(monitor);
342
}
349
}
343
/**
350
/* (non-Javadoc)
344
 * @see ISourceManipulation#copy(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
351
 * @see ISourceManipulation#copy(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
345
 */
352
 */
346
public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
353
public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
Lines 355-376 Link Here
355
	}
362
	}
356
	getJavaModel().copy(elements, containers, null, renamings, force, monitor);
363
	getJavaModel().copy(elements, containers, null, renamings, force, monitor);
357
}
364
}
358
/**
365
/* (non-Javadoc)
359
 * Returns a new element info for this element.
366
 * @see org.eclipse.jdt.internal.core.Openable#createElementInfo()
360
 */
367
 */
361
protected Object createElementInfo() {
368
protected Object createElementInfo() {
362
	return new CompilationUnitElementInfo();
369
	return new CompilationUnitElementInfo();
363
}
370
}
364
/**
371
/* (non-Javadoc)
365
 * @see ICompilationUnit#createImport(String, IJavaElement, IProgressMonitor)
372
 * @see ICompilationUnit#createImport(String, IJavaElement, IProgressMonitor)
366
 */
373
 */
367
public IImportDeclaration createImport(String importName, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException {
374
public IImportDeclaration createImport(String importName, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException {
368
	return createImport(importName, sibling, Flags.AccDefault, monitor);
375
	return createImport(importName, sibling, Flags.AccDefault, monitor);
369
}
376
}
370
377
371
/**
378
/* (non-Javadoc)
372
 * @see ICompilationUnit#createImport(String, IJavaElement, int, IProgressMonitor)
379
 * @see ICompilationUnit#createImport(String, IJavaElement, int, IProgressMonitor)
373
 * @since 3.0
374
 */
380
 */
375
public IImportDeclaration createImport(String importName, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException {
381
public IImportDeclaration createImport(String importName, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException {
376
	CreateImportOperation op = new CreateImportOperation(importName, this, flags);
382
	CreateImportOperation op = new CreateImportOperation(importName, this, flags);
Lines 381-387 Link Here
381
	return getImport(importName);
387
	return getImport(importName);
382
}
388
}
383
389
384
/**
390
/* (non-Javadoc)
385
 * @see ICompilationUnit#createPackageDeclaration(String, IProgressMonitor)
391
 * @see ICompilationUnit#createPackageDeclaration(String, IProgressMonitor)
386
 */
392
 */
387
public IPackageDeclaration createPackageDeclaration(String pkg, IProgressMonitor monitor) throws JavaModelException {
393
public IPackageDeclaration createPackageDeclaration(String pkg, IProgressMonitor monitor) throws JavaModelException {
Lines 390-396 Link Here
390
	op.runOperation(monitor);
396
	op.runOperation(monitor);
391
	return getPackageDeclaration(pkg);
397
	return getPackageDeclaration(pkg);
392
}
398
}
393
/**
399
/* (non-Javadoc)
394
 * @see ICompilationUnit#createType(String, IJavaElement, boolean, IProgressMonitor)
400
 * @see ICompilationUnit#createType(String, IJavaElement, boolean, IProgressMonitor)
395
 */
401
 */
396
public IType createType(String content, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
402
public IType createType(String content, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
Lines 413-428 Link Here
413
	op.runOperation(monitor);
419
	op.runOperation(monitor);
414
	return (IType) op.getResultElements()[0];
420
	return (IType) op.getResultElements()[0];
415
}
421
}
416
/**
422
/* (non-Javadoc)
417
 * @see ISourceManipulation#delete(boolean, IProgressMonitor)
423
 * @see ISourceManipulation#delete(boolean, IProgressMonitor)
418
 */
424
 */
419
public void delete(boolean force, IProgressMonitor monitor) throws JavaModelException {
425
public void delete(boolean force, IProgressMonitor monitor) throws JavaModelException {
420
	IJavaElement[] elements= new IJavaElement[] {this};
426
	IJavaElement[] elements= new IJavaElement[] {this};
421
	getJavaModel().delete(elements, force, monitor);
427
	getJavaModel().delete(elements, force, monitor);
422
}
428
}
423
/**
429
/* (non-Javadoc)
424
 * @see IWorkingCopy#destroy()
430
 * @see IWorkingCopy#destroy()
425
 * @deprecated
426
 */
431
 */
427
public void destroy() {
432
public void destroy() {
428
	try {
433
	try {
Lines 432-438 Link Here
432
			e.printStackTrace();
437
			e.printStackTrace();
433
	}
438
	}
434
}
439
}
435
/*
440
/* (non-Javadoc)
436
 * @see ICompilationUnit#discardWorkingCopy
441
 * @see ICompilationUnit#discardWorkingCopy
437
 */
442
 */
438
public void discardWorkingCopy() throws JavaModelException {
443
public void discardWorkingCopy() throws JavaModelException {
Lines 440-446 Link Here
440
	DiscardWorkingCopyOperation op = new DiscardWorkingCopyOperation(this);
445
	DiscardWorkingCopyOperation op = new DiscardWorkingCopyOperation(this);
441
	op.runOperation(null);
446
	op.runOperation(null);
442
}
447
}
443
/**
448
/* (non-Javadoc)
444
 * Returns true if this handle represents the same Java element
449
 * Returns true if this handle represents the same Java element
445
 * as the given handle.
450
 * as the given handle.
446
 *
451
 *
Lines 451-456 Link Here
451
	CompilationUnit other = (CompilationUnit)obj;
456
	CompilationUnit other = (CompilationUnit)obj;
452
	return this.owner.equals(other.owner) && super.equals(obj);
457
	return this.owner.equals(other.owner) && super.equals(obj);
453
}
458
}
459
/* (non-Javadoc)
460
 * @see org.eclipse.jdt.internal.core.Openable#exists()
461
 */
454
public boolean exists() {
462
public boolean exists() {
455
	// working copy always exists in the model until it is gotten rid of (even if not on classpath)
463
	// working copy always exists in the model until it is gotten rid of (even if not on classpath)
456
	if (getPerWorkingCopyInfo() != null) return true;	
464
	if (getPerWorkingCopyInfo() != null) return true;	
Lines 458-464 Link Here
458
	// if not a working copy, it exists only if it is a primary compilation unit
466
	// if not a working copy, it exists only if it is a primary compilation unit
459
	return isPrimary() && validateCompilationUnit(getResource()).isOK();
467
	return isPrimary() && validateCompilationUnit(getResource()).isOK();
460
}
468
}
461
/**
469
/* (non-Javadoc)
462
 * @see ICompilationUnit#findElements(IJavaElement)
470
 * @see ICompilationUnit#findElements(IJavaElement)
463
 */
471
 */
464
public IJavaElement[] findElements(IJavaElement element) {
472
public IJavaElement[] findElements(IJavaElement element) {
Lines 514-520 Link Here
514
		return null;
522
		return null;
515
	}
523
	}
516
}
524
}
517
/**
525
/* (non-Javadoc)
518
 * @see ICompilationUnit#findPrimaryType()
526
 * @see ICompilationUnit#findPrimaryType()
519
 */
527
 */
520
public IType findPrimaryType() {
528
public IType findPrimaryType() {
Lines 528-534 Link Here
528
536
529
/**
537
/**
530
 * @see IWorkingCopy#findSharedWorkingCopy(IBufferFactory)
538
 * @see IWorkingCopy#findSharedWorkingCopy(IBufferFactory)
531
 * @deprecated
539
 * @deprecated As it use a deprecated interface
532
 */
540
 */
533
public IJavaElement findSharedWorkingCopy(IBufferFactory factory) {
541
public IJavaElement findSharedWorkingCopy(IBufferFactory factory) {
534
542
Lines 538-544 Link Here
538
	return findWorkingCopy(BufferFactoryWrapper.create(factory));
546
	return findWorkingCopy(BufferFactoryWrapper.create(factory));
539
}
547
}
540
548
541
/**
549
/* (non-Javadoc)
542
 * @see ICompilationUnit#findWorkingCopy(WorkingCopyOwner)
550
 * @see ICompilationUnit#findWorkingCopy(WorkingCopyOwner)
543
 */
551
 */
544
public ICompilationUnit findWorkingCopy(WorkingCopyOwner workingCopyOwner) {
552
public ICompilationUnit findWorkingCopy(WorkingCopyOwner workingCopyOwner) {
Lines 555-561 Link Here
555
		}
563
		}
556
	}
564
	}
557
}
565
}
558
/**
566
/* (non-Javadoc)
559
 * @see ICompilationUnit#getAllTypes()
567
 * @see ICompilationUnit#getAllTypes()
560
 */
568
 */
561
public IType[] getAllTypes() throws JavaModelException {
569
public IType[] getAllTypes() throws JavaModelException {
Lines 579-591 Link Here
579
	allTypes.toArray(arrayOfAllTypes);
587
	allTypes.toArray(arrayOfAllTypes);
580
	return arrayOfAllTypes;
588
	return arrayOfAllTypes;
581
}
589
}
582
/**
590
/* (non-Javadoc)
583
 * @see IMember#getCompilationUnit()
591
 * @see org.eclipse.jdt.internal.core.JavaElement#getCompilationUnit()
584
 */
592
 */
585
public ICompilationUnit getCompilationUnit() {
593
public ICompilationUnit getCompilationUnit() {
586
	return this;
594
	return this;
587
}
595
}
588
/**
596
/* (non-Javadoc)
589
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
597
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
590
 */
598
 */
591
public char[] getContents() {
599
public char[] getContents() {
Lines 604-614 Link Here
604
		return CharOperation.NO_CHAR;
612
		return CharOperation.NO_CHAR;
605
	return contents;
613
	return contents;
606
}
614
}
607
/**
615
/* (non-Javadoc)
608
 * A compilation unit has a corresponding resource unless it is contained
616
 * A compilation unit has a corresponding resource unless it is contained
609
 * in a jar.
617
 * in a jar.
610
 *
618
 * 
611
 * @see IJavaElement#getCorrespondingResource()
619
 * @see org.eclipse.jdt.internal.core.Openable#getCorrespondingResource()
612
 */
620
 */
613
public IResource getCorrespondingResource() throws JavaModelException {
621
public IResource getCorrespondingResource() throws JavaModelException {
614
	PackageFragmentRoot root = getPackageFragmentRoot();
622
	PackageFragmentRoot root = getPackageFragmentRoot();
Lines 618-625 Link Here
618
		return getUnderlyingResource();
626
		return getUnderlyingResource();
619
	}
627
	}
620
}
628
}
621
/**
629
/* (non-Javadoc)
622
 * @see ICompilationUnit#getElementAt(int)
630
 * @see IJavaFile#getElementAt(int)
623
 */
631
 */
624
public IJavaElement getElementAt(int position) throws JavaModelException {
632
public IJavaElement getElementAt(int position) throws JavaModelException {
625
633
Lines 630-653 Link Here
630
		return e;
638
		return e;
631
	}
639
	}
632
}
640
}
641
/* (non-Javadoc)
642
 * @see org.eclipse.jdt.internal.core.JavaElement#getElementName()
643
 */
633
public String getElementName() {
644
public String getElementName() {
634
	return this.name;
645
	return this.name;
635
}
646
}
636
/**
647
/* (non-Javadoc)
637
 * @see IJavaElement
648
 * @see org.eclipse.jdt.core.IJavaElement#getElementType()
638
 */
649
 */
639
public int getElementType() {
650
public int getElementType() {
640
	return COMPILATION_UNIT;
651
	return COMPILATION_UNIT;
641
}
652
}
642
/**
653
/* (non-Javadoc)
643
 * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
654
 * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
644
 */
655
 */
645
public char[] getFileName(){
656
public char[] getFileName(){
646
	return getPath().toString().toCharArray();
657
	return getPath().toString().toCharArray();
647
}
658
}
648
659
649
/*
660
/* (non-Javadoc)
650
 * @see JavaElement
661
 * @see org.eclipse.jdt.internal.core.JavaElement#getHandleFromMemento(java.lang.String, org.eclipse.jdt.internal.core.util.MementoTokenizer, org.eclipse.jdt.core.WorkingCopyOwner)
651
 */
662
 */
652
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner) {
663
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner) {
653
	switch (token.charAt(0)) {
664
	switch (token.charAt(0)) {
Lines 668-694 Link Here
668
	return null;
679
	return null;
669
}
680
}
670
681
671
/**
682
/* (non-Javadoc)
672
 * @see JavaElement#getHandleMementoDelimiter()
683
 * @see JavaElement#getHandleMementoDelimiter()
673
 */
684
 */
674
protected char getHandleMementoDelimiter() {
685
protected char getHandleMementoDelimiter() {
675
	return JavaElement.JEM_COMPILATIONUNIT;
686
	return JavaElement.JEM_COMPILATIONUNIT;
676
}
687
}
677
/**
688
/* (non-Javadoc)
678
 * @see ICompilationUnit#getImport(String)
689
 * @see ICompilationUnit#getImport(String)
679
 */
690
 */
680
public IImportDeclaration getImport(String importName) {
691
public IImportDeclaration getImport(String importName) {
681
	return getImportContainer().getImport(importName);
692
	return getImportContainer().getImport(importName);
682
}
693
}
683
/**
694
/* (non-Javadoc)
684
 * @see ICompilationUnit#getImportContainer()
695
 * @see ICompilationUnit#getImportContainer()
685
 */
696
 */
686
public IImportContainer getImportContainer() {
697
public IImportContainer getImportContainer() {
687
	return new ImportContainer(this);
698
	return new ImportContainer(this);
688
}
699
}
689
700
690
701
/* (non-Javadoc)
691
/**
692
 * @see ICompilationUnit#getImports()
702
 * @see ICompilationUnit#getImports()
693
 */
703
 */
694
public IImportDeclaration[] getImports() throws JavaModelException {
704
public IImportDeclaration[] getImports() throws JavaModelException {
Lines 713-727 Link Here
713
	System.arraycopy(elements, 0, imports, 0, length);
723
	System.arraycopy(elements, 0, imports, 0, length);
714
	return imports;
724
	return imports;
715
}
725
}
716
/**
726
/* (non-Javadoc)
727
 * @see org.eclipse.jdt.internal.core.JavaElement#getJavaFile()
728
 */
729
public IJavaFile getJavaFile() {
730
	return this;
731
}
732
/* (non-Javadoc)
717
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
733
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
718
 */
734
 */
719
public char[] getMainTypeName(){
735
public char[] getMainTypeName(){
720
	return Util.getNameWithoutJavaLikeExtension(getElementName()).toCharArray();
736
	return Util.getNameWithoutJavaLikeExtension(getElementName()).toCharArray();
721
}
737
}
722
/**
738
/* (non-Javadoc)
723
 * @see IWorkingCopy#getOriginal(IJavaElement)
739
 * @see IWorkingCopy#getOriginal(IJavaElement)
724
 * @deprecated
725
 */
740
 */
726
public IJavaElement getOriginal(IJavaElement workingCopyElement) {
741
public IJavaElement getOriginal(IJavaElement workingCopyElement) {
727
	// backward compatibility
742
	// backward compatibility
Lines 733-741 Link Here
733
	
748
	
734
	return workingCopyElement.getPrimaryElement();
749
	return workingCopyElement.getPrimaryElement();
735
}
750
}
736
/**
751
/* (non-Javadoc)
737
 * @see IWorkingCopy#getOriginalElement()
752
 * @see IWorkingCopy#getOriginalElement()
738
 * @deprecated
739
 */
753
 */
740
public IJavaElement getOriginalElement() {
754
public IJavaElement getOriginalElement() {
741
	// backward compatibility
755
	// backward compatibility
Lines 749-761 Link Here
749
public WorkingCopyOwner getOwner() {
763
public WorkingCopyOwner getOwner() {
750
	return isPrimary() || !isWorkingCopy() ? null : this.owner;
764
	return isPrimary() || !isWorkingCopy() ? null : this.owner;
751
}
765
}
752
/**
766
/* (non-Javadoc)
753
 * @see ICompilationUnit#getPackageDeclaration(String)
767
 * @see ICompilationUnit#getPackageDeclaration(String)
754
 */
768
 */
755
public IPackageDeclaration getPackageDeclaration(String pkg) {
769
public IPackageDeclaration getPackageDeclaration(String pkg) {
756
	return new PackageDeclaration(this, pkg);
770
	return new PackageDeclaration(this, pkg);
757
}
771
}
758
/**
772
/* (non-Javadoc)
759
 * @see ICompilationUnit#getPackageDeclarations()
773
 * @see ICompilationUnit#getPackageDeclarations()
760
 */
774
 */
761
public IPackageDeclaration[] getPackageDeclarations() throws JavaModelException {
775
public IPackageDeclaration[] getPackageDeclarations() throws JavaModelException {
Lines 764-770 Link Here
764
	list.toArray(array);
778
	list.toArray(array);
765
	return array;
779
	return array;
766
}
780
}
767
/**
781
/* (non-Javadoc)
768
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getPackageName()
782
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getPackageName()
769
 */
783
 */
770
public char[][] getPackageName() {
784
public char[][] getPackageName() {
Lines 773-779 Link Here
773
	return Util.toCharArrays(packageFragment.names);
787
	return Util.toCharArrays(packageFragment.names);
774
}
788
}
775
789
776
/**
790
/* (non-Javadoc)
777
 * @see IJavaElement#getPath()
791
 * @see IJavaElement#getPath()
778
 */
792
 */
779
public IPath getPath() {
793
public IPath getPath() {
Lines 792-811 Link Here
792
public JavaModelManager.PerWorkingCopyInfo getPerWorkingCopyInfo() {
806
public JavaModelManager.PerWorkingCopyInfo getPerWorkingCopyInfo() {
793
	return JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(this, false/*don't create*/, false/*don't record usage*/, null/*no problem requestor needed*/);
807
	return JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(this, false/*don't create*/, false/*don't record usage*/, null/*no problem requestor needed*/);
794
}
808
}
795
/*
809
/* (non-Javadoc)
796
 * @see ICompilationUnit#getPrimary()
810
 * @see ICompilationUnit#getPrimary()
797
 */
811
 */
798
public ICompilationUnit getPrimary() {
812
public ICompilationUnit getPrimary() {
799
	return (ICompilationUnit)getPrimaryElement(true);
813
	return (ICompilationUnit)getPrimaryElement(true);
800
}
814
}
801
/*
815
/* (non-Javadoc)
802
 * @see JavaElement#getPrimaryElement(boolean)
816
 * @see JavaElement#getPrimaryElement(boolean)
803
 */
817
 */
804
public IJavaElement getPrimaryElement(boolean checkOwner) {
818
public IJavaElement getPrimaryElement(boolean checkOwner) {
805
	if (checkOwner && isPrimary()) return this;
819
	if (checkOwner && isPrimary()) return this;
806
	return new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
820
	return new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
807
}
821
}
808
/**
822
/* (non-Javadoc)
809
 * @see IJavaElement#getResource()
823
 * @see IJavaElement#getResource()
810
 */
824
 */
811
public IResource getResource() {
825
public IResource getResource() {
Lines 818-823 Link Here
818
	}
832
	}
819
}
833
}
820
/**
834
/**
835
 * @see IWorkingCopy#getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
836
 * @deprecated As it use deprecated interface
837
 */
838
public IJavaElement getSharedWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
839
	
840
	// if factory is null, default factory must be used
841
	if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
842
	
843
	return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestor, pm);
844
}
845
/* (non-Javadoc)
821
 * @see ISourceReference#getSource()
846
 * @see ISourceReference#getSource()
822
 */
847
 */
823
public String getSource() throws JavaModelException {
848
public String getSource() throws JavaModelException {
Lines 825-843 Link Here
825
	if (buffer == null) return ""; //$NON-NLS-1$
850
	if (buffer == null) return ""; //$NON-NLS-1$
826
	return buffer.getContents();
851
	return buffer.getContents();
827
}
852
}
828
/**
853
/* (non-Javadoc)
829
 * @see ISourceReference#getSourceRange()
854
 * @see ISourceReference#getSourceRange()
830
 */
855
 */
831
public ISourceRange getSourceRange() throws JavaModelException {
856
public ISourceRange getSourceRange() throws JavaModelException {
832
	return ((CompilationUnitElementInfo) getElementInfo()).getSourceRange();
857
	return ((CompilationUnitElementInfo) getElementInfo()).getSourceRange();
833
}
858
}
834
/**
859
/* (non-Javadoc)
835
 * @see ICompilationUnit#getType(String)
860
 * @see ICompilationUnit#getType(String)
836
 */
861
 */
837
public IType getType(String typeName) {
862
public IType getType(String typeName) {
838
	return new SourceType(this, typeName);
863
	return new SourceType(this, typeName);
839
}
864
}
840
/**
865
/* (non-Javadoc)
841
 * @see ICompilationUnit#getTypes()
866
 * @see ICompilationUnit#getTypes()
842
 */
867
 */
843
public IType[] getTypes() throws JavaModelException {
868
public IType[] getTypes() throws JavaModelException {
Lines 846-877 Link Here
846
	list.toArray(array);
871
	list.toArray(array);
847
	return array;
872
	return array;
848
}
873
}
849
/**
874
/* (non-Javadoc)
850
 * @see IJavaElement
875
 * @see org.eclipse.jdt.internal.core.Openable#getUnderlyingResource()
851
 */
876
 */
852
public IResource getUnderlyingResource() throws JavaModelException {
877
public IResource getUnderlyingResource() throws JavaModelException {
853
	if (isWorkingCopy() && !isPrimary()) return null;
878
	if (isWorkingCopy() && !isPrimary()) return null;
854
	return super.getUnderlyingResource();
879
	return super.getUnderlyingResource();
855
}
880
}
856
/**
881
/* (non-Javadoc)
857
 * @see IWorkingCopy#getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
858
 * @deprecated
859
 */
860
public IJavaElement getSharedWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
861
	
862
	// if factory is null, default factory must be used
863
	if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
864
	
865
	return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestor, pm);
866
}
867
/**
868
 * @see IWorkingCopy#getWorkingCopy()
882
 * @see IWorkingCopy#getWorkingCopy()
869
 * @deprecated
870
 */
883
 */
871
public IJavaElement getWorkingCopy() throws JavaModelException {
884
public IJavaElement getWorkingCopy() throws JavaModelException {
872
	return getWorkingCopy(null);
885
	return getWorkingCopy(null);
873
}
886
}
874
/**
887
/* (non-Javadoc)
875
 * @see ICompilationUnit#getWorkingCopy(IProgressMonitor)
888
 * @see ICompilationUnit#getWorkingCopy(IProgressMonitor)
876
 */
889
 */
877
public ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
890
public ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
Lines 879-890 Link Here
879
}
892
}
880
/**
893
/**
881
 * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
894
 * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
882
 * @deprecated
895
 * @deprecated As it use a deprecated interface
883
 */
896
 */
884
public IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
897
public IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
885
	return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestor, monitor);
898
	return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestor, monitor);
886
}
899
}
887
/**
900
/* (non-Javadoc)
888
 * @see ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
901
 * @see ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
889
 */
902
 */
890
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
903
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
Lines 902-914 Link Here
902
	op.runOperation(monitor);
915
	op.runOperation(monitor);
903
	return workingCopy;
916
	return workingCopy;
904
}
917
}
905
/**
918
/* (non-Javadoc)
919
 * @see org.eclipse.jdt.core.IJavaFile#getWorkingCopy(org.eclipse.jdt.core.WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
920
 */
921
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException {
922
	return getWorkingCopy(workingCopyOwner, workingCopyOwner.getProblemRequestor(), monitor);
923
}
924
/* (non-Javadoc)
906
 * @see Openable#hasBuffer()
925
 * @see Openable#hasBuffer()
907
 */
926
 */
908
protected boolean hasBuffer() {
927
protected boolean hasBuffer() {
909
	return true;
928
	return true;
910
}
929
}
911
/*
930
/* (non-Javadoc)
912
 * @see ICompilationUnit#hasResourceChanged()
931
 * @see ICompilationUnit#hasResourceChanged()
913
 */
932
 */
914
public boolean hasResourceChanged() {
933
public boolean hasResourceChanged() {
Lines 922-971 Link Here
922
	if (resource == null) return false;
941
	if (resource == null) return false;
923
	return ((CompilationUnitElementInfo)info).timestamp != resource.getModificationStamp();
942
	return ((CompilationUnitElementInfo)info).timestamp != resource.getModificationStamp();
924
}
943
}
925
/**
944
/* (non-Javadoc)
926
 * @see IWorkingCopy#isBasedOn(IResource)
945
 * @see IWorkingCopy#isBasedOn(IResource)
927
 * @deprecated
928
 */
946
 */
929
public boolean isBasedOn(IResource resource) {
947
public boolean isBasedOn(IResource resource) {
930
	if (!isWorkingCopy()) return false;
948
	if (!isWorkingCopy()) return false;
931
	if (!getResource().equals(resource)) return false;
949
	if (!getResource().equals(resource)) return false;
932
	return !hasResourceChanged();
950
	return !hasResourceChanged();
933
}
951
}
934
/**
952
/* (non-Javadoc)
935
 * @see IOpenable#isConsistent()
953
 * @see IOpenable#isConsistent()
936
 */
954
 */
937
public boolean isConsistent() {
955
public boolean isConsistent() {
938
	return !JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().contains(this);
956
	return !JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().contains(this);
939
}
957
}
958
/* (non-Javadoc)
959
 * @see org.eclipse.jdt.core.ICompilationUnit#isPrimary()
960
 */
940
public boolean isPrimary() {
961
public boolean isPrimary() {
941
	return this.owner == DefaultWorkingCopyOwner.PRIMARY;
962
	return this.owner == DefaultWorkingCopyOwner.PRIMARY;
942
}
963
}
943
/**
964
/* (non-Javadoc)
944
 * @see Openable#isSourceElement()
965
 * @see Openable#isSourceElement()
945
 */
966
 */
946
protected boolean isSourceElement() {
967
protected boolean isSourceElement() {
947
	return true;
968
	return true;
948
}
969
}
949
protected IStatus validateCompilationUnit(IResource resource) {
970
/* (non-Javadoc)
950
	IPackageFragmentRoot root = getPackageFragmentRoot();
951
	// root never null as validation is not done for working copies
952
	try {
953
		if (root.getKind() != IPackageFragmentRoot.K_SOURCE) 
954
			return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root);
955
	} catch (JavaModelException e) {
956
		return e.getJavaModelStatus();
957
	}
958
	if (resource != null) {
959
		char[][] inclusionPatterns = ((PackageFragmentRoot)root).fullInclusionPatternChars();
960
		char[][] exclusionPatterns = ((PackageFragmentRoot)root).fullExclusionPatternChars();
961
		if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) 
962
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this);
963
		if (!resource.isAccessible())
964
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
965
	}
966
	return JavaConventions.validateCompilationUnitName(getElementName());
967
}
968
/*
969
 * @see ICompilationUnit#isWorkingCopy()
971
 * @see ICompilationUnit#isWorkingCopy()
970
 */
972
 */
971
public boolean isWorkingCopy() {
973
public boolean isWorkingCopy() {
Lines 973-984 Link Here
973
	// delta, clients can still check that element was a working copy before being discarded.
975
	// delta, clients can still check that element was a working copy before being discarded.
974
	return !isPrimary() || getPerWorkingCopyInfo() != null;
976
	return !isPrimary() || getPerWorkingCopyInfo() != null;
975
}
977
}
976
/**
977
 * @see IOpenable#makeConsistent(IProgressMonitor)
978
 */
979
public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
980
	makeConsistent(NO_AST, false/*don't resolve bindings*/, false /* don't perform statements recovery */, null/*don't collect problems but report them*/, monitor);
981
}
982
public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(int astLevel, boolean resolveBindings, boolean statementsRecovery, HashMap problems, IProgressMonitor monitor) throws JavaModelException {
978
public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(int astLevel, boolean resolveBindings, boolean statementsRecovery, HashMap problems, IProgressMonitor monitor) throws JavaModelException {
983
	if (isConsistent()) return null;
979
	if (isConsistent()) return null;
984
		
980
		
Lines 999-1005 Link Here
999
		return null;
995
		return null;
1000
	}
996
	}
1001
}
997
}
1002
/**
998
/* (non-Javadoc)
999
 * @see org.eclipse.jdt.internal.core.Openable#makeConsistent(org.eclipse.core.runtime.IProgressMonitor)
1000
 */
1001
public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
1002
	makeConsistent(NO_AST, false/*don't resolve bindings*/, false /* don't perform statements recovery */, null/*don't collect problems but report them*/, monitor);
1003
}
1004
/* (non-Javadoc)
1003
 * @see ISourceManipulation#move(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
1005
 * @see ISourceManipulation#move(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
1004
 */
1006
 */
1005
public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
1007
public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
Lines 1016-1022 Link Here
1016
	getJavaModel().move(elements, containers, null, renamings, force, monitor);
1018
	getJavaModel().move(elements, containers, null, renamings, force, monitor);
1017
}
1019
}
1018
1020
1019
/**
1021
/* (non-Javadoc)
1020
 * @see Openable#openBuffer(IProgressMonitor, Object)
1022
 * @see Openable#openBuffer(IProgressMonitor, Object)
1021
 */
1023
 */
1022
protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException {
1024
protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException {
Lines 1070-1099 Link Here
1070
	}	
1072
	}	
1071
	return buffer;
1073
	return buffer;
1072
}
1074
}
1075
/* (non-Javadoc)
1076
 * @see org.eclipse.jdt.internal.core.Openable#openParent(java.lang.Object, java.util.HashMap, org.eclipse.core.runtime.IProgressMonitor)
1077
 */
1073
protected void openParent(Object childInfo, HashMap newElements, IProgressMonitor pm) throws JavaModelException {
1078
protected void openParent(Object childInfo, HashMap newElements, IProgressMonitor pm) throws JavaModelException {
1074
	if (!isWorkingCopy())
1079
	if (!isWorkingCopy())
1075
		super.openParent(childInfo, newElements, pm);
1080
		super.openParent(childInfo, newElements, pm);
1076
	// don't open parent for a working copy to speed up the first becomeWorkingCopy
1081
	// don't open parent for a working copy to speed up the first becomeWorkingCopy
1077
	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89411)
1082
	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89411)
1078
}
1083
}
1079
/**
1084
/* (non-Javadoc)
1080
 * @see ICompilationUnit#reconcile()
1085
 * @see ICompilationUnit#reconcile()
1081
 * @deprecated
1082
 */
1086
 */
1083
public IMarker[] reconcile() throws JavaModelException {
1087
public IMarker[] reconcile() throws JavaModelException {
1084
	reconcile(NO_AST, false/*don't force problem detection*/, false, null/*use primary owner*/, null/*no progress monitor*/);
1088
	reconcile(NO_AST, false/*don't force problem detection*/, false, null/*use primary owner*/, null/*no progress monitor*/);
1085
	return null;
1089
	return null;
1086
}
1090
}
1087
/**
1091
/* (non-Javadoc)
1088
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1092
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1089
 */
1093
 */
1090
public void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException {
1094
public void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException {
1091
	reconcile(NO_AST, forceProblemDetection, false, null/*use primary owner*/, monitor);
1095
	reconcile(NO_AST, forceProblemDetection, false, null/*use primary owner*/, monitor);
1092
}
1096
}
1093
1097
1094
/**
1098
/* (non-Javadoc)
1095
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1099
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1096
 * @since 3.0
1097
 */
1100
 */
1098
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1101
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1099
	int astLevel,
1102
	int astLevel,
Lines 1104-1112 Link Here
1104
	return reconcile(astLevel, forceProblemDetection, false, workingCopyOwner, monitor);
1107
	return reconcile(astLevel, forceProblemDetection, false, workingCopyOwner, monitor);
1105
}
1108
}
1106
		
1109
		
1107
/**
1110
/* (non-Javadoc)
1108
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1111
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1109
 * @since 3.0
1110
 */
1112
 */
1111
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1113
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1112
	int astLevel,
1114
	int astLevel,
Lines 1139-1145 Link Here
1139
	return op.ast;
1141
	return op.ast;
1140
}
1142
}
1141
1143
1142
/**
1144
/* (non-Javadoc)
1143
 * @see ISourceManipulation#rename(String, boolean, IProgressMonitor)
1145
 * @see ISourceManipulation#rename(String, boolean, IProgressMonitor)
1144
 */
1146
 */
1145
public void rename(String newName, boolean force, IProgressMonitor monitor) throws JavaModelException {
1147
public void rename(String newName, boolean force, IProgressMonitor monitor) throws JavaModelException {
Lines 1151-1158 Link Here
1151
	String[] renamings= new String[] {newName};
1153
	String[] renamings= new String[] {newName};
1152
	getJavaModel().rename(elements, dests, renamings, force, monitor);
1154
	getJavaModel().rename(elements, dests, renamings, force, monitor);
1153
}
1155
}
1154
/*
1156
/* (non-Javadoc)
1155
 * @see ICompilationUnit
1157
 * @see org.eclipse.jdt.core.ICompilationUnit#restore()
1156
 */
1158
 */
1157
public void restore() throws JavaModelException {
1159
public void restore() throws JavaModelException {
1158
1160
Lines 1165-1172 Link Here
1165
	updateTimeStamp(original);
1167
	updateTimeStamp(original);
1166
	makeConsistent(null);
1168
	makeConsistent(null);
1167
}
1169
}
1168
/**
1170
/* (non-Javadoc)
1169
 * @see IOpenable
1171
 * @see org.eclipse.jdt.internal.core.Openable#save(org.eclipse.core.runtime.IProgressMonitor, boolean)
1170
 */
1172
 */
1171
public void save(IProgressMonitor pm, boolean force) throws JavaModelException {
1173
public void save(IProgressMonitor pm, boolean force) throws JavaModelException {
1172
	if (isWorkingCopy()) {
1174
	if (isWorkingCopy()) {
Lines 1178-1185 Link Here
1178
		super.save(pm, force);
1180
		super.save(pm, force);
1179
	}
1181
	}
1180
}
1182
}
1181
/**
1183
/* (non-Javadoc)
1182
 * Debugging purposes
1184
 * @see org.eclipse.jdt.internal.core.JavaElement#toStringInfo(int, java.lang.StringBuffer, java.lang.Object, boolean)
1183
 */
1185
 */
1184
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) {
1186
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) {
1185
	if (!isPrimary()) {
1187
	if (!isPrimary()) {
Lines 1211-1215 Link Here
1211
	}
1213
	}
1212
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1214
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1213
}
1215
}
1216
protected IStatus validateCompilationUnit(IResource resource) {
1217
	IPackageFragmentRoot root = getPackageFragmentRoot();
1218
	// root never null as validation is not done for working copies
1219
	try {
1220
		if (root.getKind() != IPackageFragmentRoot.K_SOURCE) 
1221
			return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root);
1222
	} catch (JavaModelException e) {
1223
		return e.getJavaModelStatus();
1224
	}
1225
	if (resource != null) {
1226
		char[][] inclusionPatterns = ((PackageFragmentRoot)root).fullInclusionPatternChars();
1227
		char[][] exclusionPatterns = ((PackageFragmentRoot)root).fullExclusionPatternChars();
1228
		if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) 
1229
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this);
1230
		if (!resource.isAccessible())
1231
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
1232
	}
1233
	return JavaConventions.validateCompilationUnitName(getElementName());
1234
}
1214
1235
1215
}
1236
}
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (+9 lines)
Lines 239-244 Link Here
239
	}
239
	}
240
	return elt;
240
	return elt;
241
}
241
}
242
public IType findPrimaryType() {
243
	return getType();
244
}
242
public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException {
245
public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException {
243
	return this.getType().getAttachedJavadoc(monitor);
246
	return this.getType().getAttachedJavadoc(monitor);
244
}
247
}
Lines 327-332 Link Here
327
	return this;
330
	return this;
328
}
331
}
329
/**
332
/**
333
 * @see IMember
334
 */
335
public IJavaFile getJavaFile() {
336
	return this;
337
}
338
/**
330
 * A class file has a corresponding resource unless it is contained
339
 * A class file has a corresponding resource unless it is contained
331
 * in a jar.
340
 * in a jar.
332
 *
341
 *
(-)model/org/eclipse/jdt/internal/core/Openable.java (-2 / +2 lines)
Lines 163-170 Link Here
163
	}
163
	}
164
	return requestor.getElements();
164
	return requestor.getElements();
165
}
165
}
166
/*
166
/* (non-Javadoc)
167
 * Returns a new element info for this element.
167
 * @see org.eclipse.jdt.internal.core.JavaElement#createElementInfo()
168
 */
168
 */
169
protected Object createElementInfo() {
169
protected Object createElementInfo() {
170
	return new OpenableElementInfo();
170
	return new OpenableElementInfo();
(-)model/org/eclipse/jdt/internal/core/JavaElement.java (-4 / +10 lines)
Lines 212-225 Link Here
212
		}
212
		}
213
		return list;
213
		return list;
214
	}
214
	}
215
	/**
215
	/* (non-Javadoc)
216
	 * @see IMember
216
	 * @see IMember#getClassFile()
217
	 */
217
	 */
218
	public IClassFile getClassFile() {
218
	public IClassFile getClassFile() {
219
		return null;
219
		return null;
220
	}
220
	}
221
	/**
221
	/* (non-Javadoc)
222
	 * @see IMember
222
	 * @see IMember#getCompilationUnit()
223
	 */
223
	 */
224
	public ICompilationUnit getCompilationUnit() {
224
	public ICompilationUnit getCompilationUnit() {
225
		return null;
225
		return null;
Lines 293-298 Link Here
293
	 * contribution to a memento.
293
	 * contribution to a memento.
294
	 */
294
	 */
295
	protected abstract char getHandleMementoDelimiter();
295
	protected abstract char getHandleMementoDelimiter();
296
	/* (non-Javadoc)
297
	 * @see IMember#getJavaFile()
298
	 */
299
	public IJavaFile getJavaFile() {
300
		return null;
301
	}
296
	/**
302
	/**
297
	 * @see IJavaElement
303
	 * @see IJavaElement
298
	 */
304
	 */
(-)dom/org/eclipse/jdt/core/dom/ASTParser.java (-39 / +38 lines)
Lines 17-22 Link Here
17
import org.eclipse.jdt.core.IClassFile;
17
import org.eclipse.jdt.core.IClassFile;
18
import org.eclipse.jdt.core.ICompilationUnit;
18
import org.eclipse.jdt.core.ICompilationUnit;
19
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IJavaFile;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.JavaCore;
22
import org.eclipse.jdt.core.JavaCore;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.JavaModelException;
Lines 154-167 Link Here
154
    private char[] rawSource = null;
155
    private char[] rawSource = null;
155
    
156
    
156
    /**
157
    /**
157
     * Java mode compilation unit supplying the source.
158
     * Java model class file or compilation unit supplying the source.
158
     */
159
     */
159
    private ICompilationUnit compilationUnitSource = null;
160
    private IJavaFile javaFileSource = null;
160
    
161
    /**
162
     * Java model class file supplying the source.
163
     */
164
    private IClassFile classFileSource = null;
165
    
161
    
166
    /**
162
    /**
167
     * Character-based offset into the source string where parsing is to
163
     * Character-based offset into the source string where parsing is to
Lines 218-225 Link Here
218
	private void initializeDefaults() {
214
	private void initializeDefaults() {
219
		this.astKind = K_COMPILATION_UNIT;
215
		this.astKind = K_COMPILATION_UNIT;
220
		this.rawSource = null;
216
		this.rawSource = null;
221
		this.classFileSource = null;
217
		this.javaFileSource = null;
222
		this.compilationUnitSource = null;
223
		this.resolveBindings = false;
218
		this.resolveBindings = false;
224
		this.sourceLength = -1;
219
		this.sourceLength = -1;
225
		this.sourceOffset = 0;
220
		this.sourceOffset = 0;
Lines 452-460 Link Here
452
     */
447
     */
453
	public void setSource(char[] source) {
448
	public void setSource(char[] source) {
454
		this.rawSource = source;
449
		this.rawSource = source;
455
		// clear the others
450
		// clear the other
456
		this.compilationUnitSource = null;
451
		this.javaFileSource = null;
457
		this.classFileSource = null;
458
	}
452
	}
459
453
460
	/**
454
	/**
Lines 467-482 Link Here
467
     * is to be parsed, or <code>null</code> if none
461
     * is to be parsed, or <code>null</code> if none
468
      */
462
      */
469
	public void setSource(ICompilationUnit source) {
463
	public void setSource(ICompilationUnit source) {
470
		this.compilationUnitSource = source;
464
		setSource((IJavaFile) source);
471
		// clear the others
472
		this.rawSource = null;
473
		this.classFileSource = null;
474
		if (source != null) {
475
			this.project = source.getJavaProject();
476
			Map options = this.project.getOptions(true);
477
			options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
478
			this.compilerOptions = options;
479
		}
480
	}
465
	}
481
	
466
	
482
	/**
467
	/**
Lines 491-500 Link Here
491
     * is to be parsed, or <code>null</code> if none
476
     * is to be parsed, or <code>null</code> if none
492
     */
477
     */
493
	public void setSource(IClassFile source) {
478
	public void setSource(IClassFile source) {
494
		this.classFileSource = source;
479
		setSource((IJavaFile) source);
495
		// clear the others
480
	}
481
	
482
	/**
483
	 * Sets the source code to be parsed.
484
	 * <p>This method automatically sets the project (and compiler
485
	 * options) based on the given compilation unit of class file, in a manner
486
	 * equivalent to <code>setProject(source.getJavaProject())</code>.</p>
487
	 * <p>If the source is a class file without source attachment, the creation of the 
488
	 * ast will fail with an IllegalStateException.</p>
489
	 *
490
	 * @param source the Java model compilation unit or class file whose corresponding source code
491
	 * is to be parsed, or <code>null</code> if none
492
	 * @since 3.3
493
	 */
494
	public void setSource(IJavaFile source) {
495
		this.javaFileSource = source;
496
		// clear the other
496
		this.rawSource = null;
497
		this.rawSource = null;
497
		this.compilationUnitSource = null;
498
		if (source != null) {
498
		if (source != null) {
499
			this.project = source.getJavaProject();
499
			this.project = source.getJavaProject();
500
			Map options = this.project.getOptions(true);
500
			Map options = this.project.getOptions(true);
Lines 623-630 Link Here
623
	   if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$
623
	   if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$
624
		try {
624
		try {
625
			if ((this.rawSource == null)
625
			if ((this.rawSource == null)
626
		   	  && (this.compilationUnitSource == null)
626
		   	  && (this.javaFileSource == null)) {
627
		   	  && (this.classFileSource == null)) {
628
		   	  throw new IllegalStateException("source not specified"); //$NON-NLS-1$
627
		   	  throw new IllegalStateException("source not specified"); //$NON-NLS-1$
629
		   }
628
		   }
630
	   		result = internalCreateAST(monitor);
629
	   		result = internalCreateAST(monitor);
Lines 782-803 Link Here
782
				try {
781
				try {
783
					NodeSearcher searcher = null;
782
					NodeSearcher searcher = null;
784
					org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null;
783
					org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null;
785
					IJavaElement element = null;
784
					IJavaFile javaFile = null;
786
					if (this.compilationUnitSource != null) {
785
					if (this.javaFileSource instanceof ICompilationUnit) {
787
						sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.compilationUnitSource;
786
						sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.javaFileSource;
788
						// use a BasicCompilation that caches the source instead of using the compilationUnitSource directly 
787
						// use a BasicCompilation that caches the source instead of using the javaFileSource directly 
789
						// (if it is a working copy, the source can change between the parse and the AST convertion)
788
						// (if it is a working copy, the source can change between the parse and the AST convertion)
790
						// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632)
789
						// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632)
791
						sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project);
790
						sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project);
792
						element = this.compilationUnitSource;
791
						javaFile = this.javaFileSource;
793
					} else if (this.classFileSource != null) {
792
					} else if (this.javaFileSource instanceof IClassFile) {
794
						try {
793
						try {
795
							String sourceString = this.classFileSource.getSource();
794
							String sourceString = this.javaFileSource.getSource();
796
							if (sourceString == null) {
795
							if (sourceString == null) {
797
								throw new IllegalStateException();
796
								throw new IllegalStateException();
798
							}
797
							}
799
							PackageFragment packageFragment = (PackageFragment) this.classFileSource.getParent();
798
							PackageFragment packageFragment = (PackageFragment) this.javaFileSource.getParent();
800
							BinaryType type = (BinaryType) this.classFileSource.getType();
799
							BinaryType type = (BinaryType) this.javaFileSource.findPrimaryType();
801
							IBinaryType binaryType = (IBinaryType) type.getElementInfo();
800
							IBinaryType binaryType = (IBinaryType) type.getElementInfo();
802
							// file name is used to recreate the Java element, so it has to be the toplevel .class file name
801
							// file name is used to recreate the Java element, so it has to be the toplevel .class file name
803
							char[] fileName = binaryType.getFileName();
802
							char[] fileName = binaryType.getFileName();
Lines 811-817 Link Here
811
								fileName = newFileName;
810
								fileName = newFileName;
812
							}
811
							}
813
							sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project);
812
							sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project);
814
							element = this.classFileSource;
813
							javaFile = this.javaFileSource;
815
						} catch(JavaModelException e) {
814
						} catch(JavaModelException e) {
816
							// an error occured accessing the java element
815
							// an error occured accessing the java element
817
							throw new IllegalStateException();
816
							throw new IllegalStateException();
Lines 859-868 Link Here
859
						this.apiLevel, 
858
						this.apiLevel, 
860
						this.compilerOptions,
859
						this.compilerOptions,
861
						needToResolveBindings,
860
						needToResolveBindings,
862
						this.compilationUnitSource == null ? this.workingCopyOwner : this.compilationUnitSource.getOwner(),
861
						! (this.javaFileSource instanceof ICompilationUnit) ? this.workingCopyOwner : ((ICompilationUnit) this.javaFileSource).getOwner(),
863
						needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null, 
862
						needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null, 
864
						monitor);
863
						monitor);
865
					result.setJavaElement(element);
864
					result.setJavaElement(javaFile);
866
					return result;
865
					return result;
867
				} finally {
866
				} finally {
868
					if (compilationUnitDeclaration != null && this.resolveBindings) {
867
					if (compilationUnitDeclaration != null && this.resolveBindings) {
(-)dom/org/eclipse/jdt/core/dom/CompilationUnit.java (-5 / +28 lines)
Lines 18-23 Link Here
18
import java.util.Map;
18
import java.util.Map;
19
19
20
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IJavaFile;
21
import org.eclipse.jdt.core.compiler.IProblem;
22
import org.eclipse.jdt.core.compiler.IProblem;
22
import org.eclipse.jdt.internal.compiler.parser.Scanner;
23
import org.eclipse.jdt.internal.compiler.parser.Scanner;
23
import org.eclipse.jface.text.IDocument;
24
import org.eclipse.jface.text.IDocument;
Lines 123-133 Link Here
123
	private DefaultCommentMapper commentMapper = null;
124
	private DefaultCommentMapper commentMapper = null;
124
	
125
	
125
	/**
126
	/**
126
	 * The Java element (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
127
	 * The Java file (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
127
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java element.
128
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java file.
128
	 * @since 3.1
129
	 * @since 3.1
129
	 */
130
	 */
130
	private IJavaElement element = null;
131
	private IJavaFile javaFile = null;
131
	
132
	
132
	/**
133
	/**
133
	 * The list of import declarations in textual order order; 
134
	 * The list of import declarations in textual order order; 
Lines 492-498 Link Here
492
	 * @since 3.1
493
	 * @since 3.1
493
	 */
494
	 */
494
	public IJavaElement getJavaElement() {
495
	public IJavaElement getJavaElement() {
495
		return this.element;
496
		return this.javaFile;
497
	}
498
	
499
	/**
500
	 * The Java file (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
501
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java file.
502
	 * 
503
	 * @return the Java file this compilation unit was created from, or <code>null</code> if none
504
	 * @since 3.3
505
	 */
506
	public IJavaFile getJavaFile() {
507
		return this.javaFile;
496
	}
508
	}
497
	
509
	
498
	/**
510
	/**
Lines 940-946 Link Here
940
	 * @since 3.1
952
	 * @since 3.1
941
	 */
953
	 */
942
	void setJavaElement(IJavaElement element) {
954
	void setJavaElement(IJavaElement element) {
943
		this.element = element;
955
		this.javaFile = (IJavaFile) element;
956
	}
957
958
	/**
959
	 * Sets the Java file (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
960
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java element.
961
	 * 
962
	 * @param javaFile the Java file this compilation unit was created from
963
	 * @since 3.3
964
	 */
965
	void setJavaFile(IJavaFile javaFile) {
966
		this.javaFile = javaFile;
944
	}
967
	}
945
	
968
	
946
	/**
969
	/**
(-)model/org/eclipse/jdt/core/IJavaFile.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core;
12
13
import org.eclipse.core.runtime.IProgressMonitor;
14
15
16
/**
17
 * Represents an entire Java file (either an <code>ICompilationUnit</code>
18
 * or an <code>IClassFile</code>).
19
 * 
20
 * <p>
21
 * This interface is not intended to be implemented by clients.
22
 * </p>
23
 *
24
 * @see ICompilationUnit
25
 * @see IClassFile
26
 * @since 3.3
27
 */
28
public interface IJavaFile extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist {
29
30
/**
31
 * Finds the primary type of this Java file (that is, the type with the same name as the
32
 * compilation unit, or the type of a class file), or <code>null</code> if no such a type exists.
33
 * 
34
 * @return the found primary type of this Java file, or <code>null</code> if no such a type exists
35
 */
36
IType findPrimaryType();
37
38
/**
39
 * Returns the smallest element within this Java file that 
40
 * includes the given source position (that is, a method, field, etc.), or
41
 * <code>null</code> if there is no element other than the Java file
42
 * itself at the given position, or if the given position is not
43
 * within the source range of the source of this Java file.
44
 *
45
 * @param position a source position inside the Java file
46
 * @return the innermost Java element enclosing a given source position or <code>null</code>
47
 *	if none (excluding the Java file).
48
 * @throws JavaModelException if the Java file does not exist or if an
49
 *	exception occurs while accessing its corresponding resource
50
 */
51
IJavaElement getElementAt(int position) throws JavaModelException;
52
	
53
/**
54
 * Returns a shared working copy on this compilation unit or class file using the given working copy owner to create
55
 * the buffer. If this is already a working copy of the given owner, the element itself is returned.
56
 * This API can only answer an already existing working copy if it is based on the same
57
 * original Java file AND was using the same working copy owner (that is, as defined by {@link Object#equals}).	 
58
 * <p>
59
 * The life time of a shared working copy is as follows:
60
 * <ul>
61
 * <li>The first call to {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} 
62
 * 	creates a new working copy for this element</li>
63
 * <li>Subsequent calls increment an internal counter.</li>
64
 * <li>A call to {@link ICompilationUnit#discardWorkingCopy()} decrements the internal counter.</li>
65
 * <li>When this counter is 0, the working copy is discarded.
66
 * </ul>
67
 * So users of this method must discard exactly once the working copy.
68
 * <p>
69
 * Note that the working copy owner will be used for the life time of the shared working copy, that is if the 
70
 * working copy is closed then reopened, this owner will be used.
71
 * The buffer will be automatically initialized with the original's Java file content upon creation.
72
 * <p>
73
 * When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this
74
 * working copy.
75
 * </p><p>
76
 * Since 2.1, a working copy can be created on a not-yet existing compilation
77
 * unit. In particular, such a working copy can then be committed in order to create
78
 * the corresponding compilation unit.
79
 * </p><p>
80
 * The problems of this working copy are reported to the {@link IProblemRequestor} configured by the
81
 * {@link WorkingCopyOwner}.
82
 * </p>
83
 * 
84
 * @param owner the working copy owner that creates a buffer that is used to get the content 
85
 * 				of the working copy
86
 * @param monitor a progress monitor used to report progress while opening this compilation unit
87
 *                 or <code>null</code> if no progress should be reported 
88
 * @throws JavaModelException if the contents of this element can
89
 *   	not be determined. 
90
 * @return a new working copy of this Java file using the given owner to create
91
 *		the buffer, or this Java file if it is already a working copy
92
 */
93
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
94
95
}

Return to bug 125504