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 (-23 / +1 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 254-267 Link Here
254
 */
254
 */
255
IJavaElement[] findElements(IJavaElement element);
255
IJavaElement[] findElements(IJavaElement element);
256
/**
256
/**
257
 * Finds the primary type of this compilation unit (that is, the type with the same name as the
258
 * compilation unit), or <code>null</code> if no such a type exists.
259
 * 
260
 * @return the found primary type of this compilation unit, or <code>null</code> if no such a type exists
261
 * @since 3.0
262
 */
263
IType findPrimaryType();
264
/**
265
 * Finds the working copy for this compilation unit, given a {@link WorkingCopyOwner}. 
257
 * Finds the working copy for this compilation unit, given a {@link WorkingCopyOwner}. 
266
 * If no working copy has been created for this compilation unit associated with this
258
 * If no working copy has been created for this compilation unit associated with this
267
 * working copy owner, returns <code>null</code>.
259
 * working copy owner, returns <code>null</code>.
Lines 286-305 Link Here
286
 */
278
 */
287
IType[] getAllTypes() throws JavaModelException;
279
IType[] getAllTypes() throws JavaModelException;
288
/**
280
/**
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.
281
 * 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
282
 * 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
283
 * is a convenience method - imports can also be accessed from a compilation unit's
(-)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 (-40 / +2 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 80-100 Link Here
80
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
80
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
81
81
82
/**
82
/**
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.
83
 * Returns the type contained in this class file.
99
 *
84
 *
100
 * @return the type contained in this class file
85
 * @return the type contained in this class file
Lines 105-133 Link Here
105
IType getType() throws JavaModelException;
90
IType getType() throws JavaModelException;
106
/**
91
/**
107
 * Returns a working copy on the source associated with this class file using the given 
92
 * 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
93
 * factory to create the buffer, or <code>null</code> if there is no source associated
132
 * with the class file.
94
 * with the class file.
133
 * <p>
95
 * <p>
Lines 147-153 Link Here
147
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
109
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
148
 * </ul>
110
 * </ul>
149
 * @since 2.0
111
 * @since 2.0
150
 * @deprecated Use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
112
 * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
151
 */
113
 */
152
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
114
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
153
/**
115
/**
(-)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 (+12 lines)
Lines 713-718 Link Here
713
	System.arraycopy(elements, 0, imports, 0, length);
713
	System.arraycopy(elements, 0, imports, 0, length);
714
	return imports;
714
	return imports;
715
}
715
}
716
/*
717
 * @see IMember
718
 */
719
public IJavaFile getJavaFile() {
720
	return this;
721
}
716
/**
722
/**
717
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
723
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
718
 */
724
 */
Lines 878-883 Link Here
878
	return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/, monitor);
884
	return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/, monitor);
879
}
885
}
880
/**
886
/**
887
 * @see IJavaFile#getWorkingCopy(WorkingCopyOwner, IProblemRequestor)
888
 */
889
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException {
890
	return getWorkingCopy(workingCopyOwner, null, monitor);
891
}
892
/**
881
 * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
893
 * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
882
 * @deprecated
894
 * @deprecated
883
 */
895
 */
(-)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 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