KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > ITypeRoot


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.core;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14
15
16 /**
17  * Represents an entire Java type root (either an <code>ICompilationUnit</code>
18  * or an <code>IClassFile</code>).
19  *
20  * <p>
21  * This interface is not intended to be implemented by clients.
22  * </p>
23  *
24  * @see ICompilationUnit Note that methods {@link #findPrimaryType()} and {@link #getElementAt(int)}
25  * were already implemented in this interface respectively since version 3.0 and version 1.0.
26  * @see IClassFile Note that method {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}
27  * was already implemented in this interface since version 3.0.
28  * @since 3.3
29  */

30 public interface ITypeRoot extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist {
31
32 /**
33  * Finds the primary type of this Java type root (that is, the type with the same name as the
34  * compilation unit, or the type of a class file), or <code>null</code> if no such a type exists.
35  *
36  * @return the found primary type of this Java type root, or <code>null</code> if no such a type exists
37  */

38 IType findPrimaryType();
39
40 /**
41  * Returns the smallest element within this Java type root that
42  * includes the given source position (that is, a method, field, etc.), or
43  * <code>null</code> if there is no element other than the Java type root
44  * itself at the given position, or if the given position is not
45  * within the source range of the source of this Java type root.
46  *
47  * @param position a source position inside the Java type root
48  * @return the innermost Java element enclosing a given source position or <code>null</code>
49  * if none (excluding the Java type root).
50  * @throws JavaModelException if the Java type root does not exist or if an
51  * exception occurs while accessing its corresponding resource
52  */

53 IJavaElement getElementAt(int position) throws JavaModelException;
54     
55 /**
56  * Returns a shared working copy on this compilation unit or class file using the given working copy owner to create
57  * the buffer. If this is already a working copy of the given owner, the element itself is returned.
58  * This API can only answer an already existing working copy if it is based on the same
59  * original Java type root AND was using the same working copy owner (that is, as defined by {@link Object#equals}).
60  * <p>
61  * The life time of a shared working copy is as follows:
62  * <ul>
63  * <li>The first call to {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)}
64  * creates a new working copy for this element</li>
65  * <li>Subsequent calls increment an internal counter.</li>
66  * <li>A call to {@link ICompilationUnit#discardWorkingCopy()} decrements the internal counter.</li>
67  * <li>When this counter is 0, the working copy is discarded.
68  * </ul>
69  * So users of this method must discard exactly once the working copy.
70  * <p>
71  * Note that the working copy owner will be used for the life time of the shared working copy, that is if the
72  * working copy is closed then reopened, this owner will be used.
73  * The buffer will be automatically initialized with the original's Java type root content upon creation.
74  * <p>
75  * When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this
76  * working copy.
77  * </p><p>
78  * A working copy can be created on a not-yet existing compilation unit.
79  * In particular, such a working copy can then be committed in order to create
80  * the corresponding compilation unit.
81  * </p><p>
82  * Note that possible problems of this working copy are reported using this method only
83  * if the given working copy owner returns a problem requestor for this working copy
84  * (see {@link WorkingCopyOwner#getProblemRequestor(ICompilationUnit)}).
85  * </p>
86  *
87  * @param owner the working copy owner that creates a buffer that is used to get the content
88  * of the working copy
89  * @param monitor a progress monitor used to report progress while opening this compilation unit
90  * or <code>null</code> if no progress should be reported
91  * @throws JavaModelException if the contents of this element can
92  * not be determined.
93  * @return a new working copy of this Java type root using the given owner to create
94  * the buffer, or this Java type root if it is already a working copy
95  */

96 ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
97
98 }
99
Popular Tags