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

Collapse All | Expand All

(-)model/org/eclipse/jdt/core/IWorkingCopy.java (-3 / +3 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,
Lines 330-336 Link Here
330
	 * </ul>
330
	 * </ul>
331
	 * @return <code>null</code>
331
	 * @return <code>null</code>
332
	 * 
332
	 * 
333
	 * @deprecated Use {@link ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)} instead.
333
	 * @deprecated Use {@link ICompilationUnit#reconcile(boolean, WorkingCopyOwner, IProgressMonitor)} instead.
334
	 */
334
	 */
335
	IMarker[] reconcile() throws JavaModelException;
335
	IMarker[] reconcile() throws JavaModelException;
336
	
336
	
Lines 361-367 Link Here
361
	 * </ul>
361
	 * </ul>
362
	 * @since 2.0
362
	 * @since 2.0
363
	 * 
363
	 * 
364
	 * @deprecated Use {@link ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)} instead.
364
	 * @deprecated Use {@link ICompilationUnit#reconcile(boolean, WorkingCopyOwner, IProgressMonitor)} instead.
365
	 */
365
	 */
366
	void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException;
366
	void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException;
367
367
(-)model/org/eclipse/jdt/core/WorkingCopyOwner.java (-6 / +148 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.Path;
14
import org.eclipse.core.runtime.Path;
15
import org.eclipse.jdt.core.dom.AST;
16
import org.eclipse.jdt.core.dom.ASTParser;
15
import org.eclipse.jdt.internal.core.BufferManager;
17
import org.eclipse.jdt.internal.core.BufferManager;
16
import org.eclipse.jdt.internal.core.CompilationUnit;
18
import org.eclipse.jdt.internal.core.CompilationUnit;
17
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
19
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
Lines 19-25 Link Here
19
import org.eclipse.jdt.internal.core.PackageFragment;
21
import org.eclipse.jdt.internal.core.PackageFragment;
20
22
21
/**
23
/**
22
 * The owner of an <code>ICompilationUnit</code> handle in working copy mode. 
24
 * The owner of an {@link ICompilationUnit} handle in working copy mode. 
23
 * An owner is used to identify a working copy and to create its buffer.
25
 * An owner is used to identify a working copy and to create its buffer.
24
 * <p>
26
 * <p>
25
 * Clients should subclass this class to instantiate a working copy owner that is specific to their need and that
27
 * Clients should subclass this class to instantiate a working copy owner that is specific to their need and that
Lines 29-42 Link Here
29
 * Note: even though this class has no abstract method, which means that it provides functional default behavior,
31
 * Note: even though this class has no abstract method, which means that it provides functional default behavior,
30
 * it is still an abstract class, as clients are intended to own their owner implementation.
32
 * it is still an abstract class, as clients are intended to own their owner implementation.
31
 * </p>
33
 * </p>
32
 * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, org.eclipse.core.runtime.IProgressMonitor)
34
 * @see ICompilationUnit#getWorkingCopy(WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
33
 * @see ICompilationUnit#discardWorkingCopy()
34
 * @see ICompilationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
35
 * @since 3.0
35
 * @since 3.0
36
 */
36
 */
37
public abstract class WorkingCopyOwner {
37
public abstract class WorkingCopyOwner {
38
	
38
	
39
	/**
39
	/**
40
	 * Constant used by {@link #getReconcileASTKind()} to specify that the reconcile operation should not return an AST.
41
	 * @since 3.3
42
	 */
43
	public static final int NO_AST = 0;
44
		
45
	/**
40
	 * Sets the buffer provider of the primary working copy owner. Note that even if the
46
	 * Sets the buffer provider of the primary working copy owner. Note that even if the
41
	 * buffer provider is a working copy owner, only its <code>createBuffer(ICompilationUnit)</code>
47
	 * buffer provider is a working copy owner, only its <code>createBuffer(ICompilationUnit)</code>
42
	 * method is used by the primary working copy owner. It doesn't replace the internal primary 
48
	 * method is used by the primary working copy owner. It doesn't replace the internal primary 
Lines 109-123 Link Here
109
	 * @throws JavaModelException if the contents of this working copy can
115
	 * @throws JavaModelException if the contents of this working copy can
110
	 *   not be determined. 
116
	 *   not be determined. 
111
	 * @return a new working copy
117
	 * @return a new working copy
112
	 * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
118
	 * @see ICompilationUnit#becomeWorkingCopy(IProgressMonitor)
113
	 * @since 3.2
119
	 * @since 3.2
120
	 * 
121
	 * @deprecated Use {@link #newWorkingCopy(String, IClasspathEntry[], IProgressMonitor)} instead to make sure the
122
	 * woking copy owners problem requestor.
114
	 */
123
	 */
115
	public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
124
	public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
116
		ExternalJavaProject project = new ExternalJavaProject(classpath);
125
		ExternalJavaProject project = new ExternalJavaProject(classpath);
117
		IPackageFragment parent = project.getPackageFragmentRoot(Path.EMPTY).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
126
		IPackageFragment parent = project.getPackageFragmentRoot(Path.EMPTY).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
118
		CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
127
		CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
119
		result.becomeWorkingCopy(problemRequestor, monitor);
128
		result.becomeWorkingCopy(problemRequestor, monitor);
129
		// TODO decide if also the default problem requestor (getProblemRequestor) should be notified. 
120
		return result;
130
		return result;
121
	}
131
	}
122
132
	
133
	/**
134
	 * Returns a new working copy with the given name using this working copy owner to 
135
	 * create its buffer. 
136
	 * <p>
137
	 * This working copy always belongs to the default package in a package
138
	 * fragment root that corresponds to its Java project, and this Java project never exists.
139
	 * However this Java project has the given classpath that is used when resolving names
140
	 * in this working copy.
141
	 * </p><p>
142
	 * A DOM AST created using this working copy will have bindings resolved using the given
143
	 * classpath, and problem are reported to the given problem requestor.
144
	 * <p></p>
145
	 * <code>JavaCore#getOptions()</code> is used to create the DOM AST as it is not
146
	 * possible to set the options on the non-existing Java project.
147
	 * </p><p>
148
	 * When the working copy instance is created, an {@link IJavaElementDelta#ADDED added delta} is 
149
	 * reported on this working copy.
150
	 * </p><p>
151
	 * Once done with the working copy, users of this method must discard it using 
152
	 * {@link ICompilationUnit#discardWorkingCopy()}.
153
	 * </p><p>
154
	 * Note that when such working copy is committed, only its buffer is saved (see 
155
	 * {@link IBuffer#save(IProgressMonitor, boolean)}) but no resource is created.
156
	 * </p><p>
157
	 * This method is not intended to be overriden by clients.
158
	 * </p>
159
	 * 
160
	 * @param name the name of the working copy (e.g. "X.java")
161
	 * @param classpath the classpath used to resolve names in this working copy
162
	 * @param monitor a progress monitor used to report progress while opening the working copy
163
	 * 	or <code>null</code> if no progress should be reported 
164
	 * @throws JavaModelException if the contents of this working copy can
165
	 *   not be determined. 
166
	 * @return a new working copy
167
	 * @see ICompilationUnit#becomeWorkingCopy(IProgressMonitor)
168
	 * 
169
	 * @since 3.3
170
	 */
171
	public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProgressMonitor monitor) throws JavaModelException {
172
		ExternalJavaProject project = new ExternalJavaProject(classpath);
173
		IPackageFragment parent = project.getPackageFragmentRoot(Path.EMPTY).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
174
		CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
175
		result.becomeWorkingCopy(getProblemRequestor(), monitor);
176
		return result;
177
	}
178
	
179
	/**
180
	 * Returns the problem requestor used on reconcile (see {@link ICompilationUnit#reconcile(boolean, WorkingCopyOwner, IProgressMonitor)}
181
	 * by working copies of this working copy owner. <code>null</code> is returned if no problem requestor needs to be informed.
182
	 * <p>
183
	 * By default, no problem requestor is configured. Clients can override this method to provide a requestor.
184
	 * </p>
185
	 * 
186
	 * @return the problem requestor to be used by working copies of this working copy owner or <code>null</code>
187
	 * if no problem requestor is configured.
188
	 * 
189
	 * @since 3.3
190
	 */
191
	public IProblemRequestor getProblemRequestor() {
192
		return null;
193
	}
194
	
195
	/**
196
	 * Returns if and what kind of AST should be created on reconcile of a working copy of this working copy owner.
197
	 * If {@link #NO_AST} is returned, no AST will be created. Use the AST level constants on {@link AST} (for example
198
	 * {@link AST#JLS3}) to create an AST of given level.
199
	 * 
200
	 * @return returns {@link #NO_AST} if no AST should be created on reconcile or the AST level of the AST to create.
201
	 * @see #getReconcileASTRecoverStatements()
202
	 * @see #getReconcileASTResolveBindings()
203
	 * @see ASTParser#newParser(int)
204
	 * 
205
	 * @since 3.3
206
	 */
207
	public int getReconcileASTKind() {
208
		return NO_AST;
209
	}
210
	
211
	/**
212
	 * Specifies if an AST created on reconcile should contain resolved bindings or not.
213
	 * Note, ASTs are only created on reconcile if {@link #getReconcileASTKind()} does not return {@link #NO_AST}.
214
	 * 
215
	 * @return <code>true</code> is returned if AST created on reconcile should also contain resolved bindings.
216
	 * @see ASTParser#setResolveBindings(boolean)
217
	 * 
218
	 * @since 3.3
219
	 */
220
	public boolean getReconcileASTResolveBindings() {
221
		return false;
222
	}
223
	
224
	/**
225
	 * Specifies if an AST created on reconcile should try to recover statements or not.
226
	 * Note, ASTs are only created on reconcile if {@link #getReconcileASTKind()} does not return {@link #NO_AST}.
227
	 * 
228
	 * @return <code>true</code> is returned if AST created on reconcile should also try to recover statements.
229
	 * @see ASTParser#setStatementsRecovery(boolean)
230
	 * 
231
	 * @since 3.3
232
	 */
233
	public boolean getReconcileASTRecoverStatements() {
234
		return false;
235
	}
236
	
237
	/**
238
	 * Returns a new non primary owner using the built-in buffer management and the given settings.
239
	 * 
240
	 * @param requestor the problem requestor to use
241
	 * @param astKind the AST level to use or {@link #NO_AST} to not provide an AST on reconcile
242
	 * @param resolveBindings specifies if ASTs created on reconcile should contain resolved bindings
243
	 * @param recoverStatements specifies if ASTs created on reconcile should try to recover statements
244
	 * 
245
	 * @return the new working copy owner
246
	 * 
247
	 * @since 3.3
248
	 */
249
	public WorkingCopyOwner createNonPrimaryOwner(final IProblemRequestor requestor, final int astKind, final boolean resolveBindings, final boolean recoverStatements) {
250
		return new WorkingCopyOwner() {
251
			public IProblemRequestor getProblemRequestor() {
252
				return requestor;
253
			}
254
			public int getReconcileASTKind() {
255
				return astKind;
256
			}
257
			public boolean getReconcileASTResolveBindings() {
258
				return resolveBindings;
259
			}
260
			public boolean getReconcileASTRecoverStatements() {
261
				return recoverStatements;
262
			}
263
		};
264
	}
123
}
265
}
(-)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/ICompilationUnit.java (-20 / +124 lines)
Lines 30-39 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
37
 * 
38
 * @deprecated
37
 */
39
 */
38
public static final int NO_AST = 0;
40
public static final int NO_AST = 0;
39
41
Lines 67-74 Link Here
67
 * @throws JavaModelException if this compilation unit could not become a working copy.
69
 * @throws JavaModelException if this compilation unit could not become a working copy.
68
 * @see #discardWorkingCopy()
70
 * @see #discardWorkingCopy()
69
 * @since 3.0
71
 * @since 3.0
72
 * 
73
 * @deprecated Use {@link #becomeWorkingCopy(IProgressMonitor)} instead which uses the
74
 * {@IProblemRequestor problem requestor} defined by this compilation units working copy owner 
75
 * (see {@link WorkingCopyOwner#getProblemRequestor()}).
70
 */
76
 */
71
void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
77
void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
78
79
/**
80
 * Makes sure this compilation unit handle is in a working copy mode, say an {@link IBuffer} is
81
 * created using this compilation units working copy owner.
82
 * This method only has an effect if the compilation is a primary compilation unit ({@link ICompilationUnit#isPrimary()}
83
 * as only primary working copies can be in a non-working copy state.
84
 * <p>
85
 * For each call to this API, regardless if this compilation unit was already a working copy or not,
86
 * an internal reference counter is incremented. As long as this reference counter is not 0, the buffer is kept in memory.
87
 * </p>
88
 * <p>
89
 * To bring this compilation unit back into the original mode (where it reflects the underlying resource) and to
90
 * to release the buffer, {@link #discardWorkingCopy} must be called as many 
91
 * times as {@link #becomeWorkingCopy(IProgressMonitor)}.
92
 * </p>
93
 * <p>
94
 * Once in working copy mode, changes to this compilation unit or its children are done in memory.
95
 * Only the buffer is affected. Using {@link #commitWorkingCopy(boolean, IProgressMonitor)}
96
 * will bring the underlying resource in sync with this compilation unit. {@link #commitWorkingCopy(boolean, IProgressMonitor)}
97
 * does not modify the internal reference counter.
98
 * </p>
99
 * 
100
 * @param monitor a progress monitor used to report progress while opening this compilation unit
101
 * 	or <code>null</code> if no progress should be reported 
102
 * @throws JavaModelException if this compilation unit could not become a working copy.
103
 * @see #discardWorkingCopy()
104
 * 
105
 * @since 3.3
106
 */
107
void becomeWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
108
72
/**
109
/**
73
 * Commits the contents of this working copy to its underlying resource.
110
 * Commits the contents of this working copy to its underlying resource.
74
 *
111
 *
Lines 223-235 Link Here
223
 * This has no effect if this compilation unit was not in working copy mode.
260
 * This has no effect if this compilation unit was not in working copy mode.
224
 * </p>
261
 * </p>
225
 * <p>
262
 * <p>
226
 * If {@link #becomeWorkingCopy} was called several times on this
263
 * If {@link #becomeWorkingCopy(IProgressMonitor)} was called several times on this
227
 * compilation unit, {@link #discardWorkingCopy} must be called as 
264
 * compilation unit, {@link #discardWorkingCopy} must be called as 
228
 * many times before it switches back to the original mode.
265
 * many times before it switches back to the original mode.
229
 * </p>
266
 * </p>
267
 * <p>{@link #discardWorkingCopy} also has to be called on each compilation unit returned by
268
 * {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}.
269
 * </p>
230
 * 
270
 * 
231
 * @throws JavaModelException if this working copy could not return in its original mode.
271
 * @throws JavaModelException if this working copy could not return in its original mode.
232
 * @see #becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
272
 * @see #becomeWorkingCopy(IProgressMonitor)
273
 * @see #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)
233
 * @since 3.0
274
 * @since 3.0
234
 */
275
 */
235
void discardWorkingCopy() throws JavaModelException;
276
void discardWorkingCopy() throws JavaModelException;
Lines 286-305 Link Here
286
 */
327
 */
287
IType[] getAllTypes() throws JavaModelException;
328
IType[] getAllTypes() throws JavaModelException;
288
/**
329
/**
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.
330
 * 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
331
 * 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
332
 * is a convenience method - imports can also be accessed from a compilation unit's
Lines 344-351 Link Here
344
 */
371
 */
345
ICompilationUnit getPrimary();
372
ICompilationUnit getPrimary();
346
/**
373
/**
347
 * Returns the working copy owner of this working copy.
374
 * Returns the working copy owner of this working copy or <code>null</code> if this compilation unit is managed by the
348
 * Returns null if it is not a working copy or if it has no owner.
375
 * primary owner.
349
 * 
376
 * 
350
 * @return WorkingCopyOwner the owner of this working copy or <code>null</code>
377
 * @return WorkingCopyOwner the owner of this working copy or <code>null</code>
351
 * @since 3.0
378
 * @since 3.0
Lines 415-420 Link Here
415
 * @return a new working copy of this element if this element is not
442
 * @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
443
 * a working copy, or this element if this element is already a working copy
417
 * @since 3.0
444
 * @since 3.0
445
 * 
446
 * @deprecated use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead with a own instance of a working copy
447
 * owner.
418
 */
448
 */
419
ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
449
ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
420
/**
450
/**
Lines 457-462 Link Here
457
 * @return a new working copy of this element using the given factory to create
487
 * @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
488
 * the buffer, or this element if this element is already a working copy
459
 * @since 3.0
489
 * @since 3.0
490
 * 
491
 * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
460
 */
492
 */
461
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
493
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
462
/**
494
/**
Lines 469-475 Link Here
469
 */
501
 */
470
public boolean hasResourceChanged();
502
public boolean hasResourceChanged();
471
/**
503
/**
472
 * Returns whether this element is a working copy.
504
 * Returns true if this compilation is managed by the primary owner. The primary owner
505
 * typically contains the elements as seen in the file system or by the shared buffer.
506
 * All non-primary files belong to a custom woking copy ower that typically contains some
507
 * selected elements in a working state and inherits all other elements from the primary buffer.
508
 *
509
 * @return returns true if this compilation is managed by the primary owner
510
 * 
511
 * @since 3.3
512
 */
513
boolean isPrimary();
514
/**
515
 * Returns whether this element is a working copy. A woking copy is either a compilation unit with a non-primary
516
 * woking copy woner, or a primary compilation unit in buffered state.
473
 * 
517
 * 
474
 * @return true if this element is a working copy, false otherwise
518
 * @return true if this element is a working copy, false otherwise
475
 * @since 3.0
519
 * @since 3.0
Lines 536-541 Link Here
536
 * <li> The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
580
 * <li> The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
537
 * </ul>
581
 * </ul>
538
 * @since 3.0
582
 * @since 3.0
583
 * 
584
 * @deprecated use {@link #reconcile(boolean, WorkingCopyOwner, IProgressMonitor)} instead and use the AST as specified by 
585
 * {@link WorkingCopyOwner}. Using this API can result in performance degradation if the requested AST is
586
 * incompatible to the one configured in the {@link WorkingCopyOwner}.
539
 */
587
 */
540
CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
588
CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
541
589
Lines 601-610 Link Here
601
 * <li> The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
649
 * <li> The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
602
 * </ul>
650
 * </ul>
603
 * @since 3.2
651
 * @since 3.2
652
 * 
653
 * @deprecated Use {@link #reconcile(boolean, WorkingCopyOwner, IProgressMonitor)} instead and use the AST as specified by 
654
 * {@link WorkingCopyOwner}. Using this API can result in performance degradation if the requested AST is
655
 * incompatible to the one configured in the {@link WorkingCopyOwner}.
604
 */
656
 */
605
CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, boolean enableStatementsRecovery, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
657
CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, boolean enableStatementsRecovery, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
606
658
607
/**
659
/**
660
 * Reconciles the contents of this working copy, sends out a Java delta
661
 * notification indicating the nature of the change of the working copy since
662
 * the last time it was either reconciled or made consistent 
663
 * ({@link IOpenable#makeConsistent(IProgressMonitor)}), and returns a
664
 * compilation unit AST if requested.
665
 * <p>
666
 * It performs the reconciliation by locally caching the contents of 
667
 * the working copy, updating the contents, then creating a delta 
668
 * over the cached contents and the new contents, and finally firing
669
 * this delta.
670
 * <p>
671
 * The boolean argument allows to force problem detection even if the
672
 * working copy is already consistent.
673
 * </p>
674
 * <p>
675
 * This functionality allows to specify a working copy owner which is used
676
 * during problem detection. All references contained in the working copy are
677
 * resolved against other units; for which corresponding owned working copies
678
 * are going to take precedence over their original compilation units. If
679
 * <code>null</code> is passed in, then the primary working copy owner is used.
680
 * </p>
681
 * <p>
682
 * If the working copy owner defines a problem requestor (see {@link WorkingCopyOwner#getProblemRequestor()})
683
 * all compilation problems found in the new contents are reported to the requestor.
684
 * </p>
685
 * <p>
686
 * If the working copy owner defines that an AST should be build (see {@link WorkingCopyOwner#getReconcileASTKind()})
687
 * the created AST using the given parameters (see {@link WorkingCopyOwner#getReconcileASTRecoverStatements()}, {@link WorkingCopyOwner#getReconcileASTResolveBindings()})
688
 * is returned by this method and also reported in the Java delta notification (see {@link IJavaElementDelta#getCompilationUnitAST()}).
689
 * </p>
690
 * <p>
691
 * Note: Since 3.0, added/removed/changed inner types generate change deltas.
692
 * </p>
693
 * @param forceProblemDetection boolean indicating whether problem should be 
694
 *   recomputed even if the source hasn't changed
695
 * @param owner the owner of working copies that take precedence over the 
696
 *   original compilation units, or <code>null</code> if the primary working
697
 *   copy owner should be used
698
 * @param monitor a progress monitor
699
 * @return the compilation unit AST as configured by the {@link WorkingCopyOwner} or <code>null</code>
700
 *    or the working copy did not request an AST.
701
 * @throws JavaModelException if the contents of the original element
702
 *		cannot be accessed. Reasons include:
703
 * <ul>
704
 * <li> The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
705
 * </ul>
706
 * 
707
 * @since 3.3
708
 */
709
CompilationUnit reconcile(boolean forceProblemDetection, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
710
711
/**
608
 * Restores the contents of this working copy to the current contents of
712
 * Restores the contents of this working copy to the current contents of
609
 * this working copy's original element. Has no effect if this element
713
 * this working copy's original element. Has no effect if this element
610
 * is not a working copy.
714
 * is not a working copy.
(-)model/org/eclipse/jdt/core/IJavaElementDelta.java (-2 / +4 lines)
Lines 297-308 Link Here
297
	 * Returns the compilation unit AST created by the last reconcile operation on this delta's element.
297
	 * Returns the compilation unit AST created by the last reconcile operation on this delta's element.
298
	 * This returns a non-null value if and only if:
298
	 * This returns a non-null value if and only if:
299
	 * <ul>
299
	 * <ul>
300
	 * <li>the last reconcile operation on this working copy requested an AST</li>
300
	 * <li>the last reconcile operation on this working copy requested an AST. Note: Since 3.3 the
301
	 * working copy owner can specify if and what AST will be returned on reconcile</li>
301
	 * <li>this delta's element is an <code>ICompilationUnit</code> in working copy mode</li>
302
	 * <li>this delta's element is an <code>ICompilationUnit</code> in working copy mode</li>
302
	 * <li>the delta comes from a <code>POST_RECONCILE</code> event
303
	 * <li>the delta comes from a <code>POST_RECONCILE</code> event
303
	 * </ul>
304
	 * </ul>
305
	 * 
304
	 * @return the AST created during the last reconcile operation
306
	 * @return the AST created during the last reconcile operation
305
	 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
307
	 * @see ICompilationUnit#reconcile(boolean, WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
306
	 * @see #F_AST_AFFECTED
308
	 * @see #F_AST_AFFECTED
307
	 * @since 3.2
309
	 * @since 3.2
308
	 */
310
	 */
(-)model/org/eclipse/jdt/core/IClassFile.java (-80 / +4 lines)
Lines 32-100 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
39
 * created using the given owner. Uses the primary owner if <code>null</code> is
40
 * specified.
41
 * <p>
42
 * When switching to working copy mode, problems are reported to the given 
43
 * {@link IProblemRequestor}. Note that once in working copy mode, the given
44
 * {@link IProblemRequestor} is ignored. Only the original {@link IProblemRequestor}
45
 * is used to report subsequent problems.
46
 * </p>
47
 * <p>
48
 * Once in working copy mode, changes to this working copy or its children are done in memory.
49
 * Only the new buffer is affected. 
50
 * </p>
51
 * <p>
52
 * Using {@link ICompilationUnit#commitWorkingCopy(boolean, IProgressMonitor)} on the working copy
53
 * will throw a <code>JavaModelException</code> as a class file is implicetly read-only.
54
 * </p>
55
 * <p>
56
 * If this class file was already in working copy mode, an internal counter is incremented and no
57
 * other action is taken on this working copy. To bring this working copy back into the original mode 
58
 * (where it reflects the underlying resource), {@link ICompilationUnit#discardWorkingCopy} must be call as many 
59
 * times as {@link #becomeWorkingCopy(IProblemRequestor, WorkingCopyOwner, IProgressMonitor)}.
60
 * </p>
61
 * <p>
62
 * The primary compilation unit of a class file's working copy does not exist if the class file is not
63
 * in working copy mode (<code>classFileWorkingCopy.getPrimary().exists() == false</code>).
64
 * </p>
65
 * <p>
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>
68
 * 
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
71
 * 	that the client is not interested in problems.
72
 * @param owner the given {@link WorkingCopyOwner}, or <code>null</code> for the primary owner
73
 * @param monitor a progress monitor used to report progress while opening this compilation unit
74
 * 	or <code>null</code> if no progress should be reported 
75
 * @return a working copy for this class file
76
 * @throws JavaModelException if this compilation unit could not become a working copy.
77
 * @see ICompilationUnit#discardWorkingCopy()
78
 * @since 3.2
38
 * @since 3.2
39
 * 
40
 * @deprecated use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}
79
 */
41
 */
80
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
42
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
81
43
82
/**
44
/**
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.
45
 * Returns the type contained in this class file.
99
 *
46
 *
100
 * @return the type contained in this class file
47
 * @return the type contained in this class file
Lines 105-133 Link Here
105
IType getType() throws JavaModelException;
52
IType getType() throws JavaModelException;
106
/**
53
/**
107
 * Returns a working copy on the source associated with this class file using the given 
54
 * 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
55
 * factory to create the buffer, or <code>null</code> if there is no source associated
132
 * with the class file.
56
 * with the class file.
133
 * <p>
57
 * <p>
Lines 147-153 Link Here
147
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
71
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
148
 * </ul>
72
 * </ul>
149
 * @since 2.0
73
 * @since 2.0
150
 * @deprecated Use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
74
 * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
151
 */
75
 */
152
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
76
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
153
/**
77
/**
(-)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 (+32 lines)
Lines 586-591 Link Here
586
	return this;
586
	return this;
587
}
587
}
588
/**
588
/**
589
 * @see IMember#getJavaFile()
590
 */
591
public IJavaFile getJavaFile() {
592
	return this;
593
}
594
/**
589
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
595
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
590
 */
596
 */
591
public char[] getContents() {
597
public char[] getContents() {
Lines 873-878 Link Here
873
}
879
}
874
/**
880
/**
875
 * @see ICompilationUnit#getWorkingCopy(IProgressMonitor)
881
 * @see ICompilationUnit#getWorkingCopy(IProgressMonitor)
882
 * @deprecated
876
 */
883
 */
877
public ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
884
public ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
878
	return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/, monitor);
885
	return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/, monitor);
Lines 886-891 Link Here
886
}
893
}
887
/**
894
/**
888
 * @see ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
895
 * @see ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
896
 * @deprecated
889
 */
897
 */
890
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
898
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
891
	if (!isPrimary()) return this;
899
	if (!isPrimary()) return this;
Lines 1086-1091 Link Here
1086
}
1094
}
1087
/**
1095
/**
1088
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1096
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1097
 * @deprecated
1089
 */
1098
 */
1090
public void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException {
1099
public void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException {
1091
	reconcile(NO_AST, forceProblemDetection, false, null/*use primary owner*/, monitor);
1100
	reconcile(NO_AST, forceProblemDetection, false, null/*use primary owner*/, monitor);
Lines 1094-1099 Link Here
1094
/**
1103
/**
1095
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1104
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1096
 * @since 3.0
1105
 * @since 3.0
1106
 * @deprecated
1097
 */
1107
 */
1098
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1108
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1099
	int astLevel,
1109
	int astLevel,
Lines 1107-1112 Link Here
1107
/**
1117
/**
1108
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1118
 * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
1109
 * @since 3.0
1119
 * @since 3.0
1120
 * @deprecated
1110
 */
1121
 */
1111
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1122
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
1112
	int astLevel,
1123
	int astLevel,
Lines 1211-1215 Link Here
1211
	}
1222
	}
1212
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1223
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1213
}
1224
}
1225
/* (non-Javadoc)
1226
 * @see org.eclipse.jdt.core.ICompilationUnit#becomeWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
1227
 */
1228
public void becomeWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
1229
	becomeWorkingCopy(this.owner.getProblemRequestor(), monitor);
1230
}
1231
/* (non-Javadoc)
1232
 * @see org.eclipse.jdt.core.ICompilationUnit#reconcile(boolean, org.eclipse.jdt.core.WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
1233
 */
1234
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(boolean forceProblemDetection, WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException {
1235
	int astLevel= workingCopyOwner.getReconcileASTKind();
1236
	boolean statementRecovery= workingCopyOwner.getReconcileASTRecoverStatements();
1237
	boolean resolveBindings= workingCopyOwner.getReconcileASTResolveBindings(); // TODO: new API to pass in 'resolveBindings'
1238
	return reconcile(astLevel, forceProblemDetection, statementRecovery, workingCopyOwner, monitor);
1239
}
1240
/* (non-Javadoc)
1241
 * @see org.eclipse.jdt.core.IJavaFile#getWorkingCopy(org.eclipse.jdt.core.WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
1242
 */
1243
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException {
1244
	return getWorkingCopy(workingCopyOwner, workingCopyOwner.getProblemRequestor(), monitor);
1245
}
1214
1246
1215
}
1247
}
(-)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/JavaElement.java (+6 lines)
Lines 294-299 Link Here
294
	 */
294
	 */
295
	protected abstract char getHandleMementoDelimiter();
295
	protected abstract char getHandleMementoDelimiter();
296
	/**
296
	/**
297
	 * @see IMember
298
	 */
299
	public IJavaFile getJavaFile() {
300
		return null;
301
	}
302
	/**
297
	 * @see IJavaElement
303
	 * @see IJavaElement
298
	 */
304
	 */
299
	public IJavaModel getJavaModel() {
305
	public IJavaModel getJavaModel() {
(-)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 source is a class file has 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 (-7 / +20 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 936-946 Link Here
936
	 * Sets the Java element (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
948
	 * Sets the Java element (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
937
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java element.
949
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java element.
938
	 * 
950
	 * 
939
	 * @param element the Java element this compilation unit was created from
951
	 * @param javaFile the Java file this compilation unit was created from
940
	 * @since 3.1
952
	 * @since 3.1
941
	 */
953
	 */
942
	void setJavaElement(IJavaElement element) {
954
	//TODO: rename to setJavaFile(..)
943
		this.element = element;
955
	void setJavaElement(IJavaFile javaFile) {
956
		this.javaFile = javaFile;
944
	}
957
	}
945
	
958
	
946
	/**
959
	/**
(-)model/org/eclipse/jdt/core/IJavaFile.java (+96 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 type container (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
 * Returns a shared working copy on this compilation unit or class file using the given working copy owner to create
32
 * the buffer. If this is already a working copy of the given owner, the element itself is returned.
33
 * This API can only answer an already existing working copy if it is based on the same
34
 * original compilation unit AND was using the same working copy owner (that is, as defined by {@link Object#equals}).	 
35
 * <p>
36
 * The life time of a shared working copy is as follows:
37
 * <ul>
38
 * <li>The first call to {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} 
39
 * 	creates a new working copy for this element</li>
40
 * <li>Subsequent calls increment an internal counter.</li>
41
 * <li>A call to {@link ICompilationUnit#discardWorkingCopy()} decrements the internal counter.</li>
42
 * <li>When this counter is 0, the working copy is discarded.
43
 * </ul>
44
 * So users of this method must discard exactly once the working copy.
45
 * <p>
46
 * Note that the working copy owner will be used for the life time of this working copy, that is if the 
47
 * working copy is closed then reopened, this owner will be used.
48
 * The buffer will be automatically initialized with the original's compilation unit content
49
 * upon creation.
50
 * <p>
51
 * When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this
52
 * working copy.
53
 * </p><p>
54
 * Since 2.1, a working copy can be created on a not-yet existing compilation
55
 * unit. In particular, such a working copy can then be committed in order to create
56
 * the corresponding compilation unit.
57
 * </p><p>
58
 * The problems of this working copy are reported to the {@link IProblemRequestor} configured by the
59
 * {@link WorkingCopyOwner}.
60
 * </p>
61
 * 
62
 * @param owner the working copy owner that creates a buffer that is used to get the content 
63
 * 				of the working copy
64
 * @param monitor a progress monitor used to report progress while opening this compilation unit
65
 *                 or <code>null</code> if no progress should be reported 
66
 * @throws JavaModelException if the contents of this element can
67
 *   not be determined. 
68
 * @return a new working copy of this element using the given factory to create
69
 * the buffer, or this element if this element is already a working copy
70
 */
71
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
72
73
/**
74
 * Returns the smallest element within this java file that 
75
 * includes the given source position (that is, a method, field, etc.), or
76
 * <code>null</code> if there is no element other than the java file
77
 * itself at the given position, or if the given position is not
78
 * within the source range of this compilation unit.
79
 *
80
 * @param position a source position inside the java file
81
 * @return the innermost Java element enclosing a given source position or <code>null</code>
82
 *	if none (excluding the java file).
83
 * @throws JavaModelException if the java file does not exist or if an
84
 *	exception occurs while accessing its corresponding resource
85
 */
86
IJavaElement getElementAt(int position) throws JavaModelException;
87
88
/**
89
 * Finds the primary type of this java file (that is, the type with the same name as the
90
 * compilation unit, or the type of a class file), or <code>null</code> if no such a type exists.
91
 * 
92
 * @return the found primary type of this java file, or <code>null</code> if no such a type exists
93
 */
94
IType findPrimaryType();
95
96
}

Return to bug 125504