### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: model/org/eclipse/jdt/core/IWorkingCopy.java
===================================================================
RCS file: /cvsroot/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 19 Oct 2006 14:51:34 -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,
Index: model/org/eclipse/jdt/core/ICompilationUnit.java
===================================================================
RCS file: /cvsroot/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 19 Oct 2006 14:51:34 -0000
@@ -30,7 +30,7 @@
* 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
@@ -67,8 +67,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
+ * {@link 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
+ * or null
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.
*
@@ -99,29 +134,6 @@
*/
void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException;
/**
- * Creates and returns an non-static import declaration in this compilation unit
- * with the given name. This method is equivalent to
- * createImport(name, Flags.AccDefault, sibling, monitor)
.
- *
- * @param name the name of the import declaration to add as defined by JLS2 7.5. (For example: "java.io.File"
or
- * "java.awt.*"
)
- * @param sibling the existing element which the import declaration will be inserted immediately before (if
- * null
, then this import will be inserted as the last import declaration.
- * @param monitor the progress monitor to notify
- * @return the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
- *
- * @throws JavaModelException if the element could not be created. Reasons include:
- *
- * - This Java element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)
- * - A {@link org.eclipse.core.runtime.CoreException} occurred while updating an underlying resource
- *
- The specified sibling is not a child of this compilation unit (INVALID_SIBLING)
- *
- The name is not a valid import name (INVALID_NAME)
- *
- * @see #createImport(String, IJavaElement, int, IProgressMonitor)
- */
-IImportDeclaration createImport(String name, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException;
-
-/**
* Creates and returns an import declaration in this compilation unit
* with the given name.
*
@@ -164,7 +176,28 @@
* @since 3.0
*/
IImportDeclaration createImport(String name, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException;
-
+/**
+ * Creates and returns an non-static import declaration in this compilation unit
+ * with the given name. This method is equivalent to
+ * createImport(name, Flags.AccDefault, sibling, monitor)
.
+ *
+ * @param name the name of the import declaration to add as defined by JLS2 7.5. (For example: "java.io.File"
or
+ * "java.awt.*"
)
+ * @param sibling the existing element which the import declaration will be inserted immediately before (if
+ * null
, then this import will be inserted as the last import declaration.
+ * @param monitor the progress monitor to notify
+ * @return the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
+ *
+ * @throws JavaModelException if the element could not be created. Reasons include:
+ *
+ * - This Java element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)
+ * - A {@link org.eclipse.core.runtime.CoreException} occurred while updating an underlying resource
+ *
- The specified sibling is not a child of this compilation unit (INVALID_SIBLING)
+ *
- The name is not a valid import name (INVALID_NAME)
+ *
+ * @see #createImport(String, IJavaElement, int, IProgressMonitor)
+ */
+IImportDeclaration createImport(String name, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException;
/**
* Creates and returns a package declaration in this compilation unit
* with the given package name.
@@ -223,13 +256,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 +323,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
@@ -331,21 +354,8 @@
*/
IImportDeclaration[] getImports() throws JavaModelException;
/**
- * Returns the primary compilation unit (whose owner is the primary owner)
- * this working copy was created from, or this compilation unit if this a primary
- * compilation unit.
- *
- * Note that the returned primary compilation unit can be in working copy mode.
- *
- *
- * @return the primary compilation unit this working copy was created from,
- * or this compilation unit if it is primary
- * @since 3.0
- */
-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
@@ -372,6 +382,19 @@
*/
IPackageDeclaration[] getPackageDeclarations() throws JavaModelException;
/**
+ * Returns the primary compilation unit (whose owner is the primary owner)
+ * this working copy was created from, or this compilation unit if this a primary
+ * compilation unit.
+ *
+ * Note that the returned primary compilation unit can be in working copy mode.
+ *
+ *
+ * @return the primary compilation unit this working copy was created from,
+ * or this compilation unit if it is primary
+ * @since 3.0
+ */
+ICompilationUnit getPrimary();
+/**
* Returns the top-level type declared in this compilation unit with the given simple type name.
* The type name has to be a valid compilation unit name.
* This is a handle-only method. The type may or may not exist.
@@ -415,6 +438,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 +483,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 +497,19 @@
*/
public boolean hasResourceChanged();
/**
- * Returns whether this element is a working copy.
+ * Returns whether 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 owner 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
+ * working copy woner, or a primary compilation unit in buffered state.
*
* @return true if this element is a working copy, false otherwise
* @since 3.0
Index: model/org/eclipse/jdt/core/IMember.java
===================================================================
RCS file: /cvsroot/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 19 Oct 2006 14:51:34 -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/IClassFile.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClassFile.java,v
retrieving revision 1.21
diff -u -r1.21 IClassFile.java
--- model/org/eclipse/jdt/core/IClassFile.java 29 Sep 2006 17:13:57 -0000 1.21
+++ model/org/eclipse/jdt/core/IClassFile.java 19 Oct 2006 14:51:33 -0000
@@ -32,7 +32,7 @@
* @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, IProgressMonitor)
*/
-public interface IClassFile extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist {
+public interface IClassFile extends IJavaFile {
/**
* Changes this class file handle into a working copy. A new {@link IBuffer} is
@@ -66,7 +66,7 @@
* The resource of a class file's working copy is null
if the class file is in an external jar file.
*
*
- * @param problemRequestor a requestor which will get notified of problems detected during
+* @param problemRequestor a requestor which will get notified of problems detected during
* reconciling as they are discovered. The requestor can be set to null
indicating
* that the client is not interested in problems.
* @param owner the given {@link WorkingCopyOwner}, or null
for the primary owner
@@ -76,25 +76,12 @@
* @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 +92,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:
- *
- * - This class file does not exist (ELEMENT_DOES_NOT_EXIST)
- *
- * @since 3.0
- */
-ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
-/**
- * Returns a working copy on the source associated with this class file using the given
* factory to create the buffer, or null
if there is no source associated
* with the class file.
*
@@ -147,7 +111,7 @@
*
This class file does not exist (ELEMENT_DOES_NOT_EXIST)
*
* @since 2.0
- * @deprecated Use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
+ * @deprecated Use {@link IJavaFile#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
*/
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
/**
Index: model/org/eclipse/jdt/internal/core/SourceRefElement.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceRefElement.java,v
retrieving revision 1.46
diff -u -r1.46 SourceRefElement.java
--- model/org/eclipse/jdt/internal/core/SourceRefElement.java 24 Nov 2005 12:14:48 -0000 1.46
+++ model/org/eclipse/jdt/internal/core/SourceRefElement.java 19 Oct 2006 14:51:36 -0000
@@ -151,6 +151,12 @@
String token = memento.nextToken();
return getHandleFromMemento(token, memento, owner);
}
+/**
+ * @see IMember
+ */
+public IJavaFile getJavaFile() {
+ return ((JavaElement)getParent()).getJavaFile();
+}
/*
* @see IMember#getOccurrenceCount()
*/
Index: model/org/eclipse/jdt/internal/core/CompilationUnit.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java,v
retrieving revision 1.233
diff -u -r1.233 CompilationUnit.java
--- model/org/eclipse/jdt/internal/core/CompilationUnit.java 17 Jul 2006 11:40:27 -0000 1.233
+++ model/org/eclipse/jdt/internal/core/CompilationUnit.java 19 Oct 2006 14:51:35 -0000
@@ -54,7 +54,7 @@
this.name = name;
this.owner = owner;
}
-/*
+/* (non-Javadoc)
* @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
*/
public void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
@@ -68,6 +68,12 @@
operation.runOperation(monitor);
}
}
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.ICompilationUnit#becomeWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
+ */
+public void becomeWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
+ becomeWorkingCopy(this.owner.getProblemRequestor(), monitor);
+}
protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
// check if this compilation unit can be opened
@@ -196,27 +202,28 @@
return unitInfo.isStructureKnown();
}
-/*
+/* (non-Javadoc)
* @see Openable#canBeRemovedFromCache
*/
public boolean canBeRemovedFromCache() {
if (getPerWorkingCopyInfo() != null) return false; // working copies should remain in the cache until they are destroyed
return super.canBeRemovedFromCache();
}
-/*
+/* (non-Javadoc)
* @see Openable#canBufferBeRemovedFromCache
*/
public boolean canBufferBeRemovedFromCache(IBuffer buffer) {
if (getPerWorkingCopyInfo() != null) return false; // working copy buffers should remain in the cache until working copy is destroyed
return super.canBufferBeRemovedFromCache(buffer);
-}/*
+}
+/* (non-Javadoc)
* @see IOpenable#close
*/
public void close() throws JavaModelException {
if (getPerWorkingCopyInfo() != null) return; // a working copy must remain opened until it is discarded
super.close();
}
-/*
+/* (non-Javadoc)
* @see Openable#closing
*/
protected void closing(Object info) {
@@ -224,16 +231,31 @@
super.closing(info);
} // else the buffer of a working copy must remain open for the lifetime of the working copy
}
+
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor)
+ */
+public void codeComplete(int offset, CompletionRequestor requestor) throws JavaModelException {
+ codeComplete(offset, requestor, DefaultWorkingCopyOwner.PRIMARY);
+}
+
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner)
+ */
+public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
+ codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, offset, requestor, workingCopyOwner);
+}
+
/**
* @see ICodeAssist#codeComplete(int, ICompletionRequestor)
- * @deprecated
+ * @deprecated As it use deprecated requestor
*/
public void codeComplete(int offset, ICompletionRequestor requestor) throws JavaModelException {
codeComplete(offset, requestor, DefaultWorkingCopyOwner.PRIMARY);
}
/**
* @see ICodeAssist#codeComplete(int, ICompletionRequestor, WorkingCopyOwner)
- * @deprecated
+ * @deprecated As it use deprecated requestor
*/
public void codeComplete(int offset, ICompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
if (requestor == null) {
@@ -243,7 +265,7 @@
}
/**
* @see ICodeAssist#codeComplete(int, ICodeCompletionRequestor)
- * @deprecated - use codeComplete(int, ICompletionRequestor)
+ * @deprecated As it use deprecated requestor
*/
public void codeComplete(int offset, final ICodeCompletionRequestor requestor) throws JavaModelException {
@@ -301,46 +323,31 @@
}
/* (non-Javadoc)
- * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor)
- */
-public void codeComplete(int offset, CompletionRequestor requestor) throws JavaModelException {
- codeComplete(offset, requestor, DefaultWorkingCopyOwner.PRIMARY);
-}
-
-/* (non-Javadoc)
- * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner)
- */
-public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
- codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, offset, requestor, workingCopyOwner);
-}
-
-/**
* @see ICodeAssist#codeSelect(int, int)
*/
public IJavaElement[] codeSelect(int offset, int length) throws JavaModelException {
return codeSelect(offset, length, DefaultWorkingCopyOwner.PRIMARY);
}
-/**
+/* (non-Javadoc)
* @see ICodeAssist#codeSelect(int, int, WorkingCopyOwner)
*/
public IJavaElement[] codeSelect(int offset, int length, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
return super.codeSelect(this, offset, length, workingCopyOwner);
}
-/**
+/* (non-Javadoc)
* @see IWorkingCopy#commit(boolean, IProgressMonitor)
- * @deprecated
*/
public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException {
commitWorkingCopy(force, monitor);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#commitWorkingCopy(boolean, IProgressMonitor)
*/
public void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException {
CommitWorkingCopyOperation op= new CommitWorkingCopyOperation(this, force);
op.runOperation(monitor);
}
-/**
+/* (non-Javadoc)
* @see ISourceManipulation#copy(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
*/
public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
@@ -355,22 +362,21 @@
}
getJavaModel().copy(elements, containers, null, renamings, force, monitor);
}
-/**
- * Returns a new element info for this element.
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.Openable#createElementInfo()
*/
protected Object createElementInfo() {
return new CompilationUnitElementInfo();
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#createImport(String, IJavaElement, IProgressMonitor)
*/
public IImportDeclaration createImport(String importName, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException {
return createImport(importName, sibling, Flags.AccDefault, monitor);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#createImport(String, IJavaElement, int, IProgressMonitor)
- * @since 3.0
*/
public IImportDeclaration createImport(String importName, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException {
CreateImportOperation op = new CreateImportOperation(importName, this, flags);
@@ -381,7 +387,7 @@
return getImport(importName);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#createPackageDeclaration(String, IProgressMonitor)
*/
public IPackageDeclaration createPackageDeclaration(String pkg, IProgressMonitor monitor) throws JavaModelException {
@@ -390,7 +396,7 @@
op.runOperation(monitor);
return getPackageDeclaration(pkg);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#createType(String, IJavaElement, boolean, IProgressMonitor)
*/
public IType createType(String content, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
@@ -413,16 +419,15 @@
op.runOperation(monitor);
return (IType) op.getResultElements()[0];
}
-/**
+/* (non-Javadoc)
* @see ISourceManipulation#delete(boolean, IProgressMonitor)
*/
public void delete(boolean force, IProgressMonitor monitor) throws JavaModelException {
IJavaElement[] elements= new IJavaElement[] {this};
getJavaModel().delete(elements, force, monitor);
}
-/**
+/* (non-Javadoc)
* @see IWorkingCopy#destroy()
- * @deprecated
*/
public void destroy() {
try {
@@ -432,7 +437,7 @@
e.printStackTrace();
}
}
-/*
+/* (non-Javadoc)
* @see ICompilationUnit#discardWorkingCopy
*/
public void discardWorkingCopy() throws JavaModelException {
@@ -440,7 +445,7 @@
DiscardWorkingCopyOperation op = new DiscardWorkingCopyOperation(this);
op.runOperation(null);
}
-/**
+/* (non-Javadoc)
* Returns true if this handle represents the same Java element
* as the given handle.
*
@@ -451,6 +456,9 @@
CompilationUnit other = (CompilationUnit)obj;
return this.owner.equals(other.owner) && super.equals(obj);
}
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.Openable#exists()
+ */
public boolean exists() {
// working copy always exists in the model until it is gotten rid of (even if not on classpath)
if (getPerWorkingCopyInfo() != null) return true;
@@ -458,7 +466,7 @@
// if not a working copy, it exists only if it is a primary compilation unit
return isPrimary() && validateCompilationUnit(getResource()).isOK();
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#findElements(IJavaElement)
*/
public IJavaElement[] findElements(IJavaElement element) {
@@ -514,7 +522,7 @@
return null;
}
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#findPrimaryType()
*/
public IType findPrimaryType() {
@@ -528,7 +536,7 @@
/**
* @see IWorkingCopy#findSharedWorkingCopy(IBufferFactory)
- * @deprecated
+ * @deprecated As it use a deprecated interface
*/
public IJavaElement findSharedWorkingCopy(IBufferFactory factory) {
@@ -538,7 +546,7 @@
return findWorkingCopy(BufferFactoryWrapper.create(factory));
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#findWorkingCopy(WorkingCopyOwner)
*/
public ICompilationUnit findWorkingCopy(WorkingCopyOwner workingCopyOwner) {
@@ -555,7 +563,7 @@
}
}
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getAllTypes()
*/
public IType[] getAllTypes() throws JavaModelException {
@@ -579,13 +587,13 @@
allTypes.toArray(arrayOfAllTypes);
return arrayOfAllTypes;
}
-/**
- * @see IMember#getCompilationUnit()
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.JavaElement#getCompilationUnit()
*/
public ICompilationUnit getCompilationUnit() {
return this;
}
-/**
+/* (non-Javadoc)
* @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
*/
public char[] getContents() {
@@ -604,11 +612,11 @@
return CharOperation.NO_CHAR;
return contents;
}
-/**
+/* (non-Javadoc)
* A compilation unit has a corresponding resource unless it is contained
* in a jar.
- *
- * @see IJavaElement#getCorrespondingResource()
+ *
+ * @see org.eclipse.jdt.internal.core.Openable#getCorrespondingResource()
*/
public IResource getCorrespondingResource() throws JavaModelException {
PackageFragmentRoot root = getPackageFragmentRoot();
@@ -618,8 +626,8 @@
return getUnderlyingResource();
}
}
-/**
- * @see ICompilationUnit#getElementAt(int)
+/* (non-Javadoc)
+ * @see IJavaFile#getElementAt(int)
*/
public IJavaElement getElementAt(int position) throws JavaModelException {
@@ -630,24 +638,27 @@
return e;
}
}
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.JavaElement#getElementName()
+ */
public String getElementName() {
return this.name;
}
-/**
- * @see IJavaElement
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.IJavaElement#getElementType()
*/
public int getElementType() {
return COMPILATION_UNIT;
}
-/**
+/* (non-Javadoc)
* @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
*/
public char[] getFileName(){
return getPath().toString().toCharArray();
}
-/*
- * @see JavaElement
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.JavaElement#getHandleFromMemento(java.lang.String, org.eclipse.jdt.internal.core.util.MementoTokenizer, org.eclipse.jdt.core.WorkingCopyOwner)
*/
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner) {
switch (token.charAt(0)) {
@@ -668,27 +679,26 @@
return null;
}
-/**
+/* (non-Javadoc)
* @see JavaElement#getHandleMementoDelimiter()
*/
protected char getHandleMementoDelimiter() {
return JavaElement.JEM_COMPILATIONUNIT;
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getImport(String)
*/
public IImportDeclaration getImport(String importName) {
return getImportContainer().getImport(importName);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getImportContainer()
*/
public IImportContainer getImportContainer() {
return new ImportContainer(this);
}
-
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getImports()
*/
public IImportDeclaration[] getImports() throws JavaModelException {
@@ -713,15 +723,20 @@
System.arraycopy(elements, 0, imports, 0, length);
return imports;
}
-/**
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.JavaElement#getJavaFile()
+ */
+public IJavaFile getJavaFile() {
+ return this;
+}
+/* (non-Javadoc)
* @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
*/
public char[] getMainTypeName(){
return Util.getNameWithoutJavaLikeExtension(getElementName()).toCharArray();
}
-/**
+/* (non-Javadoc)
* @see IWorkingCopy#getOriginal(IJavaElement)
- * @deprecated
*/
public IJavaElement getOriginal(IJavaElement workingCopyElement) {
// backward compatibility
@@ -733,9 +748,8 @@
return workingCopyElement.getPrimaryElement();
}
-/**
+/* (non-Javadoc)
* @see IWorkingCopy#getOriginalElement()
- * @deprecated
*/
public IJavaElement getOriginalElement() {
// backward compatibility
@@ -749,13 +763,13 @@
public WorkingCopyOwner getOwner() {
return isPrimary() || !isWorkingCopy() ? null : this.owner;
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getPackageDeclaration(String)
*/
public IPackageDeclaration getPackageDeclaration(String pkg) {
return new PackageDeclaration(this, pkg);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getPackageDeclarations()
*/
public IPackageDeclaration[] getPackageDeclarations() throws JavaModelException {
@@ -764,7 +778,7 @@
list.toArray(array);
return array;
}
-/**
+/* (non-Javadoc)
* @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getPackageName()
*/
public char[][] getPackageName() {
@@ -773,7 +787,7 @@
return Util.toCharArrays(packageFragment.names);
}
-/**
+/* (non-Javadoc)
* @see IJavaElement#getPath()
*/
public IPath getPath() {
@@ -792,20 +806,20 @@
public JavaModelManager.PerWorkingCopyInfo getPerWorkingCopyInfo() {
return JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(this, false/*don't create*/, false/*don't record usage*/, null/*no problem requestor needed*/);
}
-/*
+/* (non-Javadoc)
* @see ICompilationUnit#getPrimary()
*/
public ICompilationUnit getPrimary() {
return (ICompilationUnit)getPrimaryElement(true);
}
-/*
+/* (non-Javadoc)
* @see JavaElement#getPrimaryElement(boolean)
*/
public IJavaElement getPrimaryElement(boolean checkOwner) {
if (checkOwner && isPrimary()) return this;
return new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
}
-/**
+/* (non-Javadoc)
* @see IJavaElement#getResource()
*/
public IResource getResource() {
@@ -818,6 +832,17 @@
}
}
/**
+ * @see IWorkingCopy#getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
+ * @deprecated As it use deprecated interface
+ */
+public IJavaElement getSharedWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
+
+ // if factory is null, default factory must be used
+ if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
+
+ return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestor, pm);
+}
+/* (non-Javadoc)
* @see ISourceReference#getSource()
*/
public String getSource() throws JavaModelException {
@@ -825,19 +850,19 @@
if (buffer == null) return ""; //$NON-NLS-1$
return buffer.getContents();
}
-/**
+/* (non-Javadoc)
* @see ISourceReference#getSourceRange()
*/
public ISourceRange getSourceRange() throws JavaModelException {
return ((CompilationUnitElementInfo) getElementInfo()).getSourceRange();
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getType(String)
*/
public IType getType(String typeName) {
return new SourceType(this, typeName);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getTypes()
*/
public IType[] getTypes() throws JavaModelException {
@@ -846,32 +871,20 @@
list.toArray(array);
return array;
}
-/**
- * @see IJavaElement
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.Openable#getUnderlyingResource()
*/
public IResource getUnderlyingResource() throws JavaModelException {
if (isWorkingCopy() && !isPrimary()) return null;
return super.getUnderlyingResource();
}
-/**
- * @see IWorkingCopy#getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
- * @deprecated
- */
-public IJavaElement getSharedWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
-
- // if factory is null, default factory must be used
- if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
-
- return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestor, pm);
-}
-/**
+/* (non-Javadoc)
* @see IWorkingCopy#getWorkingCopy()
- * @deprecated
*/
public IJavaElement getWorkingCopy() throws JavaModelException {
return getWorkingCopy(null);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getWorkingCopy(IProgressMonitor)
*/
public ICompilationUnit getWorkingCopy(IProgressMonitor monitor) throws JavaModelException {
@@ -879,12 +892,12 @@
}
/**
* @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
- * @deprecated
+ * @deprecated As it use a deprecated interface
*/
public IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestor, monitor);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
*/
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
@@ -902,13 +915,19 @@
op.runOperation(monitor);
return workingCopy;
}
-/**
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.IJavaFile#getWorkingCopy(org.eclipse.jdt.core.WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
+ */
+public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException {
+ return getWorkingCopy(workingCopyOwner, workingCopyOwner.getProblemRequestor(), monitor);
+}
+/* (non-Javadoc)
* @see Openable#hasBuffer()
*/
protected boolean hasBuffer() {
return true;
}
-/*
+/* (non-Javadoc)
* @see ICompilationUnit#hasResourceChanged()
*/
public boolean hasResourceChanged() {
@@ -922,50 +941,33 @@
if (resource == null) return false;
return ((CompilationUnitElementInfo)info).timestamp != resource.getModificationStamp();
}
-/**
+/* (non-Javadoc)
* @see IWorkingCopy#isBasedOn(IResource)
- * @deprecated
*/
public boolean isBasedOn(IResource resource) {
if (!isWorkingCopy()) return false;
if (!getResource().equals(resource)) return false;
return !hasResourceChanged();
}
-/**
+/* (non-Javadoc)
* @see IOpenable#isConsistent()
*/
public boolean isConsistent() {
return !JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().contains(this);
}
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.ICompilationUnit#isPrimary()
+ */
public boolean isPrimary() {
return this.owner == DefaultWorkingCopyOwner.PRIMARY;
}
-/**
+/* (non-Javadoc)
* @see Openable#isSourceElement()
*/
protected boolean isSourceElement() {
return true;
}
-protected IStatus validateCompilationUnit(IResource resource) {
- IPackageFragmentRoot root = getPackageFragmentRoot();
- // root never null as validation is not done for working copies
- try {
- if (root.getKind() != IPackageFragmentRoot.K_SOURCE)
- return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root);
- } catch (JavaModelException e) {
- return e.getJavaModelStatus();
- }
- if (resource != null) {
- char[][] inclusionPatterns = ((PackageFragmentRoot)root).fullInclusionPatternChars();
- char[][] exclusionPatterns = ((PackageFragmentRoot)root).fullExclusionPatternChars();
- if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns))
- return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this);
- if (!resource.isAccessible())
- return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
- }
- return JavaConventions.validateCompilationUnitName(getElementName());
-}
-/*
+/* (non-Javadoc)
* @see ICompilationUnit#isWorkingCopy()
*/
public boolean isWorkingCopy() {
@@ -973,12 +975,6 @@
// delta, clients can still check that element was a working copy before being discarded.
return !isPrimary() || getPerWorkingCopyInfo() != null;
}
-/**
- * @see IOpenable#makeConsistent(IProgressMonitor)
- */
-public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
- makeConsistent(NO_AST, false/*don't resolve bindings*/, false /* don't perform statements recovery */, null/*don't collect problems but report them*/, monitor);
-}
public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(int astLevel, boolean resolveBindings, boolean statementsRecovery, HashMap problems, IProgressMonitor monitor) throws JavaModelException {
if (isConsistent()) return null;
@@ -999,7 +995,13 @@
return null;
}
}
-/**
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.Openable#makeConsistent(org.eclipse.core.runtime.IProgressMonitor)
+ */
+public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
+ makeConsistent(NO_AST, false/*don't resolve bindings*/, false /* don't perform statements recovery */, null/*don't collect problems but report them*/, monitor);
+}
+/* (non-Javadoc)
* @see ISourceManipulation#move(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
*/
public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
@@ -1016,7 +1018,7 @@
getJavaModel().move(elements, containers, null, renamings, force, monitor);
}
-/**
+/* (non-Javadoc)
* @see Openable#openBuffer(IProgressMonitor, Object)
*/
protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException {
@@ -1070,30 +1072,31 @@
}
return buffer;
}
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.Openable#openParent(java.lang.Object, java.util.HashMap, org.eclipse.core.runtime.IProgressMonitor)
+ */
protected void openParent(Object childInfo, HashMap newElements, IProgressMonitor pm) throws JavaModelException {
if (!isWorkingCopy())
super.openParent(childInfo, newElements, pm);
// don't open parent for a working copy to speed up the first becomeWorkingCopy
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89411)
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#reconcile()
- * @deprecated
*/
public IMarker[] reconcile() throws JavaModelException {
reconcile(NO_AST, false/*don't force problem detection*/, false, null/*use primary owner*/, null/*no progress monitor*/);
return null;
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
*/
public void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws JavaModelException {
reconcile(NO_AST, forceProblemDetection, false, null/*use primary owner*/, monitor);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
- * @since 3.0
*/
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
int astLevel,
@@ -1104,9 +1107,8 @@
return reconcile(astLevel, forceProblemDetection, false, workingCopyOwner, monitor);
}
-/**
+/* (non-Javadoc)
* @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
- * @since 3.0
*/
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(
int astLevel,
@@ -1139,7 +1141,7 @@
return op.ast;
}
-/**
+/* (non-Javadoc)
* @see ISourceManipulation#rename(String, boolean, IProgressMonitor)
*/
public void rename(String newName, boolean force, IProgressMonitor monitor) throws JavaModelException {
@@ -1151,8 +1153,8 @@
String[] renamings= new String[] {newName};
getJavaModel().rename(elements, dests, renamings, force, monitor);
}
-/*
- * @see ICompilationUnit
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.ICompilationUnit#restore()
*/
public void restore() throws JavaModelException {
@@ -1165,8 +1167,8 @@
updateTimeStamp(original);
makeConsistent(null);
}
-/**
- * @see IOpenable
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.Openable#save(org.eclipse.core.runtime.IProgressMonitor, boolean)
*/
public void save(IProgressMonitor pm, boolean force) throws JavaModelException {
if (isWorkingCopy()) {
@@ -1178,8 +1180,8 @@
super.save(pm, force);
}
}
-/**
- * Debugging purposes
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.JavaElement#toStringInfo(int, java.lang.StringBuffer, java.lang.Object, boolean)
*/
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) {
if (!isPrimary()) {
@@ -1211,5 +1213,24 @@
}
((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
}
+protected IStatus validateCompilationUnit(IResource resource) {
+ IPackageFragmentRoot root = getPackageFragmentRoot();
+ // root never null as validation is not done for working copies
+ try {
+ if (root.getKind() != IPackageFragmentRoot.K_SOURCE)
+ return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root);
+ } catch (JavaModelException e) {
+ return e.getJavaModelStatus();
+ }
+ if (resource != null) {
+ char[][] inclusionPatterns = ((PackageFragmentRoot)root).fullInclusionPatternChars();
+ char[][] exclusionPatterns = ((PackageFragmentRoot)root).fullExclusionPatternChars();
+ if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns))
+ return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this);
+ if (!resource.isAccessible())
+ return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
+ }
+ return JavaConventions.validateCompilationUnitName(getElementName());
+}
}
Index: model/org/eclipse/jdt/internal/core/ClassFile.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java,v
retrieving revision 1.127
diff -u -r1.127 ClassFile.java
--- model/org/eclipse/jdt/internal/core/ClassFile.java 23 Jun 2006 11:16:24 -0000 1.127
+++ model/org/eclipse/jdt/internal/core/ClassFile.java 19 Oct 2006 14:51:35 -0000
@@ -239,6 +239,9 @@
}
return elt;
}
+public IType findPrimaryType() {
+ return getType();
+}
public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException {
return this.getType().getAttachedJavadoc(monitor);
}
@@ -327,6 +330,12 @@
return this;
}
/**
+ * @see IMember
+ */
+public IJavaFile getJavaFile() {
+ return this;
+}
+/**
* A class file has a corresponding resource unless it is contained
* in a jar.
*
Index: model/org/eclipse/jdt/internal/core/Openable.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Openable.java,v
retrieving revision 1.111
diff -u -r1.111 Openable.java
--- model/org/eclipse/jdt/internal/core/Openable.java 29 Mar 2006 03:08:47 -0000 1.111
+++ model/org/eclipse/jdt/internal/core/Openable.java 19 Oct 2006 14:51:36 -0000
@@ -163,8 +163,8 @@
}
return requestor.getElements();
}
-/*
- * Returns a new element info for this element.
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.JavaElement#createElementInfo()
*/
protected Object createElementInfo() {
return new OpenableElementInfo();
Index: model/org/eclipse/jdt/internal/core/JavaElement.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java,v
retrieving revision 1.122
diff -u -r1.122 JavaElement.java
--- model/org/eclipse/jdt/internal/core/JavaElement.java 10 May 2006 17:05:15 -0000 1.122
+++ model/org/eclipse/jdt/internal/core/JavaElement.java 19 Oct 2006 14:51:35 -0000
@@ -212,14 +212,14 @@
}
return list;
}
- /**
- * @see IMember
+ /* (non-Javadoc)
+ * @see IMember#getClassFile()
*/
public IClassFile getClassFile() {
return null;
}
- /**
- * @see IMember
+ /* (non-Javadoc)
+ * @see IMember#getCompilationUnit()
*/
public ICompilationUnit getCompilationUnit() {
return null;
@@ -293,6 +293,12 @@
* contribution to a memento.
*/
protected abstract char getHandleMementoDelimiter();
+ /* (non-Javadoc)
+ * @see IMember#getJavaFile()
+ */
+ public IJavaFile getJavaFile() {
+ return null;
+ }
/**
* @see IJavaElement
*/
Index: dom/org/eclipse/jdt/core/dom/ASTParser.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java,v
retrieving revision 1.65
diff -u -r1.65 ASTParser.java
--- dom/org/eclipse/jdt/core/dom/ASTParser.java 23 Jun 2006 13:44:54 -0000 1.65
+++ dom/org/eclipse/jdt/core/dom/ASTParser.java 19 Oct 2006 14:51:33 -0000
@@ -17,6 +17,7 @@
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaFile;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
@@ -154,14 +155,9 @@
private char[] rawSource = null;
/**
- * Java mode compilation unit supplying the source.
+ * Java model class file or compilation unit supplying the source.
*/
- private ICompilationUnit compilationUnitSource = null;
-
- /**
- * Java model class file supplying the source.
- */
- private IClassFile classFileSource = null;
+ private IJavaFile javaFileSource = null;
/**
* Character-based offset into the source string where parsing is to
@@ -218,8 +214,7 @@
private void initializeDefaults() {
this.astKind = K_COMPILATION_UNIT;
this.rawSource = null;
- this.classFileSource = null;
- this.compilationUnitSource = null;
+ this.javaFileSource = null;
this.resolveBindings = false;
this.sourceLength = -1;
this.sourceOffset = 0;
@@ -452,9 +447,8 @@
*/
public void setSource(char[] source) {
this.rawSource = source;
- // clear the others
- this.compilationUnitSource = null;
- this.classFileSource = null;
+ // clear the other
+ this.javaFileSource = null;
}
/**
@@ -467,16 +461,7 @@
* is to be parsed, or 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 the source is a class file 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, or null
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: /cvsroot/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 19 Oct 2006 14:51:33 -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;
}
/**
@@ -940,7 +952,18 @@
* @since 3.1
*/
void setJavaElement(IJavaElement element) {
- this.element = element;
+ this.javaFile = (IJavaFile) element;
+ }
+
+ /**
+ * Sets 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 element.
+ *
+ * @param javaFile the Java file this compilation unit was created from
+ * @since 3.3
+ */
+ void setJavaFile(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,95 @@
+/*******************************************************************************
+ * 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 file (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 {
+
+/**
+ * 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();
+
+/**
+ * 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 the source of this Java file.
+ *
+ * @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;
+
+/**
+ * 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 Java file 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:
+ *
+ * - The first call to {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}
+ * creates a new working copy for this element
+ * - Subsequent calls increment an internal counter.
+ * - A call to {@link ICompilationUnit#discardWorkingCopy()} decrements the internal counter.
+ * - When this counter is 0, the working copy is discarded.
+ *
+ * So users of this method must discard exactly once the working copy.
+ *
+ * Note that the working copy owner will be used for the life time of the shared 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 Java file 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
+ * or null
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 Java file using the given owner to create
+ * the buffer, or this Java file if it is already a working copy
+ */
+ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
+
+}