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
9 * IBM Corporation - initial API and implementation
10 * IBM Corporation - added getOption(String, boolean), getOptions(boolean) and setOptions(Map)
11 * IBM Corporation - deprecated getPackageFragmentRoots(IClasspathEntry) and
12 * added findPackageFragmentRoots(IClasspathEntry)
13 * IBM Corporation - added isOnClasspath(IResource)
14 *******************************************************************************/
15 package net.sourceforge.phpdt.core;
17 import org.eclipse.core.resources.IProject;
21 * A Java project represents a view of a project resource in terms of Java
22 * elements such as package fragments, types, methods and fields.
23 * A project may contain several package roots, which contain package fragments.
24 * A package root corresponds to an underlying folder or JAR.
26 * Each Java project has a classpath, defining which folders contain source code and
27 * where required libraries are located. Each Java project also has an output location,
28 * defining where the builder writes <code>.class</code> files. A project that
29 * references packages in another project can access the packages by including
30 * the required project in a classpath entry. The Java model will present the
31 * source elements in the required project; when building, the compiler will use
32 * the corresponding generated class files from the required project's output
33 * location(s)). The classpath format is a sequence of classpath entries
34 * describing the location and contents of package fragment roots.
36 * Java project elements need to be opened before they can be navigated or manipulated.
37 * The children of a Java project are the package fragment roots that are
38 * defined by the classpath and contained in this project (in other words, it
39 * does not include package fragment roots for other projects).
42 * This interface is not intended to be implemented by clients. An instance
43 * of one of these handles can be created via
44 * <code>JavaCore.create(project)</code>.
47 * @see JavaCore#create(org.eclipse.core.resources.IProject)
48 * @see IClasspathEntry
50 public interface IJavaProject extends IParent, IJavaElement, IOpenable {
53 * Returns the <code>IJavaElement</code> corresponding to the given
54 * classpath-relative path, or <code>null</code> if no such
55 * <code>IJavaElement</code> is found. The result is one of an
56 * <code>ICompilationUnit</code>, <code>IClassFile</code>, or
57 * <code>IPackageFragment</code>.
59 * When looking for a package fragment, there might be several potential
60 * matches; only one of them is returned.
62 * <p>For example, the path "java/lang/Object.java", would result in the
63 * <code>ICompilationUnit</code> or <code>IClassFile</code> corresponding to
64 * "java.lang.Object". The path "java/lang" would result in the
65 * <code>IPackageFragment</code> for "java.lang".
66 * @param path the given classpath-relative path
67 * @exception JavaModelException if the given path is <code>null</code>
69 * @return the <code>IJavaElement</code> corresponding to the given
70 * classpath-relative path, or <code>null</code> if no such
71 * <code>IJavaElement</code> is found
73 // IJavaElement findElement(IPath path) throws JavaModelException;
76 * Returns the first existing package fragment on this project's classpath
77 * whose path matches the given (absolute) path, or <code>null</code> if none
80 * - internal to the workbench: "/Project/src"
81 * - external to the workbench: "c:/jdk/classes.zip/java/lang"
82 * @param path the given absolute path
83 * @exception JavaModelException if this element does not exist or if an
84 * exception occurs while accessing its corresponding resource
85 * @return the first existing package fragment on this project's classpath
86 * whose path matches the given (absolute) path, or <code>null</code> if none
89 // IPackageFragment findPackageFragment(IPath path) throws JavaModelException;
92 * Returns the existing package fragment root on this project's classpath
93 * whose path matches the given (absolute) path, or <code>null</code> if
96 * - internal to the workbench: "/Compiler/src"
97 * - external to the workbench: "c:/jdk/classes.zip"
98 * @param path the given absolute path
99 * @exception JavaModelException if this element does not exist or if an
100 * exception occurs while accessing its corresponding resource
101 * @return the existing package fragment root on this project's classpath
102 * whose path matches the given (absolute) path, or <code>null</code> if
105 // IPackageFragmentRoot findPackageFragmentRoot(IPath path)
106 // throws JavaModelException;
108 * Returns the existing package fragment roots identified by the given entry.
109 * Note that a classpath entry that refers to another project may
110 * have more than one root (if that project has more than on root
111 * containing source), and classpath entries within the current
112 * project identify a single root.
114 * If the classpath entry denotes a variable, it will be resolved and return
115 * the roots of the target entry (empty if not resolvable).
117 * If the classpath entry denotes a container, it will be resolved and return
118 * the roots corresponding to the set of container entries (empty if not resolvable).
120 * @param entry the given entry
121 * @return the existing package fragment roots identified by the given entry
122 * @see IClasspathContainer
125 // IPackageFragmentRoot[] findPackageFragmentRoots(IClasspathEntry entry);
127 * Returns the first type found following this project's classpath
128 * with the given fully qualified name or <code>null</code> if none is found.
129 * The fully qualified name is a dot-separated name. For example,
130 * a class B defined as a member type of a class A in package x.y should have a
131 * the fully qualified name "x.y.A.B".
133 * Note that in order to be found, a type name (or its toplevel enclosing
134 * type name) must match its corresponding compilation unit name. As a
135 * consequence, secondary types cannot be found using this functionality.
136 * Secondary types can however be explicitely accessed through their enclosing
137 * unit or found by the <code>SearchEngine</code>.
139 * @param fullyQualifiedName the given fully qualified name
140 * @exception JavaModelException if this element does not exist or if an
141 * exception occurs while accessing its corresponding resource
142 * @return the first type found following this project's classpath
143 * with the given fully qualified name or <code>null</code> if none is found
144 * @see IType#getFullyQualifiedName(char)
147 // IType findType(String fullyQualifiedName) throws JavaModelException;
149 * Returns the first type found following this project's classpath
150 * with the given package name and type qualified name
151 * or <code>null</code> if none is found.
152 * The package name is a dot-separated name.
153 * The type qualified name is also a dot-separated name. For example,
154 * a class B defined as a member type of a class A should have the
155 * type qualified name "A.B".
157 * Note that in order to be found, a type name (or its toplevel enclosing
158 * type name) must match its corresponding compilation unit name. As a
159 * consequence, secondary types cannot be found using this functionality.
160 * Secondary types can however be explicitely accessed through their enclosing
161 * unit or found by the <code>SearchEngine</code>.
163 * @param packageName the given package name
164 * @param typeQualifiedName the given type qualified name
165 * @exception JavaModelException if this element does not exist or if an
166 * exception occurs while accessing its corresponding resource
167 * @return the first type found following this project's classpath
168 * with the given package name and type qualified name
169 * or <code>null</code> if none is found
170 * @see IType#getTypeQualifiedName(char)
174 // IType findType(String packageName, String typeQualifiedName) throws JavaModelException;
177 * Returns all of the existing package fragment roots that exist
178 * on the classpath, in the order they are defined by the classpath.
180 * @return all of the existing package fragment roots that exist
182 * @exception JavaModelException if this element does not exist or if an
183 * exception occurs while accessing its corresponding resource
185 // IPackageFragmentRoot[] getAllPackageFragmentRoots() throws JavaModelException;
188 * Returns an array of non-Java resources directly contained in this project.
189 * It does not transitively answer non-Java resources contained in folders;
190 * these would have to be explicitly iterated over.
192 * Non-Java resources includes other files and folders located in the
193 * project not accounted for by any of it source or binary package fragment
194 * roots. If the project is a source folder itself, resources excluded from the
195 * corresponding source classpath entry by one or more exclusion patterns
196 * are considered non-Java resources and will appear in the result
197 * (possibly in a folder)
200 * @return an array of non-Java resources directly contained in this project
201 * @exception JavaModelException if this element does not exist or if an
202 * exception occurs while accessing its corresponding resource
204 // Object[] getNonJavaResources() throws JavaModelException;
207 * Helper method for returning one option value only. Equivalent to <code>(String)this.getOptions(inheritJavaCoreOptions).get(optionName)</code>
208 * Note that it may answer <code>null</code> if this option does not exist, or if there is no custom value for it.
210 * For a complete description of the configurable options, see <code>JavaCore#getDefaultOptions</code>.
213 * @param optionName the name of an option
214 * @param inheritJavaCoreOptions - boolean indicating whether JavaCore options should be inherited as well
215 * @return the String value of a given option
216 * @see JavaCore#getDefaultOptions
219 // String getOption(String optionName, boolean inheritJavaCoreOptions);
222 * Returns the table of the current custom options for this project. Projects remember their custom options,
223 * in other words, only the options different from the the JavaCore global options for the workspace.
224 * A boolean argument allows to directly merge the project options with global ones from <code>JavaCore</code>.
226 * For a complete description of the configurable options, see <code>JavaCore#getDefaultOptions</code>.
229 * @param inheritJavaCoreOptions - boolean indicating whether JavaCore options should be inherited as well
230 * @return table of current settings of all options
231 * (key type: <code>String</code>; value type: <code>String</code>)
232 * @see JavaCore#getDefaultOptions
235 // Map getOptions(boolean inheritJavaCoreOptions);
238 * Returns the default output location for this project as a workspace-
239 * relative absolute path.
241 * The default output location is where class files are ordinarily generated
242 * (and resource files, copied). Each source classpath entry can also
243 * specify an output location for the generated class files (and copied
244 * resource files) corresponding to compilation units under that source
245 * folder. This makes it possible to arrange generated class files for
246 * different source folders in different output folders, and not
247 * necessarily the default output folder. This means that the generated
248 * class files for the project may end up scattered across several folders,
249 * rather than all in the default output folder (which is more standard).
252 * @return the workspace-relative absolute path of the default output folder
253 * @exception JavaModelException if this element does not exist
254 * @see #setOutputLocation
255 * @see IClasspathEntry#getOutputLocation
257 // IPath getOutputLocation() throws JavaModelException;
260 * Returns a package fragment root for the JAR at the specified file system path.
261 * This is a handle-only method. The underlying <code>java.io.File</code>
262 * may or may not exist. No resource is associated with this local JAR
263 * package fragment root.
265 * @param jarPath the jars's file system path
266 * @return a package fragment root for the JAR at the specified file system path
268 // IPackageFragmentRoot getPackageFragmentRoot(String jarPath);
271 * Returns a package fragment root for the given resource, which
272 * must either be a folder representing the top of a package hierarchy,
273 * or a <code>.jar</code> or <code>.zip</code> file.
274 * This is a handle-only method. The underlying resource may or may not exist.
276 * @param resource the given resource
277 * @return a package fragment root for the given resource, which
278 * must either be a folder representing the top of a package hierarchy,
279 * or a <code>.jar</code> or <code>.zip</code> file
281 // IPackageFragmentRoot getPackageFragmentRoot(IResource resource);
284 * Returns all of the package fragment roots contained in this
285 * project, identified on this project's resolved classpath. The result
286 * does not include package fragment roots in other projects referenced
287 * on this project's classpath.
289 * <p>NOTE: This is equivalent to <code>getChildren()</code>.
291 * @return all of the package fragment roots contained in this
292 * project, identified on this project's resolved classpath
293 * @exception JavaModelException if this element does not exist or if an
294 * exception occurs while accessing its corresponding resource
296 // IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;
299 * Returns the existing package fragment roots identified by the given entry.
300 * Note that a classpath entry that refers to another project may
301 * have more than one root (if that project has more than on root
302 * containing source), and classpath entries within the current
303 * project identify a single root.
305 * If the classpath entry denotes a variable, it will be resolved and return
306 * the roots of the target entry (empty if not resolvable).
308 * If the classpath entry denotes a container, it will be resolved and return
309 * the roots corresponding to the set of container entries (empty if not resolvable).
311 * @param entry the given entry
312 * @return the existing package fragment roots identified by the given entry
313 * @see IClasspathContainer
314 * @deprecated Use IJavaProject#findPackageFragmentRoots instead
316 // IPackageFragmentRoot[] getPackageFragmentRoots(IClasspathEntry entry);
319 * Returns all package fragments in all package fragment roots contained
320 * in this project. This is a convenience method.
322 * Note that the package fragment roots corresponds to the resolved
323 * classpath of the project.
325 * @return all package fragments in all package fragment roots contained
327 * @exception JavaModelException if this element does not exist or if an
328 * exception occurs while accessing its corresponding resource
330 // IPackageFragment[] getPackageFragments() throws JavaModelException;
333 * Returns the <code>IProject</code> on which this <code>IJavaProject</code>
334 * was created. This is handle-only method.
336 * @return the <code>IProject</code> on which this <code>IJavaProject</code>
339 IProject getProject();
342 * Returns the raw classpath for the project, as a list of classpath entries. This corresponds to the exact set
343 * of entries which were assigned using <code>setRawClasspath</code>, in particular such a classpath may contain
344 * classpath variable entries. Classpath variable entries can be resolved individually (see <code>JavaCore#getClasspathVariable</code>),
345 * or the full classpath can be resolved at once using the helper method <code>getResolvedClasspath</code>.
347 * A classpath variable provides an indirection level for better sharing a classpath. As an example, it allows
348 * a classpath to no longer refer directly to external JARs located in some user specific location. The classpath
349 * can simply refer to some variables defining the proper locations of these external JARs.
351 * Note that in case the project isn't yet opened, the classpath will directly be read from the associated <tt>.classpath</tt> file.
354 * @return the raw classpath for the project, as a list of classpath entries
355 * @exception JavaModelException if this element does not exist or if an
356 * exception occurs while accessing its corresponding resource
357 * @see IClasspathEntry
359 // IClasspathEntry[] getRawClasspath() throws JavaModelException;
362 * Returns the names of the projects that are directly required by this
363 * project. A project is required if it is in its classpath.
365 * The project names are returned in the order they appear on the classpath.
367 * @return the names of the projects that are directly required by this
368 * project in classpath order
369 * @exception JavaModelException if this element does not exist or if an
370 * exception occurs while accessing its corresponding resource
372 // String[] getRequiredProjectNames() throws JavaModelException;
375 * This is a helper method returning the resolved classpath for the project
376 * as a list of simple (non-variable, non-container) classpath entries.
377 * All classpath variable and classpath container entries in the project's
378 * raw classpath will be replaced by the simple classpath entries they
381 * The resulting resolved classpath is accurate for the given point in time.
382 * If the project's raw classpath is later modified, or if classpath
383 * variables are changed, the resolved classpath can become out of date.
384 * Because of this, hanging on resolved classpath is not recommended.
387 * @param ignoreUnresolvedEntry indicates how to handle unresolvable
388 * variables and containers; <code>true</code> indicates that missing
389 * variables and unresolvable classpath containers should be silently
390 * ignored, and that the resulting list should consist only of the
391 * entries that could be successfully resolved; <code>false</code> indicates
392 * that a <code>JavaModelException</code> should be thrown for the first
393 * unresolved variable or container
394 * @return the resolved classpath for the project as a list of simple
395 * classpath entries, where all classpath variable and container entries
396 * have been resolved and substituted with their final target entries
397 * @exception JavaModelException in one of the corresponding situation:
399 * <li>this element does not exist</li>
400 * <li>an exception occurs while accessing its corresponding resource</li>
401 * <li>a classpath variable or classpath container was not resolvable
402 * and <code>ignoreUnresolvedEntry</code> is <code>false</code>.</li>
404 * @see IClasspathEntry
406 // IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry)
407 // throws JavaModelException;
410 * Returns whether this project has been built at least once and thus whether it has a build state.
411 * @return true if this project has been built at least once, false otherwise
413 // boolean hasBuildState();
416 * Returns whether setting this project's classpath to the given classpath entries
417 * would result in a cycle.
419 * If the set of entries contains some variables, those are resolved in order to determine
422 * @param entries the given classpath entries
423 * @return true if the given classpath entries would result in a cycle, false otherwise
425 // boolean hasClasspathCycle(IClasspathEntry[] entries);
427 * Returns whether the given element is on the classpath of this project,
428 * that is, referenced from a classpath entry and not explicitly excluded
429 * using an exclusion pattern.
431 * @param element the given element
432 * @return <code>true</code> if the given element is on the classpath of
433 * this project, <code>false</code> otherwise
434 * @see IClasspathEntry#getExclusionPatterns
437 // boolean isOnClasspath(IJavaElement element);
439 * Returns whether the given resource is on the classpath of this project,
440 * that is, referenced from a classpath entry and not explicitly excluded
441 * using an exclusion pattern.
443 * @param element the given element
444 * @return <code>true</code> if the given resource is on the classpath of
445 * this project, <code>false</code> otherwise
446 * @see IClasspathEntry#getExclusionPatterns
449 // boolean isOnClasspath(IResource resource);
452 * Creates a new evaluation context.
453 * @return a new evaluation context.
455 // IEvaluationContext newEvaluationContext();
458 * Creates and returns a type hierarchy for all types in the given
459 * region, considering subtypes within that region.
461 * @param monitor the given progress monitor
462 * @param region the given region
463 * @exception JavaModelException if this element does not exist or if an
464 * exception occurs while accessing its corresponding resource
465 * @exception IllegalArgumentException if region is <code>null</code>
466 * @return a type hierarchy for all types in the given
467 * region, considering subtypes within that region
469 // ITypeHierarchy newTypeHierarchy(IRegion region, IProgressMonitor monitor)
470 // throws JavaModelException;
473 * Creates and returns a type hierarchy for the given type considering
474 * subtypes in the specified region.
476 * @param monitor the given monitor
477 * @param region the given region
478 * @param type the given type
480 * @exception JavaModelException if this element does not exist or if an
481 * exception occurs while accessing its corresponding resource
483 * @exception IllegalArgumentException if type or region is <code>null</code>
484 * @return a type hierarchy for the given type considering
485 * subtypes in the specified region
487 // ITypeHierarchy newTypeHierarchy(
490 // IProgressMonitor monitor)
491 // throws JavaModelException;
494 * Sets the project custom options. All and only the options explicitly included in the given table
495 * are remembered; all previous option settings are forgotten, including ones not explicitly
498 * For a complete description of the configurable options, see <code>JavaCore#getDefaultOptions</code>.
501 * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
502 * or <code>null</code> to flush all custom options (clients will automatically get the global JavaCore options).
503 * @see JavaCore#getDefaultOptions
506 // void setOptions(Map newOptions);
509 * Sets the default output location of this project to the location
510 * described by the given workspace-relative absolute path.
512 * The default output location is where class files are ordinarily generated
513 * (and resource files, copied). Each source classpath entries can also
514 * specify an output location for the generated class files (and copied
515 * resource files) corresponding to compilation units under that source
516 * folder. This makes it possible to arrange that generated class files for
517 * different source folders to end up in different output folders, and not
518 * necessarily the default output folder. This means that the generated
519 * class files for the project may end up scattered across several folders,
520 * rather than all in the default output folder (which is more standard).
523 * @param path the workspace-relative absolute path of the default output
525 * @param monitor the progress monitor
527 * @exception JavaModelException if the classpath could not be set. Reasons include:
529 * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
530 * <li> The path refers to a location not contained in this project (<code>PATH_OUTSIDE_PROJECT</code>)
531 * <li> The path is not an absolute path (<code>RELATIVE_PATH</code>)
532 * <li> The path is nested inside a package fragment root of this project (<code>INVALID_PATH</code>)
533 * <li> The output location is being modified during resource change event notification (CORE_EXCEPTION)
535 * @see #getOutputLocation
536 * @see IClasspathEntry#getOutputLocation
538 // void setOutputLocation(IPath path, IProgressMonitor monitor)
539 // throws JavaModelException;
542 * Sets the classpath of this project using a list of classpath entries. In particular such a classpath may contain
543 * classpath variable entries. Classpath variable entries can be resolved individually (see <code>JavaCore#getClasspathVariable</code>),
544 * or the full classpath can be resolved at once using the helper method <code>getResolvedClasspath</code>.
546 * A classpath variable provides an indirection level for better sharing a classpath. As an example, it allows
547 * a classpath to no longer refer directly to external JARs located in some user specific location. The classpath
548 * can simply refer to some variables defining the proper locations of these external JARs.
550 * Setting the classpath to <code>null</code> specifies a default classpath
551 * (the project root). Setting the classpath to an empty array specifies an
554 * If a cycle is detected while setting this classpath, an error marker will be added
555 * to the project closing the cycle.
556 * To avoid this problem, use <code>hasClasspathCycle(IClasspathEntry[] entries)</code>
557 * before setting the classpath.
559 * @param entries a list of classpath entries
560 * @param monitor the given progress monitor
561 * @exception JavaModelException if the classpath could not be set. Reasons include:
563 * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
564 * <li> The classpath is being modified during resource change event notification (CORE_EXCEPTION)
565 * <li> The classpath failed the validation check as defined by <code>JavaConventions#validateClasspath</code>
567 * @see IClasspathEntry
569 // void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor)
570 // throws JavaModelException;
573 * Sets the both the classpath of this project and its default output
574 * location at once. The classpath is defined using a list of classpath
575 * entries. In particular, such a classpath may contain classpath variable
576 * entries. Classpath variable entries can be resolved individually (see
577 * <code>JavaCore#getClasspathVariable</code>), or the full classpath can be
578 * resolved at once using the helper method
579 * <code>getResolvedClasspath</code>.
581 * A classpath variable provides an indirection level for better sharing a
582 * classpath. As an example, it allows a classpath to no longer refer
583 * directly to external JARs located in some user specific location. The
584 * classpath can simply refer to some variables defining the proper
585 * locations of these external JARs.
588 * Setting the classpath to <code>null</code> specifies a default classpath
589 * (the project root). Setting the classpath to an empty array specifies an
593 * If a cycle is detected while setting this classpath, an error marker will
594 * be added to the project closing the cycle. To avoid this problem, use
595 * <code>hasClasspathCycle(IClasspathEntry[] entries)</code> before setting
599 * @param entries a list of classpath entries
600 * @param monitor the progress monitor
601 * @param outputLocation the default output location
602 * @exception JavaModelException if the classpath could not be set. Reasons
605 * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
606 * <li> Two or more entries specify source roots with the same or overlapping paths (NAME_COLLISION)
607 * <li> A entry of kind <code>CPE_PROJECT</code> refers to this project (INVALID_PATH)
608 * <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
609 * <li>The output location path refers to a location not contained in this project (<code>PATH_OUTSIDE_PROJECT</code>)
610 * <li>The output location path is not an absolute path (<code>RELATIVE_PATH</code>)
611 * <li>The output location path is nested inside a package fragment root of this project (<code>INVALID_PATH</code>)
612 * <li> The classpath is being modified during resource change event notification (CORE_EXCEPTION)
614 * @see IClasspathEntry
617 // void setRawClasspath(IClasspathEntry[] entries, IPath outputLocation, IProgressMonitor monitor)
618 // throws JavaModelException;