### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/Member.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java,v retrieving revision 1.42 diff -u -r1.42 Member.java --- model/org/eclipse/jdt/internal/core/Member.java 14 Dec 2005 17:28:06 -0000 1.42 +++ model/org/eclipse/jdt/internal/core/Member.java 24 Nov 2006 13:41:29 -0000 @@ -317,6 +317,12 @@ } } /** + * @see IMember#getTypeRoot() + */ +public ITypeRoot getTypeRoot() { + return (ITypeRoot) getAncestor(IJavaElement.TYPE_ROOT); +} +/** * @see IMember */ public boolean isBinary() { Index: model/org/eclipse/jdt/internal/core/ClassFile.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java,v retrieving revision 1.128 diff -u -r1.128 ClassFile.java --- model/org/eclipse/jdt/internal/core/ClassFile.java 6 Nov 2006 14:13:45 -0000 1.128 +++ model/org/eclipse/jdt/internal/core/ClassFile.java 24 Nov 2006 13:41:29 -0000 @@ -239,6 +239,16 @@ } return elt; } +/** + * @see ITypeRoot#findPrimaryType() + */ +public IType findPrimaryType() { + IType primaryType= getType(); + if (primaryType.exists()) { + return primaryType; + } + return null; +} public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException { return this.getType().getAttachedJavadoc(monitor); } @@ -327,6 +337,12 @@ return this; } /** + * @see IMember#getTypeRoot() + */ +public ITypeRoot getTypeRoot() { + return this; +} +/** * A class file has a corresponding resource unless it is contained * in a jar. * Index: model/org/eclipse/jdt/internal/core/CompilationUnit.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java,v retrieving revision 1.235 diff -u -r1.235 CompilationUnit.java --- model/org/eclipse/jdt/internal/core/CompilationUnit.java 14 Nov 2006 16:38:47 -0000 1.235 +++ model/org/eclipse/jdt/internal/core/CompilationUnit.java 24 Nov 2006 13:41:29 -0000 @@ -716,6 +716,12 @@ return imports; } /** + * @see IMember#getTypeRoot() + */ +public ITypeRoot getTypeRoot() { + return this; +} +/** * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName() */ public char[] getMainTypeName(){ @@ -880,6 +886,12 @@ return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/, monitor); } /** + * @see ITypeRoot#getWorkingCopy(WorkingCopyOwner, IProgressMonitor) + */ +public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException { + return getWorkingCopy(workingCopyOwner, null, monitor); +} +/** * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor) * @deprecated */ Index: dom/org/eclipse/jdt/core/dom/ASTParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java,v retrieving revision 1.68 diff -u -r1.68 ASTParser.java --- dom/org/eclipse/jdt/core/dom/ASTParser.java 16 Nov 2006 17:43:52 -0000 1.68 +++ dom/org/eclipse/jdt/core/dom/ASTParser.java 24 Nov 2006 13:41:27 -0000 @@ -17,6 +17,7 @@ import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.ITypeRoot; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; @@ -154,14 +155,9 @@ private char[] rawSource = null; /** - * Java mode compilation unit supplying the source. + * Java model class file or compilation unit supplying the source. */ - private ICompilationUnit compilationUnitSource = null; - - /** - * Java model class file supplying the source. - */ - private IClassFile classFileSource = null; + private ITypeRoot typeRoot = null; /** * Character-based offset into the source string where parsing is to @@ -218,8 +214,7 @@ private void initializeDefaults() { this.astKind = K_COMPILATION_UNIT; this.rawSource = null; - this.classFileSource = null; - this.compilationUnitSource = null; + this.typeRoot = null; this.resolveBindings = false; this.sourceLength = -1; this.sourceOffset = 0; @@ -452,9 +447,8 @@ */ public void setSource(char[] source) { this.rawSource = source; - // clear the others - this.compilationUnitSource = null; - this.classFileSource = null; + // clear the type root + this.typeRoot = null; } /** @@ -467,16 +461,7 @@ * is to be parsed, or null if none */ public void setSource(ICompilationUnit source) { - this.compilationUnitSource = source; - // clear the others - this.rawSource = null; - this.classFileSource = null; - if (source != null) { - this.project = source.getJavaProject(); - Map options = this.project.getOptions(true); - options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags - this.compilerOptions = options; - } + setTypeRoot(source); } /** @@ -491,10 +476,16 @@ * is to be parsed, or null if none */ public void setSource(IClassFile source) { - this.classFileSource = source; - // clear the others + setTypeRoot(source); + } + + /* (non-Javadoc) + * Sets the source code to be parsed. + */ + void setTypeRoot(ITypeRoot source) { + this.typeRoot = source; + // clear the raw source this.rawSource = null; - this.compilationUnitSource = null; if (source != null) { this.project = source.getJavaProject(); Map options = this.project.getOptions(true); @@ -622,9 +613,7 @@ ASTNode result = null; if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$ try { - if ((this.rawSource == null) - && (this.compilationUnitSource == null) - && (this.classFileSource == null)) { + if (this.rawSource == null && this.typeRoot == null) { throw new IllegalStateException("source not specified"); //$NON-NLS-1$ } result = internalCreateAST(monitor); @@ -782,28 +771,28 @@ try { NodeSearcher searcher = null; org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null; - IJavaElement element = null; - if (this.compilationUnitSource != null) { - /* - * this.compilationUnitSource is an instance of org.eclipse.jdt.internal.core.CompilationUnit that implements - * both org.eclipse.jdt.core.ICompilationUnit and org.eclipse.jdt.internal.compiler.env.ICompilationUnit - */ - sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.compilationUnitSource; - /* - * use a BasicCompilation that caches the source instead of using the compilationUnitSource directly - * (if it is a working copy, the source can change between the parse and the AST convertion) - * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632) - */ - sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project); - element = this.compilationUnitSource; - } else if (this.classFileSource != null) { + WorkingCopyOwner wcOwner = this.workingCopyOwner; + if (this.typeRoot instanceof ICompilationUnit) { + /* + * this.compilationUnitSource is an instance of org.eclipse.jdt.internal.core.CompilationUnit that implements + * both org.eclipse.jdt.core.ICompilationUnit and org.eclipse.jdt.internal.compiler.env.ICompilationUnit + */ + sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.typeRoot; + /* + * use a BasicCompilation that caches the source instead of using the compilationUnitSource directly + * (if it is a working copy, the source can change between the parse and the AST convertion) + * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632) + */ + sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project); + wcOwner = ((ICompilationUnit) this.typeRoot).getOwner(); + } else if (this.typeRoot instanceof IClassFile) { try { - String sourceString = this.classFileSource.getSource(); + String sourceString = this.typeRoot.getSource(); if (sourceString == null) { throw new IllegalStateException(); } - PackageFragment packageFragment = (PackageFragment) this.classFileSource.getParent(); - BinaryType type = (BinaryType) this.classFileSource.getType(); + PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent(); + BinaryType type = (BinaryType) this.typeRoot.findPrimaryType(); IBinaryType binaryType = (IBinaryType) type.getElementInfo(); // file name is used to recreate the Java element, so it has to be the toplevel .class file name char[] fileName = binaryType.getFileName(); @@ -817,7 +806,6 @@ fileName = newFileName; } sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project); - element = this.classFileSource; } catch(JavaModelException e) { // an error occured accessing the java element throw new IllegalStateException(); @@ -865,10 +853,10 @@ this.apiLevel, this.compilerOptions, needToResolveBindings, - this.compilationUnitSource == null ? this.workingCopyOwner : this.compilationUnitSource.getOwner(), + wcOwner, needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null, monitor); - result.setJavaElement(element); + result.setTypeRoot(this.typeRoot); return result; } finally { if (compilationUnitDeclaration != null && this.resolveBindings) { Index: dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java,v retrieving revision 1.121 diff -u -r1.121 CompilationUnitResolver.java --- dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 17 Jul 2006 11:40:18 -0000 1.121 +++ dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 24 Nov 2006 13:41:27 -0000 @@ -362,7 +362,7 @@ // convert AST CompilationUnit node = convert(compilationUnitDeclaration, parser.scanner.getSource(), apiLevel, options, false/*don't resolve binding*/, null/*no owner needed*/, null/*no binding table needed*/, monitor); - node.setJavaElement(compilationUnits[i]); + node.setTypeRoot(compilationUnits[i]); // accept AST astRequestor.acceptAST(compilationUnits[i], node); @@ -703,7 +703,7 @@ ast.setBindingResolver(resolver); converter.setAST(ast); CompilationUnit compilationUnit = converter.convert(unit, contents); - compilationUnit.setJavaElement(source); + compilationUnit.setTypeRoot(source); compilationUnit.setLineEndTable(compilationResult.getLineSeparatorPositions()); ast.setDefaultNodeFlag(0); ast.setOriginalModificationCount(ast.modificationCount()); Index: dom/org/eclipse/jdt/core/dom/AST.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java,v retrieving revision 1.151 diff -u -r1.151 AST.java --- dom/org/eclipse/jdt/core/dom/AST.java 15 Aug 2006 15:59:12 -0000 1.151 +++ dom/org/eclipse/jdt/core/dom/AST.java 24 Nov 2006 13:41:26 -0000 @@ -269,7 +269,7 @@ CompilationUnit unit = converter.convert(compilationUnitDeclaration, source); unit.setLineEndTable(compilationUnitDeclaration.compilationResult.getLineSeparatorPositions()); - unit.setJavaElement(workingCopy); + unit.setTypeRoot(workingCopy); ast.setDefaultNodeFlag(savedDefaultNodeFlag); return unit; } Index: dom/org/eclipse/jdt/core/dom/CompilationUnit.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java,v retrieving revision 1.85 diff -u -r1.85 CompilationUnit.java --- dom/org/eclipse/jdt/core/dom/CompilationUnit.java 24 Nov 2006 01:32:03 -0000 1.85 +++ dom/org/eclipse/jdt/core/dom/CompilationUnit.java 24 Nov 2006 13:41:27 -0000 @@ -18,6 +18,7 @@ import java.util.Map; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.ITypeRoot; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.parser.Scanner; import org.eclipse.jdt.internal.compiler.util.Util; @@ -124,11 +125,10 @@ private DefaultCommentMapper commentMapper = null; /** - * The Java element (an org.eclipse.jdt.core.ICompilationUnit or an org.eclipse.jdt.core.IClassFile) - * this compilation unit was created from, or null if it was not created from a Java element. - * @since 3.1 + * The Java type root (an org.eclipse.jdt.core.ICompilationUnit or an org.eclipse.jdt.core.IClassFile) + * this compilation unit was created from, or null if it was not created from a Java type root. */ - private IJavaElement element = null; + private ITypeRoot typeRoot = null; /** * The list of import declarations in textual order order; @@ -493,7 +493,7 @@ * @since 3.1 */ public IJavaElement getJavaElement() { - return this.element; + return this.typeRoot; } /** @@ -611,6 +611,17 @@ public IProblem[] getProblems() { return this.problems; } + + /** + * The Java type root (a {@link org.eclipse.jdt.core.ICompilationUnit compilation unit} or a {@link org.eclipse.jdt.core.IClassFile class file}) + * this compilation unit was created from, or null if it was not created from a Java type root. + * + * @return the Java type root this compilation unit was created from, or null if none + * @since 3.3 + */ + public ITypeRoot getTypeRoot() { + return this.typeRoot; + } /** * Returns the live list of nodes for the import declarations of this @@ -932,16 +943,15 @@ this.optionalCommentList = Collections.unmodifiableList(commentList); } } - + /** - * Sets the Java element (an org.eclipse.jdt.core.ICompilationUnit or an org.eclipse.jdt.core.IClassFile) - * this compilation unit was created from, or null if it was not created from a Java element. + * Sets the Java type root (a {@link org.eclipse.jdt.core.ICompilationUnit compilation unit} or a {@link org.eclipse.jdt.core.IClassFile class file}) + * this compilation unit was created from, or null if it was not created from a Java type root. * - * @param element the Java element this compilation unit was created from - * @since 3.1 + * @param typeRoot the Java type root this compilation unit was created from */ - void setJavaElement(IJavaElement element) { - this.element = element; + void setTypeRoot(ITypeRoot typeRoot) { + this.typeRoot = typeRoot; } /** Index: dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java,v retrieving revision 1.9 diff -u -r1.9 ImportRewrite.java --- dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java 24 Nov 2006 01:32:06 -0000 1.9 +++ dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java 24 Nov 2006 13:41:28 -0000 @@ -21,6 +21,7 @@ import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IImportDeclaration; +import org.eclipse.jdt.core.ITypeRoot; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.compiler.CharOperation; @@ -183,7 +184,8 @@ if (astRoot == null) { throw new IllegalArgumentException("AST must not be null"); //$NON-NLS-1$ } - if (!(astRoot.getJavaElement() instanceof ICompilationUnit)) { + ITypeRoot typeRoot = astRoot.getTypeRoot(); + if (!(typeRoot instanceof ICompilationUnit)) { throw new IllegalArgumentException("AST must have been constructed from a Java element"); //$NON-NLS-1$ } List existingImport= null; @@ -202,7 +204,7 @@ existingImport.add(buf.toString()); } } - return new ImportRewrite((ICompilationUnit) astRoot.getJavaElement(), astRoot, existingImport); + return new ImportRewrite((ICompilationUnit) typeRoot, astRoot, existingImport); } private ImportRewrite(ICompilationUnit cu, CompilationUnit astRoot, List existingImports) { Index: dom/org/eclipse/jdt/core/dom/rewrite/ASTRewrite.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ASTRewrite.java,v retrieving revision 1.29 diff -u -r1.29 ASTRewrite.java --- dom/org/eclipse/jdt/core/dom/rewrite/ASTRewrite.java 23 Jun 2006 13:44:54 -0000 1.29 +++ dom/org/eclipse/jdt/core/dom/rewrite/ASTRewrite.java 24 Nov 2006 13:41:28 -0000 @@ -15,6 +15,7 @@ import java.util.Map; import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.ITypeRoot; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.AST; @@ -231,10 +232,11 @@ throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit"); //$NON-NLS-1$ } CompilationUnit astRoot= (CompilationUnit) root; - if (!(astRoot.getJavaElement() instanceof ICompilationUnit)) { + ITypeRoot typeRoot = astRoot.getTypeRoot(); + if (!(typeRoot instanceof ICompilationUnit)) { throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit"); //$NON-NLS-1$ } - ICompilationUnit cu= (ICompilationUnit) astRoot.getJavaElement(); + ICompilationUnit cu= (ICompilationUnit) typeRoot; char[] content= cu.getBuffer().getCharacters(); LineInformation lineInfo= LineInformation.create(astRoot); Index: model/org/eclipse/jdt/core/IWorkingCopy.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IWorkingCopy.java,v retrieving revision 1.41 diff -u -r1.41 IWorkingCopy.java --- model/org/eclipse/jdt/core/IWorkingCopy.java 29 Sep 2006 17:13:57 -0000 1.41 +++ model/org/eclipse/jdt/core/IWorkingCopy.java 24 Nov 2006 13:41:29 -0000 @@ -172,7 +172,7 @@ * @return the found primary type of this compilation unit, or null if no such a type exists * @since 2.0 * - * @deprecated Use {@link ICompilationUnit#findPrimaryType()} instead. + * @deprecated Use {@link ITypeRoot#findPrimaryType()} instead. */ IType findPrimaryType(); Index: model/org/eclipse/jdt/core/IMember.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMember.java,v retrieving revision 1.23 diff -u -r1.23 IMember.java --- model/org/eclipse/jdt/core/IMember.java 10 May 2006 18:03:42 -0000 1.23 +++ model/org/eclipse/jdt/core/IMember.java 24 Nov 2006 13:41:28 -0000 @@ -124,6 +124,14 @@ */ int getOccurrenceCount(); /** + * Returns the Java type root in which this member is declared. + * This is a handle-only method. + * + * @return the Java type root in which this member is declared. + * @since 3.3 + */ +ITypeRoot getTypeRoot(); +/** * Returns the local or anonymous type declared in this source member with the given simple name and/or * with the specified position relative to the order they are defined in the source. * The name is empty if it is an anonymous type. Index: model/org/eclipse/jdt/core/ICompilationUnit.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ICompilationUnit.java,v retrieving revision 1.58 diff -u -r1.58 ICompilationUnit.java --- model/org/eclipse/jdt/core/ICompilationUnit.java 6 Nov 2006 14:13:47 -0000 1.58 +++ model/org/eclipse/jdt/core/ICompilationUnit.java 24 Nov 2006 13:41:28 -0000 @@ -30,7 +30,7 @@ * This interface is not intended to be implemented by clients. *

*/ -public interface ICompilationUnit extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation, ICodeAssist { +public interface ICompilationUnit extends ITypeRoot, IWorkingCopy, ISourceManipulation { /** * Constant indicating that a reconcile operation should not return an AST. * @since 3.0 @@ -254,14 +254,6 @@ */ IJavaElement[] findElements(IJavaElement element); /** - * Finds the primary type of this compilation unit (that is, the type with the same name as the - * compilation unit), or null if no such a type exists. - * - * @return the found primary type of this compilation unit, or null if no such a type exists - * @since 3.0 - */ -IType findPrimaryType(); -/** * Finds the working copy for this compilation unit, given a {@link WorkingCopyOwner}. * If no working copy has been created for this compilation unit associated with this * working copy owner, returns null. @@ -286,20 +278,6 @@ */ IType[] getAllTypes() throws JavaModelException; /** - * Returns the smallest element within this compilation unit that - * includes the given source position (that is, a method, field, etc.), or - * null if there is no element other than the compilation - * unit itself at the given position, or if the given position is not - * within the source range of this compilation unit. - * - * @param position a source position inside the compilation unit - * @return the innermost Java element enclosing a given source position or null - * if none (excluding the compilation unit). - * @throws JavaModelException if the compilation unit does not exist or if an - * exception occurs while accessing its corresponding resource - */ -IJavaElement getElementAt(int position) throws JavaModelException; -/** * Returns the first import declaration in this compilation unit with the given name. * This is a handle-only method. The import declaration may or may not exist. This * is a convenience method - imports can also be accessed from a compilation unit's Index: model/org/eclipse/jdt/core/IJavaElement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElement.java,v retrieving revision 1.33 diff -u -r1.33 IJavaElement.java --- model/org/eclipse/jdt/core/IJavaElement.java 29 Mar 2006 03:08:47 -0000 1.33 +++ model/org/eclipse/jdt/core/IJavaElement.java 24 Nov 2006 13:41:28 -0000 @@ -36,95 +36,102 @@ /** * Constant representing a Java model (workspace level object). - * A Java element with this type can be safely cast to IJavaModel. + * A Java element with this type can be safely cast to {@link IJavaModel}. */ int JAVA_MODEL = 1; /** * Constant representing a Java project. - * A Java element with this type can be safely cast to IJavaProject. + * A Java element with this type can be safely cast to {@link IJavaProject}. */ int JAVA_PROJECT = 2; /** * Constant representing a package fragment root. - * A Java element with this type can be safely cast to IPackageFragmentRoot. + * A Java element with this type can be safely cast to {@link IPackageFragmentRoot}. */ int PACKAGE_FRAGMENT_ROOT = 3; /** * Constant representing a package fragment. - * A Java element with this type can be safely cast to IPackageFragment. + * A Java element with this type can be safely cast to {@link IPackageFragment}. */ int PACKAGE_FRAGMENT = 4; /** * Constant representing a Java compilation unit. - * A Java element with this type can be safely cast to ICompilationUnit. + * A Java element with this type can be safely cast to {@link ICompilationUnit}. */ int COMPILATION_UNIT = 5; /** * Constant representing a class file. - * A Java element with this type can be safely cast to IClassFile. + * A Java element with this type can be safely cast to {@link IClassFile}. */ int CLASS_FILE = 6; /** * Constant representing a type (a class or interface). - * A Java element with this type can be safely cast to IType. + * A Java element with this type can be safely cast to {@link IType}. */ int TYPE = 7; /** * Constant representing a field. - * A Java element with this type can be safely cast to IField. + * A Java element with this type can be safely cast to {@link IField}. */ int FIELD = 8; /** * Constant representing a method or constructor. - * A Java element with this type can be safely cast to IMethod. + * A Java element with this type can be safely cast to {@link IMethod}. */ int METHOD = 9; /** * Constant representing a stand-alone instance or class initializer. - * A Java element with this type can be safely cast to IInitializer. + * A Java element with this type can be safely cast to {@link IInitializer}. */ int INITIALIZER = 10; /** * Constant representing a package declaration within a compilation unit. - * A Java element with this type can be safely cast to IPackageDeclaration. + * A Java element with this type can be safely cast to {@link IPackageDeclaration}. */ int PACKAGE_DECLARATION = 11; /** * Constant representing all import declarations within a compilation unit. - * A Java element with this type can be safely cast to IImportContainer. + * A Java element with this type can be safely cast to {@link IImportContainer}. */ int IMPORT_CONTAINER = 12; /** * Constant representing an import declaration within a compilation unit. - * A Java element with this type can be safely cast to IImportDeclaration. + * A Java element with this type can be safely cast to {@link IImportDeclaration}. */ int IMPORT_DECLARATION = 13; /** * Constant representing a local variable declaration. - * A Java element with this type can be safely cast to ILocalVariable. + * A Java element with this type can be safely cast to {@link ILocalVariable}. * @since 3.0 */ int LOCAL_VARIABLE = 14; /** * Constant representing a type parameter declaration. - * A Java element with this type can be safely cast to ITypeParameter. + * A Java element with this type can be safely cast to {@link ITypeParameter}. * @since 3.1 */ int TYPE_PARAMETER = 15; + + /** + * Constant representing a Java type root. + * A Java element with this type can be safely cast to {@link ITypeRoot}. + * @since 3.3 + */ + int TYPE_ROOT = 16; /** * Returns whether this Java element exists in the model. Index: model/org/eclipse/jdt/core/IClassFile.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClassFile.java,v retrieving revision 1.21 diff -u -r1.21 IClassFile.java --- model/org/eclipse/jdt/core/IClassFile.java 29 Sep 2006 17:13:57 -0000 1.21 +++ model/org/eclipse/jdt/core/IClassFile.java 24 Nov 2006 13:41:28 -0000 @@ -32,7 +32,7 @@ * @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, IProgressMonitor) */ -public interface IClassFile extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist { +public interface IClassFile extends ITypeRoot { /** * Changes this class file handle into a working copy. A new {@link IBuffer} is @@ -80,21 +80,6 @@ ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException; /** - * Returns the smallest element within this class file that - * includes the given source position (a method, field, etc.), or - * null if there is no element other than the class file - * itself at the given position, or if the given position is not - * within the source range of this class file. - * - * @param position a source position inside the class file - * @return the innermost Java element enclosing a given source position or null - * if none (excluding the class file). - * - * @exception JavaModelException if this element does not exist or if an - * exception occurs while accessing its corresponding resource - */ -IJavaElement getElementAt(int position) throws JavaModelException; -/** * Returns the type contained in this class file. * * @return the type contained in this class file @@ -105,29 +90,6 @@ IType getType() throws JavaModelException; /** * Returns a working copy on the source associated with this class file using the given - * owner to create the buffer, or null if there is no source associated - * with the class file. - *

- * The buffer will be automatically initialized with the source of the class file - * upon creation. - *

- * The only valid operations on this working copy are getBuffer() or getPrimary(). - * - * @param owner the owner that creates a buffer that is used to get the content of the working copy - * or null if the primary owner should be used - * @param monitor a progress monitor used to report progress while opening this compilation unit - * or null if no progress should be reported - * @return a a working copy on the source associated with this class file - * @exception JavaModelException if the source of this class file can - * not be determined. Reasons include: - *

- * @since 3.0 - */ -ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException; -/** - * Returns a working copy on the source associated with this class file using the given * factory to create the buffer, or null if there is no source associated * with the class file. *

@@ -147,7 +109,7 @@ *

  • This class file does not exist (ELEMENT_DOES_NOT_EXIST)
  • * * @since 2.0 - * @deprecated Use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead + * @deprecated Use {@link ITypeRoot#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead */ IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException; /** Index: model/org/eclipse/jdt/core/ITypeRoot.java =================================================================== RCS file: model/org/eclipse/jdt/core/ITypeRoot.java diff -N model/org/eclipse/jdt/core/ITypeRoot.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ model/org/eclipse/jdt/core/ITypeRoot.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core; + +import org.eclipse.core.runtime.IProgressMonitor; + + +/** + * Represents an entire Java type root (either an ICompilationUnit + * or an IClassFile). + * + *

    + * This interface is not intended to be implemented by clients. + *

    + * + * @see ICompilationUnit + * @see IClassFile + * @since 3.3 + */ +public interface ITypeRoot extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist { + +/** + * Finds the primary type of this Java type root (that is, the type with the same name as the + * compilation unit, or the type of a class file), or null if no such a type exists. + * + * @return the found primary type of this Java type root, or null if no such a type exists + */ +IType findPrimaryType(); + +/** + * Returns the smallest element within this Java type root that + * includes the given source position (that is, a method, field, etc.), or + * null if there is no element other than the Java type root + * itself at the given position, or if the given position is not + * within the source range of the source of this Java type root. + * + * @param position a source position inside the Java type root + * @return the innermost Java element enclosing a given source position or null + * if none (excluding the Java type root). + * @throws JavaModelException if the Java type root does not exist or if an + * exception occurs while accessing its corresponding resource + */ +IJavaElement getElementAt(int position) throws JavaModelException; + +/** + * Returns a shared working copy on this compilation unit or class file using the given working copy owner to create + * the buffer. If this is already a working copy of the given owner, the element itself is returned. + * This API can only answer an already existing working copy if it is based on the same + * original Java type root AND was using the same working copy owner (that is, as defined by {@link Object#equals}). + *

    + * The life time of a shared working copy is as follows: + *

    + * So users of this method must discard exactly once the working copy. + *

    + * Note that the working copy owner will be used for the life time of the shared working copy, that is if the + * working copy is closed then reopened, this owner will be used. + * The buffer will be automatically initialized with the original's Java type root content upon creation. + *

    + * When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this + * working copy. + *

    + * Since 2.1, a working copy can be created on a not-yet existing compilation + * unit. In particular, such a working copy can then be committed in order to create + * the corresponding compilation unit. + *

    + * Note that possible problems of this working copy are not reported using this method. + *

    + * + * @param owner the working copy owner that creates a buffer that is used to get the content + * of the working copy + * @param monitor a progress monitor used to report progress while opening this compilation unit + * or null if no progress should be reported + * @throws JavaModelException if the contents of this element can + * not be determined. + * @return a new working copy of this Java type root using the given owner to create + * the buffer, or this Java type root if it is already a working copy + */ +ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException; + +}