*******************************************************************************/
package net.sourceforge.phpdt.core;
+import net.sourceforge.phpdt.internal.core.ImportContainer;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+
/**
* Represents an entire Java compilation unit (<code>.java</code> source file).
* <p>
* This interface is not intended to be implemented by clients.
* </p>
- */
-public interface ICompilationUnit extends IJavaElement, IParent, IOpenable {
+ */
+public interface ICompilationUnit extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation {
//extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation, ICodeAssist {
+
+ /**
+ * Constant indicating that a reconcile operation should not return an AST.
+ * @since 3.0
+ */
+ public static final int NO_AST = 0;
+
+ /**
+ * Changes this compilation unit handle into a working copy. A new <code>IBuffer</code> is
+ * created using this compilation unit handle's owner. Uses the primary owner is none was
+ * specified when this compilation unit handle was created.
+ * <p>
+ * When switching to working copy mode, problems are reported to given
+ * <code>IProblemRequestor</code>.
+ * </p>
+ * <p>
+ * Once in working copy mode, changes to this compilation unit or its children are done in memory.
+ * Only the new buffer is affected. Using <code>commitWorkingCopy(boolean, IProgressMonitor)</code>
+ * will bring the underlying resource in sync with this compilation unit.
+ * </p>
+ * <p>
+ * If this compilation unit was already in working copy mode, an internal counter is incremented and no
+ * other action is taken on this compilation unit. To bring this compilation unit back into the original mode
+ * (where it reflects the underlying resource), <code>discardWorkingCopy</code> must be call as many
+ * times as <code>becomeWorkingCopy</code>.
+ * </p>
+ *
+ * @param problemRequestor a requestor which will get notified of problems detected during
+ * reconciling as they are discovered. The requestor can be set to <code>null</code> indicating
+ * that the client is not interested in problems.
+ * @param monitor a progress monitor used to report progress while opening this compilation unit
+ * or <code>null</code> if no progress should be reported
+ * @throws JavaModelException if this compilation unit could not become a working copy.
+ * @see #discardWorkingCopy()
+ * @since 3.0
+ */
+ void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException;
+ /**
+ * Commits the contents of this working copy to its underlying resource.
+ *
+ * <p>It is possible that the contents of the original resource have changed
+ * since this working copy was created, in which case there is an update conflict.
+ * The value of the <code>force</code> parameter effects the resolution of
+ * such a conflict:<ul>
+ * <li> <code>true</code> - in this case the contents of this working copy are applied to
+ * the underlying resource even though this working copy was created before
+ * a subsequent change in the resource</li>
+ * <li> <code>false</code> - in this case a <code>JavaModelException</code> is thrown</li>
+ * </ul>
+ * <p>
+ * 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.
+ * </p>
+ * @param force a flag to handle the cases when the contents of the original resource have changed
+ * since this working copy was created
+ * @param monitor the given progress monitor
+ * @throws JavaModelException if this working copy could not commit. Reasons include:
+ * <ul>
+ * <li> A <code>CoreException</code> occurred while updating an underlying resource
+ * <li> This element is not a working copy (INVALID_ELEMENT_TYPES)
+ * <li> A update conflict (described above) (UPDATE_CONFLICT)
+ * </ul>
+ * @since 3.0
+ */
+ void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException;
+ /**
+ * Changes this compilation unit in working copy mode back to its original mode.
+ * <p>
+ * This has no effect if this compilation unit was not in working copy mode.
+ * </p>
+ * <p>
+ * If <code>becomeWorkingCopy</code> was called several times on this
+ * compilation unit, <code>discardWorkingCopy</code> must be called as
+ * many times before it switches back to the original mode.
+ * </p>
+ *
+ * @throws JavaModelException if this working copy could not return in its original mode.
+ * @see #becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
+ * @since 3.0
+ */
+ void discardWorkingCopy() throws JavaModelException;
/**
* Creates and returns an import declaration in this compilation unit
* with the given name.
* @exception JavaModelException if this element does not exist or if an
* exception occurs while accessing its corresponding resource
*/
-//IType[] getAllTypes() throws JavaModelException;
+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
* @exception JavaModelException if the compilation unit does not exist or if an
* exception occurs while accessing its corresponding resource
*/
-//IJavaElement getElementAt(int position) throws JavaModelException;
+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
* @return a handle onto the corresponding import container. The
* import contain may or may not exist.
*/
-//IImportContainer getImportContainer();
+ImportContainer getImportContainer();
/**
* Returns the import declarations in this compilation unit
* in the order in which they appear in the source. This is
*
* @param name the name of the package declaration as defined by JLS2 7.4. (For example, <code>"java.lang"</code>)
*/
-//IPackageDeclaration getPackageDeclaration(String name);
+IPackageDeclaration getPackageDeclaration(String name);
/**
* Returns the package declarations in this compilation unit
* in the order in which they appear in the source.
*/
//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.
+ * <p>
+ * Note that the returned primary compilation unit can be in working copy mode.
+ * </p>
+ *
+ * @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.
* @return a handle onto the corresponding type. The type may or may not exist.
* @see JavaConventions#validateCompilationUnitName(String name)
*/
-//IType getType(String name);
+IType getType(String name);
/**
* Returns the top-level types declared in this compilation unit
* in the order in which they appear in the source.
* @exception JavaModelException if this element does not exist or if an
* exception occurs while accessing its corresponding resource
*/
-//IType[] getTypes() throws JavaModelException;
+IType[] getTypes() throws JavaModelException;
}