1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.core;
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.IProgressMonitor;
17 //import net.sourceforge.phpdt.core.eval.IEvaluationContext;
20 * A Java project represents a view of a project resource in terms of Java
21 * elements such as package fragments, types, methods and fields.
22 * A project may contain several package roots, which contain package fragments.
23 * A package root corresponds to an underlying folder or JAR.
25 * Each Java project has a classpath, defining which folders contain source code and
26 * where required libraries are located. Each Java project also has an output location,
27 * defining where the builder writes <code>.class</code> files. A project that
28 * references packages in another project can access the packages by including
29 * the required project in a classpath entry. The Java model will present the
30 * source elements in the required project, and when building, the compiler will
31 * use the binaries from that project (that is, the output location of the
32 * required project is used as a library). The classpath format is a sequence
33 * of classpath entries describing the location and contents of package fragment
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 first type found following this project's classpath
109 * with the given fully qualified name or <code>null</code> if none is found.
110 * The fully qualified name is a dot-separated name. For example,
111 * a class B defined as a member type of a class A in package x.y should have a
112 * the fully qualified name "x.y.A.B".
114 * @param fullyQualifiedName the given fully qualified name
115 * @exception JavaModelException if this element does not exist or if an
116 * exception occurs while accessing its corresponding resource
117 * @return the first type found following this project's classpath
118 * with the given fully qualified name or <code>null</code> if none is found
119 * @see IType#getFullyQualifiedName(char)
122 IType findType(String fullyQualifiedName) throws JavaModelException;
124 * Returns the first type found following this project's classpath
125 * with the given package name and type qualified name
126 * or <code>null</code> if none is found.
127 * The package name is a dot-separated name.
128 * The type qualified name is also a dot-separated name. For example,
129 * a class B defined as a member type of a class A should have the
130 * type qualified name "A.B".
132 * @param packageName the given package name
133 * @param typeQualifiedName the given type qualified name
134 * @exception JavaModelException if this element does not exist or if an
135 * exception occurs while accessing its corresponding resource
136 * @return the first type found following this project's classpath
137 * with the given package name and type qualified name
138 * or <code>null</code> if none is found
139 * @see IType#getTypeQualifiedName(char)
142 IType findType(String packageName, String typeQualifiedName) throws JavaModelException;
145 * Returns all of the existing package fragment roots that exist
146 * on the classpath, in the order they are defined by the classpath.
148 * @return all of the existing package fragment roots that exist
150 * @exception JavaModelException if this element does not exist or if an
151 * exception occurs while accessing its corresponding resource
153 // IPackageFragmentRoot[] getAllPackageFragmentRoots() throws JavaModelException;
156 * Returns an array of non-Java resources directly contained in this project.
157 * It does not transitively answer non-Java resources contained in folders;
158 * these would have to be explicitly iterated over.
159 * @return an array of non-Java resources directly contained in this project
161 Object[] getNonJavaResources() throws JavaModelException;
164 * Returns the full path to the location where the builder writes
165 * <code>.class</code> files.
167 * @exception JavaModelException if this element does not exist or if an
168 * exception occurs while accessing its corresponding resource
169 * @return the full path to the location where the builder writes
170 * <code>.class</code> files
172 IPath getOutputLocation() throws JavaModelException;
175 * Returns a package fragment root for the JAR at the specified file system path.
176 * This is a handle-only method. The underlying <code>java.io.File</code>
177 * may or may not exist. No resource is associated with this local JAR
178 * package fragment root.
180 * @param jarPath the jars's file system path
181 * @return a package fragment root for the JAR at the specified file system path
183 // IPackageFragmentRoot getPackageFragmentRoot(String jarPath);
186 * Returns a package fragment root for the given resource, which
187 * must either be a folder representing the top of a package hierarchy,
188 * or a <code>.jar</code> or <code>.zip</code> file.
189 * This is a handle-only method. The underlying resource may or may not exist.
191 * @param resource the given resource
192 * @return a package fragment root for the given resource, which
193 * must either be a folder representing the top of a package hierarchy,
194 * or a <code>.jar</code> or <code>.zip</code> file
196 // IPackageFragmentRoot getPackageFragmentRoot(IResource resource);
199 * Returns all of the package fragment roots contained in this
200 * project, identified on this project's resolved classpath. The result
201 * does not include package fragment roots in other projects referenced
202 * on this project's classpath.
204 * <p>NOTE: This is equivalent to <code>getChildren()</code>.
206 * @return all of the package fragment roots contained in this
207 * project, identified on this project's resolved classpath
208 * @exception JavaModelException if this element does not exist or if an
209 * exception occurs while accessing its corresponding resource
211 // IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;
214 * Returns the existing package fragment roots identified by the given entry.
215 * Note that a classpath entry that refers to another project may
216 * have more than one root (if that project has more than on root
217 * containing source), and classpath entries within the current
218 * project identify a single root.
220 * If the classpath entry denotes a variable, it will be resolved and return
221 * the roots of the target entry (empty if not resolvable).
223 * If the classpath entry denotes a container, it will be resolved and return
224 * the roots corresponding to the set of container entries (empty if not resolvable).
226 * @param entry the given entry
227 * @return the existing package fragment roots identified by the given entry
228 * @see IClasspathContainer
230 // IPackageFragmentRoot[] getPackageFragmentRoots(IClasspathEntry entry);
233 * Returns all package fragments in all package fragment roots contained
234 * in this project. This is a convenience method.
236 * Note that the package fragment roots corresponds to the resolved
237 * classpath of the project.
239 * @return all package fragments in all package fragment roots contained
241 * @exception JavaModelException if this element does not exist or if an
242 * exception occurs while accessing its corresponding resource
244 // IPackageFragment[] getPackageFragments() throws JavaModelException;
247 * Returns the <code>IProject</code> on which this <code>IJavaProject</code>
248 * was created. This is handle-only method.
250 * @return the <code>IProject</code> on which this <code>IJavaProject</code>
253 IProject getProject();
256 * This is a helper method returning the resolved classpath for the project, as a list of classpath entries,
257 * where all classpath variable entries have been resolved and substituted with their final target entries.
259 * A resolved classpath corresponds to a particular instance of the raw classpath bound in the context of
260 * the current values of the referred variables, and thus should not be persisted.
262 * A classpath variable provides an indirection level for better sharing a classpath. As an example, it allows
263 * a classpath to no longer refer directly to external JARs located in some user specific location. The classpath
264 * can simply refer to some variables defining the proper locations of these external JARs.
266 * The boolean argument <code>ignoreUnresolvedVariable</code> allows to specify how to handle unresolvable variables,
267 * when set to <code>true</code>, missing variables are simply ignored, the resulting path is then only formed of the
268 * resolvable entries, without any indication about which variable(s) was ignored. When set to <code>false</code>, a
269 * JavaModelException will be thrown for the first unresolved variable (from left to right).
271 * @exception JavaModelException in one of the corresponding situation:
273 * <li> this element does not exist </li>
274 * <li> an exception occurs while accessing its corresponding resource </li>
275 * <li> a classpath variable was not resolvable and <code>ignoreUnresolvedVariable</code> was set to <code>false</code>. </li>
278 * @see IClasspathEntry
280 // IClasspathEntry[] getExpandedClasspath(boolean ignoreUnresolvedVariable)
281 // throws JavaModelException;
284 * Returns the raw classpath for the project, as a list of classpath entries. This corresponds to the exact set
285 * of entries which were assigned using <code>setRawClasspath</code>, in particular such a classpath may contain
286 * classpath variable entries. Classpath variable entries can be resolved individually (see <code>JavaCore#getClasspathVariable</code>),
287 * or the full classpath can be resolved at once using the helper method <code>getResolvedClasspath</code>.
289 * A classpath variable provides an indirection level for better sharing a classpath. As an example, it allows
290 * a classpath to no longer refer directly to external JARs located in some user specific location. The classpath
291 * can simply refer to some variables defining the proper locations of these external JARs.
293 * Note that in case the project isn't yet opened, the classpath will directly be read from the associated <tt>.classpath</tt> file.
296 * @return the raw classpath for the project, as a list of classpath entries
297 * @exception JavaModelException if this element does not exist or if an
298 * exception occurs while accessing its corresponding resource
299 * @see IClasspathEntry
301 // IClasspathEntry[] getRawClasspath() throws JavaModelException;
304 * Returns the names of the projects that are directly required by this
305 * project. A project is required if it is in its classpath.
307 * @return the names of the projects that are directly required by this
309 * @exception JavaModelException if this element does not exist or if an
310 * exception occurs while accessing its corresponding resource
312 String[] getRequiredProjectNames() throws JavaModelException;
315 * This is a helper method returning the resolved classpath for the project, as a list of classpath entries,
316 * where all classpath variable entries have been resolved and substituted with their final target entries.
318 * A resolved classpath corresponds to a particular instance of the raw classpath bound in the context of
319 * the current values of the referred variables, and thus should not be persisted.
321 * A classpath variable provides an indirection level for better sharing a classpath. As an example, it allows
322 * a classpath to no longer refer directly to external JARs located in some user specific location. The classpath
323 * can simply refer to some variables defining the proper locations of these external JARs.
325 * The boolean argument <code>ignoreUnresolvedVariable</code> allows to specify how to handle unresolvable variables,
326 * when set to <code>true</code>, missing variables are simply ignored, the resulting path is then only formed of the
327 * resolvable entries, without any indication about which variable(s) was ignored. When set to <code>false</code>, a
328 * JavaModelException will be thrown for the first unresolved variable (from left to right).
330 * @param ignoreUnresolvedVariable specify how to handle unresolvable variables
331 * @return the resolved classpath for the project, as a list of classpath entries,
332 * where all classpath variable entries have been resolved and substituted with their final target entries
333 * @exception JavaModelException in one of the corresponding situation:
335 * <li> this element does not exist </li>
336 * <li> an exception occurs while accessing its corresponding resource </li>
337 * <li> a classpath variable was not resolvable and <code>ignoreUnresolvedVariable</code> was set to <code>false</code>. </li>
339 * @see IClasspathEntry
341 // IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedVariable) throws JavaModelException;
344 * Returns whether this project has been built at least once and thus whether it has a build state.
345 * @return true if this project has been built at least once, false otherwise
347 boolean hasBuildState();
350 * Returns whether setting this project's classpath to the given classpath entries
351 * would result in a cycle.
353 * If the set of entries contains some variables, those are resolved in order to determine
356 * @param entries the given classpath entries
357 * @return true if the given classpath entries would result in a cycle, false otherwise
359 // boolean hasClasspathCycle(IClasspathEntry[] entries);
361 * Returns whether the given element is on the classpath of this project.
363 * @param element the given element
364 * @exception JavaModelException if this element does not exist or if an
365 * exception occurs while accessing its corresponding resource
366 * @return true if the given element is on the classpath of this project, false otherwise
369 boolean isOnClasspath(IJavaElement element) throws JavaModelException;
372 * Creates a new evaluation context.
373 * @return a new evaluation context.
375 // IEvaluationContext newEvaluationContext();
378 * Creates and returns a type hierarchy for all types in the given
379 * region, considering subtypes within that region.
381 * @param monitor the given progress monitor
382 * @param region the given region
383 * @exception JavaModelException if this element does not exist or if an
384 * exception occurs while accessing its corresponding resource
385 * @exception IllegalArgumentException if region is <code>null</code>
386 * @return a type hierarchy for all types in the given
387 * region, considering subtypes within that region
389 // ITypeHierarchy newTypeHierarchy(IRegion region, IProgressMonitor monitor)
390 // throws JavaModelException;
393 * Creates and returns a type hierarchy for the given type considering
394 * subtypes in the specified region.
396 * @param monitor the given monitor
397 * @param region the given region
398 * @param type the given type
400 * @exception JavaModelException if this element does not exist or if an
401 * exception occurs while accessing its corresponding resource
403 * @exception IllegalArgumentException if type or region is <code>null</code>
404 * @return a type hierarchy for the given type considering
405 * subtypes in the specified region
407 // ITypeHierarchy newTypeHierarchy(
410 // IProgressMonitor monitor)
411 // throws JavaModelException;
414 * Sets the output location of this project to the location
415 * described by the given absolute path.
418 * @param path the given absolute path
419 * @param monitor the given progress monitor
421 * @exception JavaModelException if the classpath could not be set. Reasons include:
423 * <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
424 * <li>The path refers to a location not contained in this project (<code>PATH_OUTSIDE_PROJECT</code>)
425 * <li>The path is not an absolute path (<code>RELATIVE_PATH</code>)
426 * <li>The path is nested inside a package fragment root of this project (<code>INVALID_PATH</code>)
427 * <li> The output location is being modified during resource change event notification (CORE_EXCEPTION)
430 void setOutputLocation(IPath path, IProgressMonitor monitor) throws JavaModelException;
433 * Sets the classpath of this project using a list of classpath entries. In particular such a classpath may contain
434 * classpath variable entries. Classpath variable entries can be resolved individually (see <code>JavaCore#getClasspathVariable</code>),
435 * or the full classpath can be resolved at once using the helper method <code>getResolvedClasspath</code>.
437 * A classpath variable provides an indirection level for better sharing a classpath. As an example, it allows
438 * a classpath to no longer refer directly to external JARs located in some user specific location. The classpath
439 * can simply refer to some variables defining the proper locations of these external JARs.
441 * Setting the classpath to <code>null</code> specifies a default classpath
442 * (the project root). Setting the classpath to an empty array specifies an
445 * If a cycle is detected while setting this classpath, an error marker will be added
446 * to the project closing the cycle.
447 * To avoid this problem, use <code>hasClasspathCycle(IClasspathEntry[] entries)</code>
448 * before setting the classpath.
450 * @param entries a list of classpath entries
451 * @param monitor the given progress monitor
452 * @exception JavaModelException if the classpath could not be set. Reasons include:
454 * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
455 * <li> The classpath is being modified during resource change event notification (CORE_EXCEPTION)
456 * <li> The classpath failed the validation check as defined by <code>JavaConventions#validateClasspath</code>
458 * @see IClasspathEntry
460 // void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor)
461 // throws JavaModelException;
464 * Sets the both the classpath of this project and its output location at once.
465 * The classpath is defined using a list of classpath entries. In particular such a classpath may contain
466 * classpath variable entries. Classpath variable entries can be resolved individually (see <code>JavaCore#getClasspathVariable</code>),
467 * or the full classpath can be resolved at once using the helper method <code>getResolvedClasspath</code>.
469 * A classpath variable provides an indirection level for better sharing a classpath. As an example, it allows
470 * a classpath to no longer refer directly to external JARs located in some user specific location. The classpath
471 * can simply refer to some variables defining the proper locations of these external JARs.
473 * Setting the classpath to <code>null</code> specifies a default classpath
474 * (the project root). Setting the classpath to an empty array specifies an
477 * If a cycle is detected while setting this classpath, an error marker will be added
478 * to the project closing the cycle.
479 * To avoid this problem, use <code>hasClasspathCycle(IClasspathEntry[] entries)</code>
480 * before setting the classpath.
482 * @param entries a list of classpath entries
483 * @param monitor the given progress monitor
484 * @param outputLocation the given output location
486 * @exception JavaModelException if the classpath could not be set. Reasons include:
488 * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
489 * <li> Two or more entries specify source roots with the same or overlapping paths (NAME_COLLISION)
490 * <li> A entry of kind <code>CPE_PROJECT</code> refers to this project (INVALID_PATH)
491 * <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
492 * <li>The output location path refers to a location not contained in this project (<code>PATH_OUTSIDE_PROJECT</code>)
493 * <li>The output location path is not an absolute path (<code>RELATIVE_PATH</code>)
494 * <li>The output location path is nested inside a package fragment root of this project (<code>INVALID_PATH</code>)
495 * <li> The classpath is being modified during resource change event notification (CORE_EXCEPTION)
497 * @see IClasspathEntry
500 // void setRawClasspath(IClasspathEntry[] entries, IPath outputLocation, IProgressMonitor monitor)
501 // throws JavaModelException;