83de070d921517eaa8d8561cc14ebdbedd8ec10b
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / IClasspathEntry.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 import org.eclipse.core.runtime.IPath;
14
15 /** 
16  * An entry on a Java project classpath identifying one or more package fragment
17  * roots. A classpath entry has a content kind (either source, 
18  * <code>K_SOURCE</code>, or binary, <code>K_BINARY</code>), which is inherited
19  * by each package fragment root and package fragment associated with the entry.
20  * <p>
21  * A classpath entry can refer to any of the following:<ul>
22  * 
23  *      <li>Source code in the current project. In this case, the entry identifies a
24  *              root folder in the current project containing package fragments and
25  *              <code>.java</code> source files. The root folder itself represents a default
26  *              package, subfolders represent package fragments, and <code>.java</code> files
27  *              represent compilation units. All compilation units will be compiled when
28  *              the project is built. The classpath entry must specify the
29  *              absolute path to the root folder. Entries of this kind are 
30  *              associated with the <code>CPE_SOURCE</code> constant.
31  *      Source classpath entries can carry patterns to exclude selected files.
32  *      Excluded <code>.java</code> source files do not appear as compilation
33  *      units and are not compiled when the project is built.
34  *  </li>
35  * 
36  *      <li>A binary library in the current project, in another project, or in the external
37  *              file system. In this case the entry identifies a JAR (or root folder) containing
38  *              package fragments and <code>.class</code> files.  The classpath entry
39  *              must specify the absolute path to the JAR (or root folder), and in case it refers
40  *              to an external JAR, then there is no associated resource in the workbench. Entries 
41  *              of this kind are associated with the <code>CPE_LIBRARY</code> constant.</li>
42  * 
43  *      <li>A required project. In this case the entry identifies another project in
44  *              the workspace. The required project is used as a binary library when compiling
45  *              (that is, the builder looks in the output location of the required project
46  *              for required <code>.class</code> files when building). When performing other
47  *              "development" operations - such as code assist, code resolve, type hierarchy
48  *              creation, etc. - the source code of the project is referred to. Thus, development
49  *              is performed against a required project's source code, and compilation is 
50  *              performed against a required project's last built state.  The
51  *              classpath entry must specify the absolute path to the
52  *              project. Entries of this kind are  associated with the <code>CPE_PROJECT</code>
53  *              constant. 
54  *              Note: referencing a required project with a classpath entry refers to the source 
55  *     code or associated <code>.class</code> files located in its output location. 
56  *     It will also automatically include any other libraries or projects that the required project's classpath 
57  *     refers to, iff the corresponding classpath entries are tagged as being exported 
58  *     (<code>IClasspathEntry#isExported</code>). 
59  *    Unless exporting some classpath entries, classpaths are not chained by default - 
60  *    each project must specify its own classpath in its entirety.</li>
61  * 
62  *  <li> A path beginning in a classpath variable defined globally to the workspace.
63  *              Entries of this kind are  associated with the <code>CPE_VARIABLE</code> constant.  
64  *      Classpath variables are created using <code>JavaCore#setClasspathVariable</code>,
65  *              and gets resolved, to either a project or library entry, using
66  *      <code>JavaCore#getResolvedClasspathVariable</code>.
67  *              It is also possible to register an automatic initializer (<code>ClasspathVariableInitializer</code>),
68  *      which will be invoked through the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
69  *      After resolution, a classpath variable entry may either correspond to a project or a library entry. </li>
70  * 
71  *  <li> A named classpath container identified by its container path.
72  *     A classpath container provides a way to indirectly reference a set of classpath entries through
73  *     a classpath entry of kind <code>CPE_CONTAINER</code>. Typically, a classpath container can
74  *     be used to describe a complex library composed of multiple JARs, projects or classpath variables,
75  *     considering also that containers can be mapped differently on each project. Several projects can
76  *     reference the same generic container path, but have each of them actually bound to a different
77  *     container object.
78  *     The container path is a formed by a first ID segment followed with extra segments, 
79  *     which can be used as additional hints for resolving this container reference. If no container was ever 
80  *     recorded for this container path onto this project (using <code>setClasspathContainer</code>, 
81  *      then a <code>ClasspathContainerInitializer</code> will be activated if any was registered for this 
82  *      container ID onto the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
83  *      A classpath container entry can be resolved explicitly using <code>JavaCore#getClasspathContainer</code>
84  *      and the resulting container entries can contain any non-container entry. In particular, it may contain variable
85  *     entries, which in turn needs to be resolved before being directly used. 
86  *      <br> Also note that the container resolution APIs include an IJavaProject argument, so as to allow the same
87  *      container path to be interpreted in different ways for different projects. </li>
88  * </ul>
89  * </p>
90  * The result of <code>IJavaProject#getResolvedClasspath</code> will have all entries of type
91  * <code>CPE_VARIABLE</code> and <code>CPE_CONTAINER</code> resolved to a set of 
92  * <code>CPE_SOURCE</code>, <code>CPE_LIBRARY</code> or <code>CPE_PROJECT</code>
93  * classpath entries.
94  * <p>
95  * Any classpath entry other than a source folder (kind <code>CPE_SOURCE</code>) can
96  * be marked as being exported. Exported entries are automatically contributed to
97  * dependent projects, along with the project's default output folder, which is
98  * implicitly exported, and any auxiliary output folders specified on source
99  * classpath entries. The project's output folder(s) are always listed first,
100  * followed by the any exported entries.
101  * <p>
102  * This interface is not intended to be implemented by clients.
103  * Classpath entries can be created via methods on <code>JavaCore</code>.
104  * </p>
105  *
106  * @see JavaCore#newLibraryEntry
107  * @see JavaCore#newProjectEntry
108  * @see JavaCore#newSourceEntry
109  * @see JavaCore#newVariableEntry
110  * @see JavaCore#newContainerEntry
111  * @see ClasspathVariableInitializer
112  * @see ClasspathContainerInitializer
113  */
114 public interface IClasspathEntry {
115
116         /**
117          * Entry kind constant describing a classpath entry identifying a
118          * library. A library is a folder or JAR containing package
119          * fragments consisting of pre-compiled binaries.
120          */
121         int CPE_LIBRARY = 1;
122
123         /**
124          * Entry kind constant describing a classpath entry identifying a
125          * required project.
126          */
127         int CPE_PROJECT = 2;
128
129         /**
130          * Entry kind constant describing a classpath entry identifying a
131          * folder containing package fragments with source code
132          * to be compiled.
133          */
134         int CPE_SOURCE = 3;
135
136         /**
137          * Entry kind constant describing a classpath entry defined using
138          * a path that begins with a classpath variable reference.
139          */
140         int CPE_VARIABLE = 4;
141
142         /**
143          * Entry kind constant describing a classpath entry representing
144          * a name classpath container.
145          * 
146          * @since 2.0
147          */
148         int CPE_CONTAINER = 5;
149
150         /**
151          * Returns the kind of files found in the package fragments identified by this
152          * classpath entry.
153          *
154          * @return <code>IPackageFragmentRoot.K_SOURCE</code> for files containing
155          *   source code, and <code>IPackageFragmentRoot.K_BINARY</code> for binary
156          *   class files.
157          *   There is no specified value for an entry denoting a variable (<code>CPE_VARIABLE</code>)
158          *   or a classpath container (<code>CPE_CONTAINER</code>).
159          */
160         int getContentKind();
161
162         /**
163          * Returns the kind of this classpath entry.
164          *
165          * @return one of:
166          * <ul>
167          * <li><code>CPE_SOURCE</code> - this entry describes a source root in
168                         its project
169          * <li><code>CPE_LIBRARY</code> - this entry describes a folder or JAR
170                         containing binaries
171          * <li><code>CPE_PROJECT</code> - this entry describes another project
172          *
173          * <li><code>CPE_VARIABLE</code> - this entry describes a project or library
174          *      indirectly via a classpath variable in the first segment of the path
175          * *
176          * <li><code>CPE_CONTAINER</code> - this entry describes set of entries
177          *      referenced indirectly via a classpath container
178          * </ul>
179          */
180         int getEntryKind();
181
182         /**
183          * Returns the set of patterns used to exclude resources associated with
184          * this source entry.
185          * <p>
186          * Exclusion patterns allow specified portions of the resource tree rooted
187          * at this source entry's path to be filtered out. If no exclusion patterns
188          * are specified, this source entry includes all relevent files. Each path
189          * specified must be a relative path, and will be interpreted relative
190          * to this source entry's path. File patterns are case-sensitive. A file
191          * matched by one or more of these patterns is excluded from the 
192          * corresponding package fragment root.
193          * </p>
194          * <p>
195          * Note that there is no need to supply a pattern to exclude ".class" files
196          * because a source entry filters these out automatically.
197          * </p>
198          * <p>
199          * The pattern mechanism is similar to Ant's. Each pattern is represented as
200          * a relative path. The path segments can be regular file or folder names or simple patterns
201          * involving standard wildcard characters.
202          * </p>
203          * <p>
204          * '*' matches 0 or more characters within a segment. So
205          * <code>*.java</code> matches <code>.java</code>, <code>a.java</code>
206          * and <code>Foo.java</code>, but not <code>Foo.properties</code>
207          * (does not end with <code>.java</code>).
208          * </p>
209          * <p>
210          * '?' matches 1 character within a segment. So <code>?.java</code> 
211          * matches <code>a.java</code>, <code>A.java</code>, 
212          * but not <code>.java</code> or <code>xyz.java</code> (neither have
213          * just one character before <code>.java</code>).
214          * </p>
215          * <p>
216          * Combinations of *'s and ?'s are allowed.
217          * </p>
218          * <p>
219          * The special pattern '**' matches zero or more segments. A path 
220          * like <code>tests/</code> that ends in a trailing separator is interpreted
221          * as <code>tests/&#42;&#42;</code>, and would match all files under the 
222          * the folder named <code>tests</code>.
223          * </p>
224          * <p>
225          * Examples:
226          * <ul>
227          * <li>
228          * <code>tests/&#42;&#42;</code> (or simply <code>tests/</code>) 
229          * matches all files under a root folder
230          * named <code>tests</code>. This includes <code>tests/Foo.java</code>
231          * and <code>tests/com/example/Foo.java</code>, but not 
232          * <code>com/example/tests/Foo.java</code> (not under a root folder named
233          * <code>tests</code>).
234          * </li>
235          * <li>
236          * <code>tests/&#42;</code> matches all files directly below a root 
237          * folder named <code>tests</code>. This includes <code>tests/Foo.java</code>
238          * and <code>tests/FooHelp.java</code>
239          * but not <code>tests/com/example/Foo.java</code> (not directly under
240          * a folder named <code>tests</code>) or 
241          * <code>com/Foo.java</code> (not under a folder named <code>tests</code>).
242          * </li>
243          * <li>
244          * <code>&#42;&#42;/tests/&#42;&#42;</code> matches all files under any
245          * folder named <code>tests</code>. This includes <code>tests/Foo.java</code>,
246          * <code>com/examples/tests/Foo.java</code>, and 
247          * <code>com/examples/tests/unit/Foo.java</code>, but not 
248          * <code>com/example/Foo.java</code> (not under a folder named
249          * <code>tests</code>).
250          * </li>
251          * </ul>
252          * </p>
253          * 
254          * @return the possibly empty list of resource exclusion patterns 
255          *   associated with this source entry, and <code>null</code> for other
256          *   kinds of classpath entries
257          * @since 2.1
258          */
259         IPath[] getExclusionPatterns();
260         
261         /**
262          * Returns the full path to the specific location where the builder writes 
263          * <code>.class</code> files generated for this source entry 
264          * (entry kind <code>CPE_SOURCE</code>).
265          * <p>
266          * Source entries can optionally be associated with a specific output location.
267          * If none is provided, the source entry will be implicitly associated with its project
268          * default output location (see <code>IJavaProject#getOutputLocation</code>).
269          * </p><p>
270          * NOTE: A specific output location cannot coincidate with another source/library entry.
271          * </p>
272          * 
273          * @return the full path to the specific location where the builder writes 
274          * <code>.class</code> files for this source entry, or <code>null</code>
275          * if using default output folder
276          * @since 2.1
277          */
278         IPath getOutputLocation();
279         
280         /**
281          * Returns the path of this classpath entry.
282          *
283          * The meaning of the path of a classpath entry depends on its entry kind:<ul>
284          *      <li>Source code in the current project (<code>CPE_SOURCE</code>) -  
285          *      The path associated with this entry is the absolute path to the root folder. </li>
286          *      <li>A binary library in the current project (<code>CPE_LIBRARY</code>) - the path
287          *              associated with this entry is the absolute path to the JAR (or root folder), and 
288          *              in case it refers to an external JAR, then there is no associated resource in 
289          *              the workbench.
290          *      <li>A required project (<code>CPE_PROJECT</code>) - the path of the entry denotes the
291          *              path to the corresponding project resource.</li>
292          *  <li>A variable entry (<code>CPE_VARIABLE</code>) - the first segment of the path 
293          *      is the name of a classpath variable. If this classpath variable
294          *              is bound to the path <it>P</it>, the path of the corresponding classpath entry
295          *              is computed by appending to <it>P</it> the segments of the returned
296          *              path without the variable.</li>
297          *  <li> A container entry (<code>CPE_CONTAINER</code>) - the path of the entry
298          *      is the name of the classpath container, which can be bound indirectly to a set of classpath 
299          *      entries after resolution. The containerPath is a formed by a first ID segment followed with 
300          *     extra segments that can be used as additional hints for resolving this container 
301          *      reference (also see <code>IClasspathContainer</code>).
302          * </li>
303          * </ul>
304          *
305          * @return the path of this classpath entry
306          */
307         IPath getPath();
308
309         /**
310          * Returns the path to the source archive or folder associated with this
311          * classpath entry, or <code>null</code> if this classpath entry has no
312          * source attachment.
313          * <p>
314          * Only library and variable classpath entries may have source attachments.
315          * For library classpath entries, the result path (if present) locates a source
316          * archive or folder. This archive or folder can be located in a project of the 
317          * workspace or outside thr workspace. For variable classpath entries, the 
318          * result path (if present) has an analogous form and meaning as the 
319          * variable path, namely the first segment is the name of a classpath variable.
320          * </p>
321          *
322          * @return the path to the source archive or folder, or <code>null</code> if none
323          */
324         IPath getSourceAttachmentPath();
325
326         /**
327          * Returns the path within the source archive or folder where package fragments
328          * are located. An empty path indicates that packages are located at
329          * the root of the source archive or folder. Returns a non-<code>null</code> value
330          * if and only if <code>getSourceAttachmentPath</code> returns 
331          * a non-<code>null</code> value.
332          *
333          * @return the path within the source archive or folder, or <code>null</code> if
334          *    not applicable
335          */
336         IPath getSourceAttachmentRootPath();
337         
338         /**
339          * Returns whether this entry is exported to dependent projects.
340          * Always returns <code>false</code> for source entries (kind
341          * <code>CPE_SOURCE</code>), which cannot be exported.
342          * 
343          * @return <code>true</code> if exported, and <code>false</code> otherwise
344          * @since 2.0
345          */
346         boolean isExported();
347         
348         /**
349          * This is a helper method, which returns the resolved classpath entry denoted 
350          * by an entry (if it is a variable entry). It is obtained by resolving the variable 
351          * reference in the first segment. Returns <node>null</code> if unable to resolve using 
352          * the following algorithm:
353          * <ul>
354          * <li> if variable segment cannot be resolved, returns <code>null</code></li>
355          * <li> finds a project, JAR or binary folder in the workspace at the resolved path location</li>
356          * <li> if none finds an external JAR file or folder outside the workspace at the resolved path location </li>
357          * <li> if none returns <code>null</code></li>
358          * </ul>
359          * <p>
360          * Variable source attachment is also resolved and recorded in the resulting classpath entry.
361          * <p>
362          * @return the resolved library or project classpath entry, or <code>null</code>
363          *   if the given path could not be resolved to a classpath entry
364          *      <p> 
365          * Note that this deprecated API doesn't handle CPE_CONTAINER entries.
366          * 
367          * @deprecated - use JavaCore.getResolvedClasspathEntry(...)
368          */
369         IClasspathEntry getResolvedEntry();     
370 }