Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / IOpenable.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core;
12
13
14 /**
15  * Common protocol for Java elements that must be opened before they can be 
16  * navigated or modified. Opening a textual element (such as a compilation unit)
17  * involves opening a buffer on its contents.  While open, any changes to the buffer
18  * can be reflected in the element's structure; 
19  * see <code>isConsistent</code> and <code>makeConsistent(IProgressMonitor)</code>.
20  * <p>
21  * To reduce complexity in clients, elements are automatically opened
22  * by the Java model as element properties are accessed. The Java model maintains
23  * an LRU cache of open elements, and automatically closes elements as they
24  * are swapped out of the cache to make room for other elements. Elements with
25  * unsaved changes are never removed from the cache, and thus, if the client
26  * maintains many open elements with unsaved
27  * changes, the LRU cache can grow in size (in this case the cache is not
28  * bounded). However, as elements are saved, the cache will shrink back to its
29  * original bounded size.
30  * </p>
31  * <p>
32  * To open an element, all openable parent elements must be open.
33  * The Java model automatically opens parent elements, as it automatically opens elements.
34  * Opening an element may provide access to direct children and other descendants,
35  * but does not automatically open any descendents which are themselves <code>IOpenable</code>.
36  * For example, opening a compilation unit provides access to all its constituent elements,
37  * but opening a package fragment does not open all compilation units in the package fragment.
38  * </p>
39  * <p>
40  * This interface is not intended to be implemented by clients.
41  * </p>
42  */
43 public interface IOpenable {
44
45 /**
46  * Closes this element and its buffer (if any).
47  * Closing an element which is not open has no effect.
48  *
49  * <p>Note: although <code>close</code> is exposed in the API, clients are
50  * not expected to open and close elements - the Java model does this automatically
51  * as elements are accessed.
52  *
53  * @exception JavaModelException if an error occurs closing this element
54  */
55 //public void close() throws JavaModelException;
56 /**
57  * Returns the buffer opened for this element, or <code>null</code>
58  * if this element does not have a buffer.
59  *
60  * @exception JavaModelException if this element does not exist or if an
61  *              exception occurs while accessing its corresponding resource.
62  * @return the buffer opened for this element, or <code>null</code>
63  * if this element does not have a buffer
64  */
65 public IBuffer getBuffer() throws JavaModelException;
66 /**
67  * Returns <code>true</code> if this element is open and:
68  * <ul>
69  * <li>its buffer has unsaved changes, or
70  * <li>one of its descendants has unsaved changes, or
71  * <li>a working copy has been created on one of this
72  * element's children and has not yet destroyed
73  * </ul>
74  *
75  * @exception JavaModelException if this element does not exist or if an
76  *              exception occurs while accessing its corresponding resource.
77  * @return <code>true</code> if this element is open and:
78  * <ul>
79  * <li>its buffer has unsaved changes, or
80  * <li>one of its descendants has unsaved changes, or
81  * <li>a working copy has been created on one of this
82  * element's children and has not yet destroyed
83  * </ul>
84  */
85 //boolean hasUnsavedChanges() throws JavaModelException;
86 /**
87  * Returns whether the element is consistent with its underlying resource or buffer.
88  * The element is consistent when opened, and is consistent if the underlying resource
89  * or buffer has not been modified since it was last consistent.
90  *
91  * <p>NOTE: Child consistency is not considered. For example, a package fragment
92  * responds <code>true</code> when it knows about all of its
93  * compilation units present in its underlying folder. However, one or more of
94  * the compilation units could be inconsistent.
95  *
96  * @exception JavaModelException if this element does not exist or if an
97  *              exception occurs while accessing its corresponding resource.
98  * @return true if the element is consistent with its underlying resource or buffer, false otherwise.
99  * @see IOpenable#makeConsistent
100  */
101 boolean isConsistent() throws JavaModelException;
102 /**
103  * Returns whether this openable is open. This is a handle-only method.
104  * @return true if this openable is open, false otherwise
105  */
106 boolean isOpen();
107 /**
108  * Makes this element consistent with its underlying resource or buffer 
109  * by updating the element's structure and properties as necessary.
110  *
111  * @param progress the given progress monitor
112  * @exception JavaModelException if the element is unable to access the contents
113  *              of its underlying resource. Reasons include:
114  * <ul>
115  *  <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
116  * </ul>
117  * @see IOpenable#isConsistent
118  */
119 //void makeConsistent(IProgressMonitor progress) throws JavaModelException;
120 /**
121  * Opens this element and all parent elements that are not already open.
122  * For compilation units, a buffer is opened on the contents of the underlying resource.
123  *
124  * <p>Note: although <code>open</code> is exposed in the API, clients are
125  * not expected to open and close elements - the Java model does this automatically
126  * as elements are accessed.
127  *
128  * @param progress the given progress monitor
129  * @exception JavaModelException if an error occurs accessing the contents
130  *              of its underlying resource. Reasons include:
131  * <ul>
132  *  <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
133  * </ul>
134  */
135 //public void open(IProgressMonitor progress) throws JavaModelException;
136 /**
137  * Saves any changes in this element's buffer to its underlying resource
138  * via a workspace resource operation. This has no effect if the element has no underlying
139  * buffer, or if there are no unsaved changed in the buffer.
140  * <p>
141  * The <code>force</code> parameter controls how this method deals with
142  * cases where the workbench is not completely in sync with the local file system.
143  * If <code>false</code> is specified, this method will only attempt
144  * to overwrite a corresponding file in the local file system provided
145  * it is in sync with the workbench. This option ensures there is no 
146  * unintended data loss; it is the recommended setting.
147  * However, if <code>true</code> is specified, an attempt will be made
148  * to write a corresponding file in the local file system, 
149  * overwriting any existing one if need be.
150  * In either case, if this method succeeds, the resource will be marked 
151  * as being local (even if it wasn't before).
152  * <p>
153  * As a result of this operation, the element is consistent with its underlying 
154  * resource or buffer. 
155  *
156  * @param progress the given progress monitor
157  * @param force it controls how this method deals with
158  * cases where the workbench is not completely in sync with the local file system
159  * @exception JavaModelException if an error occurs accessing the contents
160  *              of its underlying resource. Reasons include:
161  * <ul>
162  *  <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
163  *  <li>This Java element is read-only (READ_ONLY)</li>
164  * </ul>
165  */
166 //public void save(IProgressMonitor progress, boolean force) throws JavaModelException;
167 }