org.aspectj.org.eclipse.jdt.internal.core
Class JavaModel
java.lang.Object
PlatformObject
org.aspectj.org.eclipse.jdt.internal.core.JavaElement
org.aspectj.org.eclipse.jdt.internal.core.Openable
org.aspectj.org.eclipse.jdt.internal.core.JavaModel
- All Implemented Interfaces:
- IBufferChangedListener, IJavaElement, IJavaModel, IOpenable, IParent
public class JavaModel
- extends Openable
- implements IJavaModel
Implementation of IJavaModel. The Java Model maintains a cache of
active IJavaProjects in a workspace. A Java Model is specific to a
workspace. To retrieve a workspace's model, use the
#getJavaModel(IWorkspace) method.
- See Also:
IJavaModel
| Fields inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaElement |
JEM_CLASSFILE, JEM_COMPILATIONUNIT, JEM_COUNT, JEM_ESCAPE, JEM_FIELD, JEM_IMPORTDECLARATION, JEM_INITIALIZER, JEM_JAVAPROJECT, JEM_LOCALVARIABLE, JEM_METHOD, JEM_PACKAGEDECLARATION, JEM_PACKAGEFRAGMENT, JEM_PACKAGEFRAGMENTROOT, JEM_TYPE, JEM_TYPE_PARAMETER, NO_ELEMENTS, NO_INFO, parent |
| Fields inherited from interface org.aspectj.org.eclipse.jdt.core.IJavaElement |
CLASS_FILE, COMPILATION_UNIT, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVA_MODEL, JAVA_PROJECT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETER |
|
Constructor Summary |
protected |
JavaModel()
Constructs a new Java Model on the given workspace. |
|
Method Summary |
protected boolean |
buildStructure(OpenableElementInfo info,
IProgressMonitor pm,
java.util.Map newElements,
IResource underlyingResource)
Builds this element's structure and properties in the given
info object, based on this element's current contents (reuse buffer
contents if this element has an open buffer, or resource contents
if this element does not have an open buffer). |
boolean |
contains(IResource resource)
Returns whether this Java model contains an IJavaElement whose
resource is the given resource or a non-Java resource which is the given resource. |
void |
copy(IJavaElement[] elements,
IJavaElement[] containers,
IJavaElement[] siblings,
java.lang.String[] renamings,
boolean force,
IProgressMonitor monitor)
Copies the given elements to the specified container(s). |
protected java.lang.Object |
createElementInfo()
Returns a new element info for this element. |
void |
delete(IJavaElement[] elements,
boolean force,
IProgressMonitor monitor)
Deletes the given elements, forcing the operation if necessary and specified. |
boolean |
equals(java.lang.Object o)
Returns true if this handle represents the same Java element
as the given handle. |
static void |
flushExternalFileCache()
Flushes the cache of external files known to be existing. |
int |
getElementType()
Returns this element's kind encoded as an integer. |
static java.io.File |
getFile(java.lang.Object target)
Helper method - returns the file item (ie. |
IJavaElement |
getHandleFromMemento(java.lang.String token,
MementoTokenizer memento,
WorkingCopyOwner owner)
|
protected void |
getHandleMemento(java.lang.StringBuffer buff)
|
protected char |
getHandleMementoDelimiter()
Returns the char that marks the start of this handles
contribution to a memento. |
IJavaProject |
getJavaProject(IResource resource)
Returns the active Java project associated with the specified
resource, or null if no Java project yet exists
for the resource. |
IJavaProject |
getJavaProject(java.lang.String projectName)
Returns the Java project with the given name. |
IJavaProject[] |
getJavaProjects()
Returns the Java projects in this Java model, or an empty array if there
are none. |
java.lang.Object[] |
getNonJavaResources()
Returns an array of non-Java resources (that is, non-Java projects) in
the workspace. |
IPath |
getPath()
Returns the path to the innermost resource enclosing this element. |
IResource |
getResource()
Returns the innermost resource enclosing this element. |
static java.lang.Object |
getTarget(IContainer container,
IPath path,
boolean checkResourceExistence)
Helper method - returns the targeted item (IResource if internal or java.io.File if external),
or null if unbound
Internal items must be referred to using container relative paths. |
IResource |
getUnderlyingResource()
Returns the smallest underlying resource that contains
this element, or null if this element is not contained
in a resource. |
IWorkspace |
getWorkspace()
Returns the workbench associated with this object. |
static boolean |
isFile(java.lang.Object target)
Helper method - returns whether an object is afile (ie. |
void |
move(IJavaElement[] elements,
IJavaElement[] containers,
IJavaElement[] siblings,
java.lang.String[] renamings,
boolean force,
IProgressMonitor monitor)
Moves the given elements to the specified container(s). |
void |
refreshExternalArchives(IJavaElement[] elementsScope,
IProgressMonitor monitor)
Triggers an update of the JavaModel with respect to the referenced external archives. |
void |
rename(IJavaElement[] elements,
IJavaElement[] destinations,
java.lang.String[] renamings,
boolean force,
IProgressMonitor monitor)
Renames the given elements as specified. |
protected void |
runOperation(MultiOperation op,
IJavaElement[] elements,
IJavaElement[] siblings,
java.lang.String[] renamings,
IProgressMonitor monitor)
Configures and runs the MultiOperation. |
protected void |
toStringInfo(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info,
boolean showResolvedInfo)
Debugging purposes |
| Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.Openable |
bufferChanged, canBeRemovedFromCache, canBufferBeRemovedFromCache, closeBuffer, closing, codeComplete, codeSelect, exists, findRecommendedLineSeparator, generateInfos, getBuffer, getBufferFactory, getBufferManager, getCorrespondingResource, getOpenable, getPackageFragmentRoot, hasBuffer, hasUnsavedChanges, isConsistent, isOpen, isSourceElement, isStructureKnown, makeConsistent, open, openBuffer, openParent, parentExists, resourceExists, save |
| Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaElement |
close, escapeMementoName, findNode, getAncestor, getAttachedJavadoc, getChildren, getChildrenOfType, getClassFile, getCompilationUnit, getElementInfo, getElementInfo, getElementName, getHandleFromMemento, getHandleIdentifier, getHandleMemento, getJavadocBaseLocation, getJavaModel, getJavaProject, getLibraryJavadocLocation, getOpenableParent, getParent, getPrimaryElement, getPrimaryElement, getSchedulingRule, getSourceElementAt, getSourceMapper, getURLContents, hasChildren, hashCode, isAncestorOf, isReadOnly, newJavaModelException, newNotPresentException, openWhenClosed, readableName, resolved, tabString, toDebugString, toString, toString, toStringAncestors, toStringChildren, toStringInfo, toStringName, toStringWithAncestors, toStringWithAncestors, unresolved |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.aspectj.org.eclipse.jdt.core.IJavaElement |
exists, getAncestor, getAttachedJavadoc, getCorrespondingResource, getElementName, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPrimaryElement, getSchedulingRule, isReadOnly, isStructureKnown |
existingExternalFiles
public static java.util.HashSet existingExternalFiles
- A set of java.io.Files used as a cache of external jars that
are known to be existing.
Note this cache is kept for the whole session.
existingExternalConfirmedFiles
public static java.util.HashSet existingExternalConfirmedFiles
- A set of external files (
existingExternalFiles) which have
been confirmed as file (ie. which returns true to File.isFile().
Note this cache is kept for the whole session.
JavaModel
protected JavaModel()
throws java.lang.Error
- Constructs a new Java Model on the given workspace.
Note that only one instance of JavaModel handle should ever be created.
One should only indirect through JavaModelManager#getJavaModel() to get
access to it.
- Throws:
java.lang.Error - if called more than once
buildStructure
protected boolean buildStructure(OpenableElementInfo info,
IProgressMonitor pm,
java.util.Map newElements,
IResource underlyingResource)
- Description copied from class:
Openable
- Builds this element's structure and properties in the given
info object, based on this element's current contents (reuse buffer
contents if this element has an open buffer, or resource contents
if this element does not have an open buffer). Children
are placed in the given newElements table (note, this element
has already been placed in the newElements table). Returns true
if successful, or false if an error is encountered while determining
the structure of this element.
- Specified by:
buildStructure in class Openable
contains
public boolean contains(IResource resource)
- Description copied from interface:
IJavaModel
- Returns whether this Java model contains an
IJavaElement whose
resource is the given resource or a non-Java resource which is the given resource.
Note: no existency check is performed on the argument resource. If it is not accessible
(see IResource.isAccessible()) yet but would be located in Java model
range, then it will return true.
If the resource is accessible, it can be reached by navigating the Java model down using the
getChildren() and/or getNonJavaResources() methods.
- Specified by:
contains in interface IJavaModel
- Parameters:
resource - the resource to check
- Returns:
- true if the resource is accessible through the Java model
copy
public void copy(IJavaElement[] elements,
IJavaElement[] containers,
IJavaElement[] siblings,
java.lang.String[] renamings,
boolean force,
IProgressMonitor monitor)
throws JavaModelException
- Description copied from interface:
IJavaModel
- Copies the given elements to the specified container(s).
If one container is specified, all elements are copied to that
container. If more than one container is specified, the number of
elements and containers must match, and each element is copied to
its associated container.
Optionally, each copy can positioned before a sibling
element. If null is specified for a given sibling, the copy
is inserted as the last child of its associated container.
Optionally, each copy can be renamed. If
null is specified for the new name, the copy
is not renamed.
Optionally, any existing child in the destination container with
the same name can be replaced by specifying true for
force. Otherwise an exception is thrown in the event that a name
collision occurs.
- Specified by:
copy in interface IJavaModel
- Parameters:
elements - the elements to copycontainers - the container, or list of containerssiblings - the list of siblings element any of which may be
null; or nullrenamings - the list of new names any of which may be
null; or nullforce - true if any existing child in a target container
with the target name should be replaced, and false to throw an
exception in the event of a name collisionmonitor - a progress monitor
- Throws:
JavaModelException - if an element could not be copied. Reasons include:
- There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
- A specified element, container, or sibling does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException occurred while updating an underlying resource
- A container is of an incompatible type (
INVALID_DESTINATION)
- A sibling is not a child of it associated container (
INVALID_SIBLING)
- A new name is invalid (
INVALID_NAME)
- A child in its associated container already exists with the same
name and
replace has been specified as false (NAME_COLLISION)
- A container or element is read-only (
READ_ONLY)
- See Also:
IJavaModel
createElementInfo
protected java.lang.Object createElementInfo()
- Returns a new element info for this element.
- Overrides:
createElementInfo in class Openable
delete
public void delete(IJavaElement[] elements,
boolean force,
IProgressMonitor monitor)
throws JavaModelException
- Description copied from interface:
IJavaModel
- Deletes the given elements, forcing the operation if necessary and specified.
- Specified by:
delete in interface IJavaModel
- Parameters:
elements - the elements to deleteforce - a flag controlling whether underlying resources that are not
in sync with the local file system will be toleratedmonitor - a progress monitor
- Throws:
JavaModelException - if an element could not be deleted. Reasons include:
- There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
- A specified element does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException occurred while updating an underlying resource
- An element is read-only (
READ_ONLY)
- See Also:
IJavaModel
equals
public boolean equals(java.lang.Object o)
- Description copied from class:
JavaElement
- Returns true if this handle represents the same Java element
as the given handle. By default, two handles represent the same
element if they are identical or if they represent the same type
of element, have equal names, parents, and occurrence counts.
If a subclass has other requirements for equality, this method
must be overridden.
- Overrides:
equals in class JavaElement
- See Also:
Object.equals(java.lang.Object)
getElementType
public int getElementType()
- Description copied from interface:
IJavaElement
- Returns this element's kind encoded as an integer.
This is a handle-only method.
- Specified by:
getElementType in interface IJavaElement
- Returns:
- the kind of element; one of the constants declared in
IJavaElement - See Also:
IJavaElement
flushExternalFileCache
public static void flushExternalFileCache()
- Flushes the cache of external files known to be existing.
getHandleFromMemento
public IJavaElement getHandleFromMemento(java.lang.String token,
MementoTokenizer memento,
WorkingCopyOwner owner)
- Specified by:
getHandleFromMemento in class JavaElement
getHandleMemento
protected void getHandleMemento(java.lang.StringBuffer buff)
- Overrides:
getHandleMemento in class JavaElement
- See Also:
JavaElement.getHandleMemento(StringBuffer)
getHandleMementoDelimiter
protected char getHandleMementoDelimiter()
- Returns the
char that marks the start of this handles
contribution to a memento.
- Specified by:
getHandleMementoDelimiter in class JavaElement
getJavaProject
public IJavaProject getJavaProject(java.lang.String projectName)
- Description copied from interface:
IJavaModel
- Returns the Java project with the given name. This is a handle-only method.
The project may or may not exist.
- Specified by:
getJavaProject in interface IJavaModel
- Parameters:
projectName - the name of the Java project
- Returns:
- the Java project with the given name
- See Also:
IJavaModel
getJavaProject
public IJavaProject getJavaProject(IResource resource)
- Returns the active Java project associated with the specified
resource, or
null if no Java project yet exists
for the resource.
- Specified by:
getJavaProject in interface IJavaModel
- Parameters:
resource - the name of the Java project
- Returns:
- the Java project with the given name
- Throws:
java.lang.IllegalArgumentException - if the given resource
is not one of an IProject, IFolder, or IFile.
getJavaProjects
public IJavaProject[] getJavaProjects()
throws JavaModelException
- Description copied from interface:
IJavaModel
- Returns the Java projects in this Java model, or an empty array if there
are none.
- Specified by:
getJavaProjects in interface IJavaModel
- Returns:
- the Java projects in this Java model, or an empty array if there
are none
- Throws:
JavaModelException - if this request fails.- See Also:
IJavaModel
getNonJavaResources
public java.lang.Object[] getNonJavaResources()
throws JavaModelException
- Description copied from interface:
IJavaModel
- Returns an array of non-Java resources (that is, non-Java projects) in
the workspace.
Non-Java projects include all projects that are closed (even if they have the
Java nature).
- Specified by:
getNonJavaResources in interface IJavaModel
- Returns:
- an array of non-Java projects (
IProjects) contained
in the workspace.
- Throws:
JavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resource- See Also:
IJavaModel
getPath
public IPath getPath()
- Description copied from interface:
IJavaElement
- Returns the path to the innermost resource enclosing this element.
If this element is not included in an external archive,
the path returned is the full, absolute path to the underlying resource,
relative to the workbench.
If this element is included in an external archive,
the path returned is the absolute path to the archive in the file system.
This is a handle-only method.
- Specified by:
getPath in interface IJavaElement
- Returns:
- the path to the innermost resource enclosing this element
getResource
public IResource getResource()
- Description copied from interface:
IJavaElement
- Returns the innermost resource enclosing this element.
If this element is included in an archive and this archive is not external,
this is the underlying resource corresponding to the archive.
If this element is included in an external archive,
null
is returned.
This is a handle-only method.
- Specified by:
getResource in interface IJavaElement
- Returns:
- the innermost resource enclosing this element,
null if this
element is included in an external archive
getUnderlyingResource
public IResource getUnderlyingResource()
- Description copied from interface:
IJavaElement
- Returns the smallest underlying resource that contains
this element, or
null if this element is not contained
in a resource.
- Specified by:
getUnderlyingResource in interface IJavaElement- Overrides:
getUnderlyingResource in class Openable
- Returns:
- the underlying resource, or
null if none - See Also:
IOpenable
getWorkspace
public IWorkspace getWorkspace()
- Returns the workbench associated with this object.
- Specified by:
getWorkspace in interface IJavaModel
- Returns:
- the workspace associated with this Java model
move
public void move(IJavaElement[] elements,
IJavaElement[] containers,
IJavaElement[] siblings,
java.lang.String[] renamings,
boolean force,
IProgressMonitor monitor)
throws JavaModelException
- Description copied from interface:
IJavaModel
- Moves the given elements to the specified container(s).
If one container is specified, all elements are moved to that
container. If more than one container is specified, the number of
elements and containers must match, and each element is moved to
its associated container.
Optionally, each element can positioned before a sibling
element. If null is specified for sibling, the element
is inserted as the last child of its associated container.
Optionally, each element can be renamed. If
null is specified for the new name, the element
is not renamed.
Optionally, any existing child in the destination container with
the same name can be replaced by specifying true for
force. Otherwise an exception is thrown in the event that a name
collision occurs.
- Specified by:
move in interface IJavaModel
- Parameters:
elements - the elements to movecontainers - the container, or list of containerssiblings - the list of siblings element any of which may be
null; or nullrenamings - the list of new names any of which may be
null; or nullforce - true if any existing child in a target container
with the target name should be replaced, and false to throw an
exception in the event of a name collisionmonitor - a progress monitor
- Throws:
JavaModelException - if an element could not be moved. Reasons include:
- There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
- A specified element, container, or sibling does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException occurred while updating an underlying resource
- A container is of an incompatible type (
INVALID_DESTINATION)
- A sibling is not a child of it associated container (
INVALID_SIBLING)
- A new name is invalid (
INVALID_NAME)
- A child in its associated container already exists with the same
name and
replace has been specified as false (NAME_COLLISION)
- A container or element is read-only (
READ_ONLY)
- See Also:
IJavaModel
refreshExternalArchives
public void refreshExternalArchives(IJavaElement[] elementsScope,
IProgressMonitor monitor)
throws JavaModelException
- Description copied from interface:
IJavaModel
- Triggers an update of the JavaModel with respect to the referenced external archives.
This operation will issue a JavaModel delta describing the discovered changes, in term
of Java element package fragment roots added, removed or changed.
Note that a collection of elements can be passed so as to narrow the set of archives
to refresh (passing
null along is equivalent to refreshing the entire mode).
The elements can be:
- package fragment roots corresponding to external archives
- Java projects, which referenced external archives will be refreshed
- Java model, all referenced external archives will be refreshed.
In case an archive is used by multiple projects, the delta issued will account for
all of them. This means that even if a project was not part of the elements scope, it
may still be notified of changes if it is referencing a library comprised in the scope.
- Specified by:
refreshExternalArchives in interface IJavaModel
- Parameters:
elementsScope - - a collection of elements defining the scope of the refreshmonitor - - a progress monitor used to report progress
- Throws:
JavaModelException - in one of the corresponding situation:
- an exception occurs while accessing project resources
- See Also:
IJavaModel.refreshExternalArchives(IJavaElement[], IProgressMonitor)
rename
public void rename(IJavaElement[] elements,
IJavaElement[] destinations,
java.lang.String[] renamings,
boolean force,
IProgressMonitor monitor)
throws JavaModelException
- Description copied from interface:
IJavaModel
- Renames the given elements as specified.
If one container is specified, all elements are renamed within that
container. If more than one container is specified, the number of
elements and containers must match, and each element is renamed within
its associated container.
- Specified by:
rename in interface IJavaModel
- Parameters:
elements - the elements to renamedestinations - the container, or list of containersrenamings - the list of new namesforce - true if an existing child in a target container
with the target name should be replaced, and false to throw an
exception in the event of a name collisionmonitor - a progress monitor
- Throws:
JavaModelException - if an element could not be renamed. Reasons include:
- There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
- A specified element does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException occurred while updating an underlying resource
- A new name is invalid (
INVALID_NAME)
- A child already exists with the same name and
replace has been specified as false (NAME_COLLISION)
- An element is read-only (
READ_ONLY)
- See Also:
IJavaModel
runOperation
protected void runOperation(MultiOperation op,
IJavaElement[] elements,
IJavaElement[] siblings,
java.lang.String[] renamings,
IProgressMonitor monitor)
throws JavaModelException
- Configures and runs the
MultiOperation.
- Throws:
JavaModelException
toStringInfo
protected void toStringInfo(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info,
boolean showResolvedInfo)
- Description copied from class:
JavaElement
- Debugging purposes
- Overrides:
toStringInfo in class JavaElement
showResolvedInfo - TODO
getTarget
public static java.lang.Object getTarget(IContainer container,
IPath path,
boolean checkResourceExistence)
- Helper method - returns the targeted item (IResource if internal or java.io.File if external),
or null if unbound
Internal items must be referred to using container relative paths.
isFile
public static boolean isFile(java.lang.Object target)
- Helper method - returns whether an object is afile (ie. which returns true to
File.isFile().
getFile
public static java.io.File getFile(java.lang.Object target)
- Helper method - returns the file item (ie. which returns true to
File.isFile(),
or null if unbound