01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.core;
11:
12: /**
13: * Common protocol for Java elements that have associated source code.
14: * This set consists of <code>IClassFile</code>, <code>ICompilationUnit</code>,
15: * <code>IPackageDeclaration</code>, <code>IImportDeclaration</code>,
16: * <code>IImportContainer</code>, <code>IType</code>, <code>IField</code>,
17: * <code>IMethod</code>, and <code>IInitializer</code>.
18: * <p>
19: * Note: For <code>IClassFile</code>, <code>IType</code> and other members
20: * derived from a binary type, the implementation returns source iff the
21: * element has attached source code.
22: * </p>
23: * <p>
24: * Source reference elements may be working copies if they were created from
25: * a compilation unit that is a working copy.
26: * </p>
27: * <p>
28: * This interface is not intended to be implemented by clients.
29: * </p>
30: *
31: * @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IProgressMonitor)
32: */
33: public interface ISourceReference {
34: /**
35: * Returns whether this element exists in the model.
36: *
37: * @return <code>true</code> if this element exists in the Java model
38: * @since 2.0
39: */
40: boolean exists();
41:
42: /**
43: * Returns the source code associated with this element.
44: * This extracts the substring from the source buffer containing this source
45: * element. This corresponds to the source range that would be returned by
46: * <code>getSourceRange</code>.
47: * <p>
48: * For class files, this returns the source of the entire compilation unit
49: * associated with the class file (if there is one).
50: * </p>
51: *
52: * @return the source code, or <code>null</code> if this element has no
53: * associated source code
54: * @exception JavaModelException if an exception occurs while accessing its corresponding resource
55: */
56: String getSource() throws JavaModelException;
57:
58: /**
59: * Returns the source range associated with this element.
60: * <p>
61: * For class files, this returns the range of the entire compilation unit
62: * associated with the class file (if there is one).
63: * </p>
64: * <p>
65: * If this element has no associated source code <code>null</code> is either returned,
66: * or a source range with a -1 offset and a 0 length.
67: * </p>
68: *
69: * @return the source range, or either <code>null</code> or [-1, 0] if this element has no
70: * associated source code
71: * @exception JavaModelException if an exception occurs while accessing its corresponding resource
72: */
73: ISourceRange getSourceRange() throws JavaModelException;
74: }
|