### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: model/org/eclipse/jdt/core/IWorkingCopy.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IWorkingCopy.java,v
retrieving revision 1.41
diff -u -r1.41 IWorkingCopy.java
--- model/org/eclipse/jdt/core/IWorkingCopy.java 29 Sep 2006 17:13:57 -0000 1.41
+++ model/org/eclipse/jdt/core/IWorkingCopy.java 17 Oct 2006 13:24:51 -0000
@@ -277,7 +277,7 @@
* the buffer, or this element if this element is already a working copy
* @since 2.0
*
- * @deprecated Use {@link ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)} instead.
+ * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead.
*/
IJavaElement getWorkingCopy(
IProgressMonitor monitor,
@@ -330,7 +330,7 @@
*
* @return null
*
- * @deprecated Use {@link ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)} instead.
+ * @deprecated Use {@link ICompilationUnit#reconcile(boolean, WorkingCopyOwner, IProgressMonitor)} instead.
*/
IMarker[] reconcile() throws JavaModelException;
@@ -361,7 +361,7 @@
*
* @since 2.0
*
- * @deprecated Use {@link ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)} instead.
+ * @deprecated Use {@link ICompilationUnit#reconcile(boolean, WorkingCopyOwner, IProgressMonitor)} instead.
*/
void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException;
Index: model/org/eclipse/jdt/core/WorkingCopyOwner.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/WorkingCopyOwner.java,v
retrieving revision 1.20
diff -u -r1.20 WorkingCopyOwner.java
--- model/org/eclipse/jdt/core/WorkingCopyOwner.java 13 Jul 2006 11:23:22 -0000 1.20
+++ model/org/eclipse/jdt/core/WorkingCopyOwner.java 17 Oct 2006 13:24:51 -0000
@@ -12,6 +12,8 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.internal.core.BufferManager;
import org.eclipse.jdt.internal.core.CompilationUnit;
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
@@ -19,7 +21,7 @@
import org.eclipse.jdt.internal.core.PackageFragment;
/**
- * The owner of an ICompilationUnit
handle in working copy mode.
+ * The owner of an {@link ICompilationUnit} handle in working copy mode.
* An owner is used to identify a working copy and to create its buffer.
*
* Clients should subclass this class to instantiate a working copy owner that is specific to their need and that @@ -29,14 +31,18 @@ * Note: even though this class has no abstract method, which means that it provides functional default behavior, * it is still an abstract class, as clients are intended to own their owner implementation. *
- * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, org.eclipse.core.runtime.IProgressMonitor) - * @see ICompilationUnit#discardWorkingCopy() - * @see ICompilationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor) + * @see ICompilationUnit#getWorkingCopy(WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor) * @since 3.0 */ public abstract class WorkingCopyOwner { /** + * Constant used by {@link #getReconcileASTKind()} to specify that the reconcile operation should not return an AST. + * @since 3.3 + */ + public static final int NO_AST = 0; + + /** * Sets the buffer provider of the primary working copy owner. Note that even if the * buffer provider is a working copy owner, only itscreateBuffer(ICompilationUnit)
* method is used by the primary working copy owner. It doesn't replace the internal primary
@@ -109,15 +115,151 @@
* @throws JavaModelException if the contents of this working copy can
* not be determined.
* @return a new working copy
- * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
+ * @see ICompilationUnit#becomeWorkingCopy(IProgressMonitor)
* @since 3.2
+ *
+ * @deprecated Use {@link #newWorkingCopy(String, IClasspathEntry[], IProgressMonitor)} instead to make sure the
+ * woking copy owners problem requestor.
*/
public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
ExternalJavaProject project = new ExternalJavaProject(classpath);
IPackageFragment parent = project.getPackageFragmentRoot(Path.EMPTY).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
result.becomeWorkingCopy(problemRequestor, monitor);
+ // TODO decide if also the default problem requestor (getProblemRequestor) should be notified.
return result;
}
-
+
+ /**
+ * Returns a new working copy with the given name using this working copy owner to
+ * create its buffer.
+ * + * This working copy always belongs to the default package in a package + * fragment root that corresponds to its Java project, and this Java project never exists. + * However this Java project has the given classpath that is used when resolving names + * in this working copy. + *
+ * A DOM AST created using this working copy will have bindings resolved using the given + * classpath, and problem are reported to the given problem requestor. + *
+ *JavaCore#getOptions()
is used to create the DOM AST as it is not
+ * possible to set the options on the non-existing Java project.
+ * + * When the working copy instance is created, an {@link IJavaElementDelta#ADDED added delta} is + * reported on this working copy. + *
+ * Once done with the working copy, users of this method must discard it using + * {@link ICompilationUnit#discardWorkingCopy()}. + *
+ * Note that when such working copy is committed, only its buffer is saved (see + * {@link IBuffer#save(IProgressMonitor, boolean)}) but no resource is created. + *
+ * This method is not intended to be overriden by clients. + *
+ * + * @param name the name of the working copy (e.g. "X.java") + * @param classpath the classpath used to resolve names in this working copy + * @param monitor a progress monitor used to report progress while opening the working copy + * ornull
if no progress should be reported
+ * @throws JavaModelException if the contents of this working copy can
+ * not be determined.
+ * @return a new working copy
+ * @see ICompilationUnit#becomeWorkingCopy(IProgressMonitor)
+ *
+ * @since 3.3
+ */
+ public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProgressMonitor monitor) throws JavaModelException {
+ ExternalJavaProject project = new ExternalJavaProject(classpath);
+ IPackageFragment parent = project.getPackageFragmentRoot(Path.EMPTY).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
+ CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
+ result.becomeWorkingCopy(getProblemRequestor(), monitor);
+ return result;
+ }
+
+ /**
+ * Returns the problem requestor used on reconcile (see {@link ICompilationUnit#reconcile(boolean, WorkingCopyOwner, IProgressMonitor)}
+ * by working copies of this working copy owner. null
is returned if no problem requestor needs to be informed.
+ * + * By default, no problem requestor is configured. Clients can override this method to provide a requestor. + *
+ * + * @return the problem requestor to be used by working copies of this working copy owner ornull
+ * if no problem requestor is configured.
+ *
+ * @since 3.3
+ */
+ public IProblemRequestor getProblemRequestor() {
+ return null;
+ }
+
+ /**
+ * Returns if and what kind of AST should be created on reconcile of a working copy of this working copy owner.
+ * If {@link #NO_AST} is returned, no AST will be created. Use the AST level constants on {@link AST} (for example
+ * {@link AST#JLS3}) to create an AST of given level.
+ *
+ * @return returns {@link #NO_AST} if no AST should be created on reconcile or the AST level of the AST to create.
+ * @see #getReconcileASTRecoverStatements()
+ * @see #getReconcileASTResolveBindings()
+ * @see ASTParser#newParser(int)
+ *
+ * @since 3.3
+ */
+ public int getReconcileASTKind() {
+ return NO_AST;
+ }
+
+ /**
+ * Specifies if an AST created on reconcile should contain resolved bindings or not.
+ * Note, ASTs are only created on reconcile if {@link #getReconcileASTKind()} does not return {@link #NO_AST}.
+ *
+ * @return true
is returned if AST created on reconcile should also contain resolved bindings.
+ * @see ASTParser#setResolveBindings(boolean)
+ *
+ * @since 3.3
+ */
+ public boolean getReconcileASTResolveBindings() {
+ return false;
+ }
+
+ /**
+ * Specifies if an AST created on reconcile should try to recover statements or not.
+ * Note, ASTs are only created on reconcile if {@link #getReconcileASTKind()} does not return {@link #NO_AST}.
+ *
+ * @return true
is returned if AST created on reconcile should also try to recover statements.
+ * @see ASTParser#setStatementsRecovery(boolean)
+ *
+ * @since 3.3
+ */
+ public boolean getReconcileASTRecoverStatements() {
+ return false;
+ }
+
+ /**
+ * Returns a new non primary owner using the built-in buffer management and the given settings.
+ *
+ * @param requestor the problem requestor to use
+ * @param astKind the AST level to use or {@link #NO_AST} to not provide an AST on reconcile
+ * @param resolveBindings specifies if ASTs created on reconcile should contain resolved bindings
+ * @param recoverStatements specifies if ASTs created on reconcile should try to recover statements
+ *
+ * @return the new working copy owner
+ *
+ * @since 3.3
+ */
+ public WorkingCopyOwner createNonPrimaryOwner(final IProblemRequestor requestor, final int astKind, final boolean resolveBindings, final boolean recoverStatements) {
+ return new WorkingCopyOwner() {
+ public IProblemRequestor getProblemRequestor() {
+ return requestor;
+ }
+ public int getReconcileASTKind() {
+ return astKind;
+ }
+ public boolean getReconcileASTResolveBindings() {
+ return resolveBindings;
+ }
+ public boolean getReconcileASTRecoverStatements() {
+ return recoverStatements;
+ }
+ };
+ }
}
Index: model/org/eclipse/jdt/core/IMember.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMember.java,v
retrieving revision 1.23
diff -u -r1.23 IMember.java
--- model/org/eclipse/jdt/core/IMember.java 10 May 2006 18:03:42 -0000 1.23
+++ model/org/eclipse/jdt/core/IMember.java 17 Oct 2006 13:24:51 -0000
@@ -49,6 +49,14 @@
*/
ICompilationUnit getCompilationUnit();
/**
+ * Returns the Java file in which this member is declared.
+ * This is a handle-only method.
+ *
+ * @return the Java file in which this member is declared
+ * @since 3.3
+ */
+IJavaFile getJavaFile();
+/**
* Returns the type in which this member is declared, or null
* if this member is not declared in a type (for example, a top-level type).
* This is a handle-only method.
Index: model/org/eclipse/jdt/core/ICompilationUnit.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ICompilationUnit.java,v
retrieving revision 1.57
diff -u -r1.57 ICompilationUnit.java
--- model/org/eclipse/jdt/core/ICompilationUnit.java 29 Mar 2006 03:08:46 -0000 1.57
+++ model/org/eclipse/jdt/core/ICompilationUnit.java 17 Oct 2006 13:24:51 -0000
@@ -30,10 +30,12 @@
* This interface is not intended to be implemented by clients.
*
*/
-public interface ICompilationUnit extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation, ICodeAssist {
+public interface ICompilationUnit extends IJavaFile, IWorkingCopy, ISourceManipulation {
/**
* Constant indicating that a reconcile operation should not return an AST.
* @since 3.0
+ *
+ * @deprecated
*/
public static final int NO_AST = 0;
@@ -67,8 +69,43 @@
* @throws JavaModelException if this compilation unit could not become a working copy.
* @see #discardWorkingCopy()
* @since 3.0
+ *
+ * @deprecated Use {@link #becomeWorkingCopy(IProgressMonitor)} instead which uses the
+ * {@IProblemRequestor problem requestor} defined by this compilation units working copy owner
+ * (see {@link WorkingCopyOwner#getProblemRequestor()}).
*/
void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
+
+/**
+ * Makes sure this compilation unit handle is in a working copy mode, say an {@link IBuffer} is
+ * created using this compilation units working copy owner.
+ * This method only has an effect if the compilation is a primary compilation unit ({@link ICompilationUnit#isPrimary()}
+ * as only primary working copies can be in a non-working copy state.
+ * + * For each call to this API, regardless if this compilation unit was already a working copy or not, + * an internal reference counter is incremented. As long as this reference counter is not 0, the buffer is kept in memory. + *
+ *+ * To bring this compilation unit back into the original mode (where it reflects the underlying resource) and to + * to release the buffer, {@link #discardWorkingCopy} must be called as many + * times as {@link #becomeWorkingCopy(IProgressMonitor)}. + *
+ *+ * Once in working copy mode, changes to this compilation unit or its children are done in memory. + * Only the buffer is affected. Using {@link #commitWorkingCopy(boolean, IProgressMonitor)} + * will bring the underlying resource in sync with this compilation unit. {@link #commitWorkingCopy(boolean, IProgressMonitor)} + * does not modify the internal reference counter. + *
+ * + * @param monitor a progress monitor used to report progress while opening this compilation unit + * ornull
if no progress should be reported
+ * @throws JavaModelException if this compilation unit could not become a working copy.
+ * @see #discardWorkingCopy()
+ *
+ * @since 3.3
+ */
+void becomeWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
+
/**
* Commits the contents of this working copy to its underlying resource.
*
@@ -223,13 +260,17 @@
* This has no effect if this compilation unit was not in working copy mode.
*
* - * If {@link #becomeWorkingCopy} was called several times on this + * If {@link #becomeWorkingCopy(IProgressMonitor)} was called several times on this * compilation unit, {@link #discardWorkingCopy} must be called as * many times before it switches back to the original mode. *
+ *{@link #discardWorkingCopy} also has to be called on each compilation unit returned by + * {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}. + *
* * @throws JavaModelException if this working copy could not return in its original mode. - * @see #becomeWorkingCopy(IProblemRequestor, IProgressMonitor) + * @see #becomeWorkingCopy(IProgressMonitor) + * @see #getWorkingCopy(WorkingCopyOwner, IProgressMonitor) * @since 3.0 */ void discardWorkingCopy() throws JavaModelException; @@ -286,20 +327,6 @@ */ IType[] getAllTypes() throws JavaModelException; /** - * Returns the smallest element within this compilation unit that - * includes the given source position (that is, a method, field, etc.), or - *null
if there is no element other than the compilation
- * unit itself at the given position, or if the given position is not
- * within the source range of this compilation unit.
- *
- * @param position a source position inside the compilation unit
- * @return the innermost Java element enclosing a given source position or null
- * if none (excluding the compilation unit).
- * @throws JavaModelException if the compilation unit does not exist or if an
- * exception occurs while accessing its corresponding resource
- */
-IJavaElement getElementAt(int position) throws JavaModelException;
-/**
* Returns the first import declaration in this compilation unit with the given name.
* This is a handle-only method. The import declaration may or may not exist. This
* is a convenience method - imports can also be accessed from a compilation unit's
@@ -344,8 +371,8 @@
*/
ICompilationUnit getPrimary();
/**
- * Returns the working copy owner of this working copy.
- * Returns null if it is not a working copy or if it has no owner.
+ * Returns the working copy owner of this working copy or null
if this compilation unit is managed by the
+ * primary owner.
*
* @return WorkingCopyOwner the owner of this working copy or null
* @since 3.0
@@ -415,6 +442,9 @@
* @return a new working copy of this element if this element is not
* a working copy, or this element if this element is already a working copy
* @since 3.0
+ *
+ * @deprecated use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead with a own instance of a working copy
+ * owner.
*/
ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException;
/**
@@ -457,6 +487,8 @@
* @return a new working copy of this element using the given factory to create
* the buffer, or this element if this element is already a working copy
* @since 3.0
+ *
+ * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
*/
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
/**
@@ -469,7 +501,19 @@
*/
public boolean hasResourceChanged();
/**
- * Returns whether this element is a working copy.
+ * Returns true if this compilation is managed by the primary owner. The primary owner
+ * typically contains the elements as seen in the file system or by the shared buffer.
+ * All non-primary files belong to a custom woking copy ower that typically contains some
+ * selected elements in a working state and inherits all other elements from the primary buffer.
+ *
+ * @return returns true if this compilation is managed by the primary owner
+ *
+ * @since 3.3
+ */
+boolean isPrimary();
+/**
+ * Returns whether this element is a working copy. A woking copy is either a compilation unit with a non-primary
+ * woking copy woner, or a primary compilation unit in buffered state.
*
* @return true if this element is a working copy, false otherwise
* @since 3.0
@@ -536,6 +580,10 @@
* + * It performs the reconciliation by locally caching the contents of + * the working copy, updating the contents, then creating a delta + * over the cached contents and the new contents, and finally firing + * this delta. + *
+ * The boolean argument allows to force problem detection even if the + * working copy is already consistent. + *
+ *
+ * This functionality allows to specify a working copy owner which is used
+ * during problem detection. All references contained in the working copy are
+ * resolved against other units; for which corresponding owned working copies
+ * are going to take precedence over their original compilation units. If
+ * null
is passed in, then the primary working copy owner is used.
+ *
+ * If the working copy owner defines a problem requestor (see {@link WorkingCopyOwner#getProblemRequestor()}) + * all compilation problems found in the new contents are reported to the requestor. + *
+ *+ * If the working copy owner defines that an AST should be build (see {@link WorkingCopyOwner#getReconcileASTKind()}) + * the created AST using the given parameters (see {@link WorkingCopyOwner#getReconcileASTRecoverStatements()}, {@link WorkingCopyOwner#getReconcileASTResolveBindings()}) + * is returned by this method and also reported in the Java delta notification (see {@link IJavaElementDelta#getCompilationUnitAST()}). + *
+ *+ * Note: Since 3.0, added/removed/changed inner types generate change deltas. + *
+ * @param forceProblemDetection boolean indicating whether problem should be + * recomputed even if the source hasn't changed + * @param owner the owner of working copies that take precedence over the + * original compilation units, ornull
if the primary working
+ * copy owner should be used
+ * @param monitor a progress monitor
+ * @return the compilation unit AST as configured by the {@link WorkingCopyOwner} or null
+ * or the working copy did not request an AST.
+ * @throws JavaModelException if the contents of the original element
+ * cannot be accessed. Reasons include:
+ * ICompilationUnit
in working copy modePOST_RECONCILE
event
* null
is
- * specified.
- * - * When switching to working copy mode, problems are reported to the given - * {@link IProblemRequestor}. Note that once in working copy mode, the given - * {@link IProblemRequestor} is ignored. Only the original {@link IProblemRequestor} - * is used to report subsequent problems. - *
- *- * Once in working copy mode, changes to this working copy or its children are done in memory. - * Only the new buffer is affected. - *
- *
- * Using {@link ICompilationUnit#commitWorkingCopy(boolean, IProgressMonitor)} on the working copy
- * will throw a JavaModelException
as a class file is implicetly read-only.
- *
- * If this class file was already in working copy mode, an internal counter is incremented and no - * other action is taken on this working copy. To bring this working copy back into the original mode - * (where it reflects the underlying resource), {@link ICompilationUnit#discardWorkingCopy} must be call as many - * times as {@link #becomeWorkingCopy(IProblemRequestor, WorkingCopyOwner, IProgressMonitor)}. - *
- *
- * The primary compilation unit of a class file's working copy does not exist if the class file is not
- * in working copy mode (classFileWorkingCopy.getPrimary().exists() == false
).
- *
- * The resource of a class file's working copy is null
if the class file is in an external jar file.
- *
null
indicating
- * that the client is not interested in problems.
- * @param owner the given {@link WorkingCopyOwner}, or null
for the primary owner
- * @param monitor a progress monitor used to report progress while opening this compilation unit
- * or null
if no progress should be reported
- * @return a working copy for this class file
- * @throws JavaModelException if this compilation unit could not become a working copy.
- * @see ICompilationUnit#discardWorkingCopy()
* @since 3.2
+ *
+ * @deprecated use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}
*/
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
/**
- * Returns the smallest element within this class file that
- * includes the given source position (a method, field, etc.), or
- * null
if there is no element other than the class file
- * itself at the given position, or if the given position is not
- * within the source range of this class file.
- *
- * @param position a source position inside the class file
- * @return the innermost Java element enclosing a given source position or null
- * if none (excluding the class file).
- *
- * @exception JavaModelException if this element does not exist or if an
- * exception occurs while accessing its corresponding resource
- */
-IJavaElement getElementAt(int position) throws JavaModelException;
-/**
* Returns the type contained in this class file.
*
* @return the type contained in this class file
@@ -105,29 +52,6 @@
IType getType() throws JavaModelException;
/**
* Returns a working copy on the source associated with this class file using the given
- * owner to create the buffer, or null
if there is no source associated
- * with the class file.
- * - * The buffer will be automatically initialized with the source of the class file - * upon creation. - *
- * The only valid operations on this working copy are getBuffer()
or getPrimary()
.
- *
- * @param owner the owner that creates a buffer that is used to get the content of the working copy
- * or null
if the primary owner should be used
- * @param monitor a progress monitor used to report progress while opening this compilation unit
- * or null
if no progress should be reported
- * @return a a working copy on the source associated with this class file
- * @exception JavaModelException if the source of this class file can
- * not be determined. Reasons include:
- *
null
if there is no source associated
* with the class file.
* @@ -147,7 +71,7 @@ *
null
if none
*/
public void setSource(ICompilationUnit source) {
- this.compilationUnitSource = source;
- // clear the others
- this.rawSource = null;
- this.classFileSource = null;
- if (source != null) {
- this.project = source.getJavaProject();
- Map options = this.project.getOptions(true);
- options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
- this.compilerOptions = options;
- }
+ setSource((IJavaFile) source);
}
/**
@@ -491,10 +476,25 @@
* is to be parsed, or null
if none
*/
public void setSource(IClassFile source) {
- this.classFileSource = source;
- // clear the others
+ setSource((IJavaFile) source);
+ }
+
+ /**
+ * Sets the source code to be parsed.
+ * This method automatically sets the project (and compiler
+ * options) based on the given compilation unit of class file, in a manner
+ * equivalent to setProject(source.getJavaProject())
.
If source is a class file has without source attachment, the creation of the + * ast will fail with an IllegalStateException.
+ * + * @param source the Java model compilation unit or class file whose corresponding source code + * is to be parsed, ornull
if none
+ * @since 3.3
+ */
+ public void setSource(IJavaFile source) {
+ this.javaFileSource = source;
+ // clear the other
this.rawSource = null;
- this.compilationUnitSource = null;
if (source != null) {
this.project = source.getJavaProject();
Map options = this.project.getOptions(true);
@@ -623,8 +623,7 @@
if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$
try {
if ((this.rawSource == null)
- && (this.compilationUnitSource == null)
- && (this.classFileSource == null)) {
+ && (this.javaFileSource == null)) {
throw new IllegalStateException("source not specified"); //$NON-NLS-1$
}
result = internalCreateAST(monitor);
@@ -782,22 +781,22 @@
try {
NodeSearcher searcher = null;
org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null;
- IJavaElement element = null;
- if (this.compilationUnitSource != null) {
- sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.compilationUnitSource;
- // use a BasicCompilation that caches the source instead of using the compilationUnitSource directly
+ IJavaFile javaFile = null;
+ if (this.javaFileSource instanceof ICompilationUnit) {
+ sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.javaFileSource;
+ // use a BasicCompilation that caches the source instead of using the javaFileSource directly
// (if it is a working copy, the source can change between the parse and the AST convertion)
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632)
sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project);
- element = this.compilationUnitSource;
- } else if (this.classFileSource != null) {
+ javaFile = this.javaFileSource;
+ } else if (this.javaFileSource instanceof IClassFile) {
try {
- String sourceString = this.classFileSource.getSource();
+ String sourceString = this.javaFileSource.getSource();
if (sourceString == null) {
throw new IllegalStateException();
}
- PackageFragment packageFragment = (PackageFragment) this.classFileSource.getParent();
- BinaryType type = (BinaryType) this.classFileSource.getType();
+ PackageFragment packageFragment = (PackageFragment) this.javaFileSource.getParent();
+ BinaryType type = (BinaryType) this.javaFileSource.findPrimaryType();
IBinaryType binaryType = (IBinaryType) type.getElementInfo();
// file name is used to recreate the Java element, so it has to be the toplevel .class file name
char[] fileName = binaryType.getFileName();
@@ -811,7 +810,7 @@
fileName = newFileName;
}
sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project);
- element = this.classFileSource;
+ javaFile = this.javaFileSource;
} catch(JavaModelException e) {
// an error occured accessing the java element
throw new IllegalStateException();
@@ -859,10 +858,10 @@
this.apiLevel,
this.compilerOptions,
needToResolveBindings,
- this.compilationUnitSource == null ? this.workingCopyOwner : this.compilationUnitSource.getOwner(),
+ ! (this.javaFileSource instanceof ICompilationUnit) ? this.workingCopyOwner : ((ICompilationUnit) this.javaFileSource).getOwner(),
needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null,
monitor);
- result.setJavaElement(element);
+ result.setJavaElement(javaFile);
return result;
} finally {
if (compilationUnitDeclaration != null && this.resolveBindings) {
Index: dom/org/eclipse/jdt/core/dom/CompilationUnit.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java,v
retrieving revision 1.83
diff -u -r1.83 CompilationUnit.java
--- dom/org/eclipse/jdt/core/dom/CompilationUnit.java 23 Jun 2006 13:44:54 -0000 1.83
+++ dom/org/eclipse/jdt/core/dom/CompilationUnit.java 17 Oct 2006 13:24:50 -0000
@@ -18,6 +18,7 @@
import java.util.Map;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaFile;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
import org.eclipse.jface.text.IDocument;
@@ -123,11 +124,11 @@
private DefaultCommentMapper commentMapper = null;
/**
- * The Java element (an org.eclipse.jdt.core.ICompilationUnit
or an org.eclipse.jdt.core.IClassFile
)
- * this compilation unit was created from, or null
if it was not created from a Java element.
+ * The Java file (an org.eclipse.jdt.core.ICompilationUnit
or an org.eclipse.jdt.core.IClassFile
)
+ * this compilation unit was created from, or null
if it was not created from a Java file.
* @since 3.1
*/
- private IJavaElement element = null;
+ private IJavaFile javaFile = null;
/**
* The list of import declarations in textual order order;
@@ -492,7 +493,18 @@
* @since 3.1
*/
public IJavaElement getJavaElement() {
- return this.element;
+ return this.javaFile;
+ }
+
+ /**
+ * The Java file (an org.eclipse.jdt.core.ICompilationUnit
or an org.eclipse.jdt.core.IClassFile
)
+ * this compilation unit was created from, or null
if it was not created from a Java file.
+ *
+ * @return the Java file this compilation unit was created from, or null
if none
+ * @since 3.3
+ */
+ public IJavaFile getJavaFile() {
+ return this.javaFile;
}
/**
@@ -936,11 +948,12 @@
* Sets the Java element (an org.eclipse.jdt.core.ICompilationUnit
or an org.eclipse.jdt.core.IClassFile
)
* this compilation unit was created from, or null
if it was not created from a Java element.
*
- * @param element the Java element this compilation unit was created from
+ * @param javaFile the Java file this compilation unit was created from
* @since 3.1
*/
- void setJavaElement(IJavaElement element) {
- this.element = element;
+ //TODO: rename to setJavaFile(..)
+ void setJavaElement(IJavaFile javaFile) {
+ this.javaFile = javaFile;
}
/**
Index: model/org/eclipse/jdt/core/IJavaFile.java
===================================================================
RCS file: model/org/eclipse/jdt/core/IJavaFile.java
diff -N model/org/eclipse/jdt/core/IJavaFile.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/jdt/core/IJavaFile.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+
+/**
+ * Represents an entire Java type container (either an ICompilationUnit
+ * or an IClassFile
).
+ *
+ * + * This interface is not intended to be implemented by clients. + *
+ * + * @see ICompilationUnit + * @see IClassFile + * @since 3.3 + */ +public interface IJavaFile extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist { + +/** + * Returns a shared working copy on this compilation unit or class file using the given working copy owner to create + * the buffer. If this is already a working copy of the given owner, the element itself is returned. + * This API can only answer an already existing working copy if it is based on the same + * original compilation unit AND was using the same working copy owner (that is, as defined by {@link Object#equals}). + *+ * The life time of a shared working copy is as follows: + *
+ * Note that the working copy owner will be used for the life time of this working copy, that is if the + * working copy is closed then reopened, this owner will be used. + * The buffer will be automatically initialized with the original's compilation unit content + * upon creation. + *
+ * When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this + * working copy. + *
+ * Since 2.1, a working copy can be created on a not-yet existing compilation + * unit. In particular, such a working copy can then be committed in order to create + * the corresponding compilation unit. + *
+ * The problems of this working copy are reported to the {@link IProblemRequestor} configured by the + * {@link WorkingCopyOwner}. + *
+ * + * @param owner the working copy owner that creates a buffer that is used to get the content + * of the working copy + * @param monitor a progress monitor used to report progress while opening this compilation unit + * ornull
if no progress should be reported
+ * @throws JavaModelException if the contents of this element can
+ * not be determined.
+ * @return a new working copy of this element using the given factory to create
+ * the buffer, or this element if this element is already a working copy
+ */
+ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
+
+/**
+ * Returns the smallest element within this java file that
+ * includes the given source position (that is, a method, field, etc.), or
+ * null
if there is no element other than the java file
+ * itself at the given position, or if the given position is not
+ * within the source range of this compilation unit.
+ *
+ * @param position a source position inside the java file
+ * @return the innermost Java element enclosing a given source position or null
+ * if none (excluding the java file).
+ * @throws JavaModelException if the java file does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+IJavaElement getElementAt(int position) throws JavaModelException;
+
+/**
+ * Finds the primary type of this java file (that is, the type with the same name as the
+ * compilation unit, or the type of a class file), or null
if no such a type exists.
+ *
+ * @return the found primary type of this java file, or null
if no such a type exists
+ */
+IType findPrimaryType();
+
+}