Klasse JavaModel

java.lang.Object
org.eclipse.core.runtime.PlatformObject
Alle implementierten Schnittstellen:
IBufferChangedListener, IJavaElement, IJavaModel, IOpenable, IParent, org.eclipse.core.runtime.IAdaptable

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() method.
Siehe auch:
  • Konstruktordetails

    • JavaModel

      protected JavaModel() throws 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.
      Löst aus:
      Error - if called more than once
  • Methodendetails

    • buildStructure

      protected boolean buildStructure(OpenableElementInfo info, org.eclipse.core.runtime.IProgressMonitor pm, Map newElements, org.eclipse.core.resources.IResource underlyingResource)
      Beschreibung aus Klasse kopiert: 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.
      Angegeben von:
      buildStructure in Klasse Openable
    • contains

      public boolean contains(org.eclipse.core.resources.IResource resource)
      Beschreibung aus Schnittstelle kopiert: 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.

      Angegeben von:
      contains in Schnittstelle IJavaModel
      Parameter:
      resource - the resource to check
      Gibt zurück:
      true if the resource is accessible through the Java model
    • copy

      public void copy(IJavaElement[] elements, IJavaElement[] containers, IJavaElement[] siblings, String[] renamings, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Beschreibung aus Schnittstelle kopiert: 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.

      Angegeben von:
      copy in Schnittstelle IJavaModel
      Parameter:
      elements - the elements to copy
      containers - the container, or list of containers
      siblings - the list of siblings element any of which may be null; or null
      renamings - the list of new names any of which may be null; or null
      force - 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 collision
      monitor - a progress monitor
      Löst aus:
      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)
      Siehe auch:
    • createElementInfo

      protected Object createElementInfo()
      Returns a new element info for this element.
      Setzt außer Kraft:
      createElementInfo in Klasse Openable
    • delete

      public void delete(IJavaElement[] elements, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Beschreibung aus Schnittstelle kopiert: IJavaModel
      Deletes the given elements, forcing the operation if necessary and specified.
      Angegeben von:
      delete in Schnittstelle IJavaModel
      Parameter:
      elements - the elements to delete
      force - a flag controlling whether underlying resources that are not in sync with the local file system will be tolerated
      monitor - a progress monitor
      Löst aus:
      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)
      Siehe auch:
    • equals

      public boolean equals(Object o)
      Beschreibung aus Klasse kopiert: 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.

      Setzt außer Kraft:
      equals in Klasse JavaElement
      Siehe auch:
    • getElementType

      public int getElementType()
      Beschreibung aus Schnittstelle kopiert: IJavaElement
      Returns this element's kind encoded as an integer. This is a handle-only method.
      Angegeben von:
      getElementType in Schnittstelle IJavaElement
      Gibt zurück:
      the kind of element; one of the constants declared in IJavaElement
      Siehe auch:
    • getHandleFromMemento

      public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner)
      Angegeben von:
      getHandleFromMemento in Klasse JavaElement
    • getHandleMemento

      protected void getHandleMemento(StringBuffer buff)
      Setzt außer Kraft:
      getHandleMemento in Klasse JavaElement
      Siehe auch:
    • getHandleMementoDelimiter

      protected char getHandleMementoDelimiter()
      Returns the char that marks the start of this handles contribution to a memento.
      Angegeben von:
      getHandleMementoDelimiter in Klasse JavaElement
    • getJavaProject

      public JavaProject getJavaProject(String projectName)
      Beschreibung aus Schnittstelle kopiert: IJavaModel
      Returns the Java project with the given name. The given name must be a valid path segment as defined by IPath.isValidSegment(String). This is a handle-only method. The project may or may not exist.
      Angegeben von:
      getJavaProject in Schnittstelle IJavaModel
      Parameter:
      projectName - the name of the Java project
      Gibt zurück:
      the Java project with the given name
      Siehe auch:
    • getJavaModel

      public JavaModel getJavaModel()
      Beschreibung aus Schnittstelle kopiert: IJavaElement
      Returns the Java model. This is a handle-only method.
      Angegeben von:
      getJavaModel in Schnittstelle IJavaElement
      Setzt außer Kraft:
      getJavaModel in Klasse JavaElement
      Gibt zurück:
      the Java model
      Siehe auch:
    • getJavaProject

      public IJavaProject getJavaProject(org.eclipse.core.resources.IResource resource)
      Returns the active Java project associated with the specified resource, or null if no Java project yet exists for the resource.
      Löst aus:
      IllegalArgumentException - if the given resource is not one of an IProject, IFolder, or IFile.
    • getJavaProjects

      public IJavaProject[] getJavaProjects() throws JavaModelException
      Beschreibung aus Schnittstelle kopiert: IJavaModel
      Returns the Java projects in this Java model, or an empty array if there are none.
      Angegeben von:
      getJavaProjects in Schnittstelle IJavaModel
      Gibt zurück:
      the Java projects in this Java model, or an empty array if there are none
      Löst aus:
      JavaModelException - if this request fails.
      Siehe auch:
    • getNonJavaResources

      public Object[] getNonJavaResources() throws JavaModelException
      Beschreibung aus Schnittstelle kopiert: 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).

      Angegeben von:
      getNonJavaResources in Schnittstelle IJavaModel
      Gibt zurück:
      an array of non-Java projects (IProjects) contained in the workspace.
      Löst aus:
      JavaModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource
      Siehe auch:
    • getPath

      public org.eclipse.core.runtime.IPath getPath()
      Beschreibung aus Schnittstelle kopiert: IJavaElement
      Returns the path to the innermost resource enclosing this element. If this element is not included in an external library, the path returned is the full, absolute path to the underlying resource, relative to the workbench. If this element is included in an external library, the path returned is the absolute path to the archive or to the folder in the file system. This is a handle-only method.
      Angegeben von:
      getPath in Schnittstelle IJavaElement
      Gibt zurück:
      the path to the innermost resource enclosing this element
    • resource

      public org.eclipse.core.resources.IResource resource(PackageFragmentRoot root)
      Angegeben von:
      resource in Klasse Openable
    • getUnderlyingResource

      public org.eclipse.core.resources.IResource getUnderlyingResource()
      Beschreibung aus Schnittstelle kopiert: IJavaElement
      Returns the smallest underlying resource that contains this element, or null if this element is not contained in a resource.
      Angegeben von:
      getUnderlyingResource in Schnittstelle IJavaElement
      Setzt außer Kraft:
      getUnderlyingResource in Klasse Openable
      Gibt zurück:
      the underlying resource, or null if none
      Siehe auch:
    • getWorkspace

      public org.eclipse.core.resources.IWorkspace getWorkspace()
      Returns the workbench associated with this object.
      Angegeben von:
      getWorkspace in Schnittstelle IJavaModel
      Gibt zurück:
      the workspace associated with this Java model
    • move

      public void move(IJavaElement[] elements, IJavaElement[] containers, IJavaElement[] siblings, String[] renamings, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Beschreibung aus Schnittstelle kopiert: 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.

      Angegeben von:
      move in Schnittstelle IJavaModel
      Parameter:
      elements - the elements to move
      containers - the container, or list of containers
      siblings - the list of siblings element any of which may be null; or null
      renamings - the list of new names any of which may be null; or null
      force - 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 collision
      monitor - a progress monitor
      Löst aus:
      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)
      Siehe auch:
    • refreshExternalArchives

      public void refreshExternalArchives(IJavaElement[] elementsScope, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Beschreibung aus Schnittstelle kopiert: 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.

      Since 3.7, a project refresh automatically triggers a refresh of external archives. Hence, this method doesn't need to be explicitly called after a project refresh.

      Angegeben von:
      refreshExternalArchives in Schnittstelle IJavaModel
      Parameter:
      elementsScope - - a collection of elements defining the scope of the refresh
      monitor - - a progress monitor used to report progress
      Löst aus:
      JavaModelException - in one of the corresponding situation:
      • an exception occurs while accessing project resources
      Siehe auch:
    • rename

      public void rename(IJavaElement[] elements, IJavaElement[] destinations, String[] renamings, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Beschreibung aus Schnittstelle kopiert: 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.
      Angegeben von:
      rename in Schnittstelle IJavaModel
      Parameter:
      elements - the elements to rename
      destinations - the container, or list of containers
      renamings - the list of new names
      force - 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 collision
      monitor - a progress monitor
      Löst aus:
      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)
      Siehe auch:
    • runOperation

      protected void runOperation(MultiOperation op, IJavaElement[] elements, IJavaElement[] siblings, String[] renamings, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Configures and runs the MultiOperation.
      Löst aus:
      JavaModelException
    • toStringInfo

      protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo)
      Beschreibung aus Klasse kopiert: JavaElement
      Debugging purposes
      Setzt außer Kraft:
      toStringInfo in Klasse JavaElement
      Parameter:
      showResolvedInfo - TODO
    • getTarget

      public static Object getTarget(org.eclipse.core.runtime.IPath path, boolean checkResourceExistence)
      Helper method - for the provided IPath, returns:
      • If the path corresponds to an internal file or folder, the IResource for that resource
      • If the path corresponds to an external folder linked through ExternalFoldersManager, the IFolder for that folder
      • If the path corresponds to an external library archive, the File for that archive
      • Can return null if checkResourceExistence is true and the entity referred to by the path does not exist on the file system
      Internal items must be referred to using container-relative paths.
    • getWorkspaceTarget

      public static org.eclipse.core.resources.IResource getWorkspaceTarget(org.eclipse.core.runtime.IPath path)
      Helper method - returns the IResource corresponding to the provided IPath, or null if no such resource exists.
    • getExternalTarget

      public static Object getExternalTarget(org.eclipse.core.runtime.IPath path, boolean checkResourceExistence)
      Helper method - returns either the linked IFolder or the File corresponding to the provided IPath. If checkResourceExistence is false, then the IFolder or File object is always returned, otherwise null is returned if it does not exist on the file system.
    • isFile

      public static boolean isFile(Object target)
      Helper method - returns whether an object is a file (i.e., it returns true to File.isFile().
    • isJimage

      public static boolean isJimage(File file)
    • isJmod

      public static boolean isJmod(File file)
    • getFile

      public static File getFile(Object target)
      Helper method - returns the File item if target is a file (i.e., the target returns true to File.isFile(). Otherwise returns null.
    • validateExistence

      protected org.eclipse.core.runtime.IStatus validateExistence(org.eclipse.core.resources.IResource underlyingResource)
      Angegeben von:
      validateExistence in Klasse Openable