View | Details | Raw Unified | Return to bug 125504 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/Member.java (+6 lines)
Lines 317-322 Link Here
317
	}
317
	}
318
}
318
}
319
/**
319
/**
320
 * @see IMember#getTypeRoot()
321
 */
322
public ITypeRoot getTypeRoot() {
323
	return (ITypeRoot) getAncestor(IJavaElement.TYPE_ROOT);
324
}
325
/**
320
 * @see IMember
326
 * @see IMember
321
 */
327
 */
322
public boolean isBinary() {
328
public boolean isBinary() {
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (+16 lines)
Lines 239-244 Link Here
239
	}
239
	}
240
	return elt;
240
	return elt;
241
}
241
}
242
/**
243
 * @see ITypeRoot#findPrimaryType()
244
 */
245
public IType findPrimaryType() {
246
	IType primaryType= getType();
247
	if (primaryType.exists()) {
248
		return primaryType;
249
	}
250
	return null;
251
}
242
public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException {
252
public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException {
243
	return this.getType().getAttachedJavadoc(monitor);
253
	return this.getType().getAttachedJavadoc(monitor);
244
}
254
}
Lines 327-332 Link Here
327
	return this;
337
	return this;
328
}
338
}
329
/**
339
/**
340
 * @see IMember#getTypeRoot()
341
 */
342
public ITypeRoot getTypeRoot() {
343
	return this;
344
}
345
/**
330
 * A class file has a corresponding resource unless it is contained
346
 * A class file has a corresponding resource unless it is contained
331
 * in a jar.
347
 * in a jar.
332
 *
348
 *
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (+12 lines)
Lines 716-721 Link Here
716
	return imports;
716
	return imports;
717
}
717
}
718
/**
718
/**
719
 * @see IMember#getTypeRoot()
720
 */
721
public ITypeRoot getTypeRoot() {
722
	return this;
723
}
724
/**
719
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
725
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
720
 */
726
 */
721
public char[] getMainTypeName(){
727
public char[] getMainTypeName(){
Lines 880-885 Link Here
880
	return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/, monitor);
886
	return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/, monitor);
881
}
887
}
882
/**
888
/**
889
 * @see ITypeRoot#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)
890
 */
891
public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException {
892
	return getWorkingCopy(workingCopyOwner, null, monitor);
893
}
894
/**
883
 * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
895
 * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
884
 * @deprecated
896
 * @deprecated
885
 */
897
 */
(-)dom/org/eclipse/jdt/core/dom/ASTParser.java (-49 / +37 lines)
Lines 17-22 Link Here
17
import org.eclipse.jdt.core.IClassFile;
17
import org.eclipse.jdt.core.IClassFile;
18
import org.eclipse.jdt.core.ICompilationUnit;
18
import org.eclipse.jdt.core.ICompilationUnit;
19
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.ITypeRoot;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.JavaCore;
22
import org.eclipse.jdt.core.JavaCore;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.JavaModelException;
Lines 154-167 Link Here
154
    private char[] rawSource = null;
155
    private char[] rawSource = null;
155
    
156
    
156
    /**
157
    /**
157
     * Java mode compilation unit supplying the source.
158
     * Java model class file or compilation unit supplying the source.
158
     */
159
     */
159
    private ICompilationUnit compilationUnitSource = null;
160
    private ITypeRoot typeRoot = null;
160
    
161
    /**
162
     * Java model class file supplying the source.
163
     */
164
    private IClassFile classFileSource = null;
165
    
161
    
166
    /**
162
    /**
167
     * Character-based offset into the source string where parsing is to
163
     * Character-based offset into the source string where parsing is to
Lines 218-225 Link Here
218
	private void initializeDefaults() {
214
	private void initializeDefaults() {
219
		this.astKind = K_COMPILATION_UNIT;
215
		this.astKind = K_COMPILATION_UNIT;
220
		this.rawSource = null;
216
		this.rawSource = null;
221
		this.classFileSource = null;
217
		this.typeRoot = null;
222
		this.compilationUnitSource = null;
223
		this.resolveBindings = false;
218
		this.resolveBindings = false;
224
		this.sourceLength = -1;
219
		this.sourceLength = -1;
225
		this.sourceOffset = 0;
220
		this.sourceOffset = 0;
Lines 452-460 Link Here
452
     */
447
     */
453
	public void setSource(char[] source) {
448
	public void setSource(char[] source) {
454
		this.rawSource = source;
449
		this.rawSource = source;
455
		// clear the others
450
		// clear the type root
456
		this.compilationUnitSource = null;
451
		this.typeRoot = null;
457
		this.classFileSource = null;
458
	}
452
	}
459
453
460
	/**
454
	/**
Lines 467-482 Link Here
467
     * is to be parsed, or <code>null</code> if none
461
     * is to be parsed, or <code>null</code> if none
468
      */
462
      */
469
	public void setSource(ICompilationUnit source) {
463
	public void setSource(ICompilationUnit source) {
470
		this.compilationUnitSource = source;
464
		setTypeRoot(source);
471
		// clear the others
472
		this.rawSource = null;
473
		this.classFileSource = null;
474
		if (source != null) {
475
			this.project = source.getJavaProject();
476
			Map options = this.project.getOptions(true);
477
			options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
478
			this.compilerOptions = options;
479
		}
480
	}
465
	}
481
	
466
	
482
	/**
467
	/**
Lines 491-500 Link Here
491
     * is to be parsed, or <code>null</code> if none
476
     * is to be parsed, or <code>null</code> if none
492
     */
477
     */
493
	public void setSource(IClassFile source) {
478
	public void setSource(IClassFile source) {
494
		this.classFileSource = source;
479
		setTypeRoot(source);
495
		// clear the others
480
	}
481
482
	/* (non-Javadoc)
483
	 * Sets the source code to be parsed.
484
	 */
485
	void setTypeRoot(ITypeRoot source) {
486
		this.typeRoot = source;
487
		// clear the raw source
496
		this.rawSource = null;
488
		this.rawSource = null;
497
		this.compilationUnitSource = null;
498
		if (source != null) {
489
		if (source != null) {
499
			this.project = source.getJavaProject();
490
			this.project = source.getJavaProject();
500
			Map options = this.project.getOptions(true);
491
			Map options = this.project.getOptions(true);
Lines 622-630 Link Here
622
	   ASTNode result = null;
613
	   ASTNode result = null;
623
	   if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$
614
	   if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$
624
		try {
615
		try {
625
			if ((this.rawSource == null)
616
			if (this.rawSource == null && this.typeRoot == null) {
626
		   	  && (this.compilationUnitSource == null)
627
		   	  && (this.classFileSource == null)) {
628
		   	  throw new IllegalStateException("source not specified"); //$NON-NLS-1$
617
		   	  throw new IllegalStateException("source not specified"); //$NON-NLS-1$
629
		   }
618
		   }
630
	   		result = internalCreateAST(monitor);
619
	   		result = internalCreateAST(monitor);
Lines 782-809 Link Here
782
				try {
771
				try {
783
					NodeSearcher searcher = null;
772
					NodeSearcher searcher = null;
784
					org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null;
773
					org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null;
785
					IJavaElement element = null;
774
					WorkingCopyOwner wcOwner = this.workingCopyOwner;
786
					if (this.compilationUnitSource != null) {
775
					if (this.typeRoot instanceof ICompilationUnit) {
787
						/*
776
							/*
788
						 * this.compilationUnitSource is an instance of org.eclipse.jdt.internal.core.CompilationUnit that implements
777
							 * this.compilationUnitSource is an instance of org.eclipse.jdt.internal.core.CompilationUnit that implements
789
						 * both org.eclipse.jdt.core.ICompilationUnit and org.eclipse.jdt.internal.compiler.env.ICompilationUnit
778
							 * both org.eclipse.jdt.core.ICompilationUnit and org.eclipse.jdt.internal.compiler.env.ICompilationUnit
790
						 */ 
779
							 */ 
791
						sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.compilationUnitSource;
780
							sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.typeRoot;
792
						/*
781
							/*
793
						 * use a BasicCompilation that caches the source instead of using the compilationUnitSource directly
782
							 * use a BasicCompilation that caches the source instead of using the compilationUnitSource directly
794
						 * (if it is a working copy, the source can change between the parse and the AST convertion)
783
							 * (if it is a working copy, the source can change between the parse and the AST convertion)
795
						 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632)
784
							 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632)
796
						 */
785
							 */
797
						sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project);
786
							sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project);
798
						element = this.compilationUnitSource;
787
							wcOwner = ((ICompilationUnit) this.typeRoot).getOwner();
799
					} else if (this.classFileSource != null) {
788
					} else if (this.typeRoot instanceof IClassFile) {
800
						try {
789
						try {
801
							String sourceString = this.classFileSource.getSource();
790
							String sourceString = this.typeRoot.getSource();
802
							if (sourceString == null) {
791
							if (sourceString == null) {
803
								throw new IllegalStateException();
792
								throw new IllegalStateException();
804
							}
793
							}
805
							PackageFragment packageFragment = (PackageFragment) this.classFileSource.getParent();
794
							PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent();
806
							BinaryType type = (BinaryType) this.classFileSource.getType();
795
							BinaryType type = (BinaryType) this.typeRoot.findPrimaryType();
807
							IBinaryType binaryType = (IBinaryType) type.getElementInfo();
796
							IBinaryType binaryType = (IBinaryType) type.getElementInfo();
808
							// file name is used to recreate the Java element, so it has to be the toplevel .class file name
797
							// file name is used to recreate the Java element, so it has to be the toplevel .class file name
809
							char[] fileName = binaryType.getFileName();
798
							char[] fileName = binaryType.getFileName();
Lines 817-823 Link Here
817
								fileName = newFileName;
806
								fileName = newFileName;
818
							}
807
							}
819
							sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project);
808
							sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project);
820
							element = this.classFileSource;
821
						} catch(JavaModelException e) {
809
						} catch(JavaModelException e) {
822
							// an error occured accessing the java element
810
							// an error occured accessing the java element
823
							throw new IllegalStateException();
811
							throw new IllegalStateException();
Lines 865-874 Link Here
865
						this.apiLevel, 
853
						this.apiLevel, 
866
						this.compilerOptions,
854
						this.compilerOptions,
867
						needToResolveBindings,
855
						needToResolveBindings,
868
						this.compilationUnitSource == null ? this.workingCopyOwner : this.compilationUnitSource.getOwner(),
856
						wcOwner,
869
						needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null, 
857
						needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null, 
870
						monitor);
858
						monitor);
871
					result.setJavaElement(element);
859
					result.setTypeRoot(this.typeRoot);
872
					return result;
860
					return result;
873
				} finally {
861
				} finally {
874
					if (compilationUnitDeclaration != null && this.resolveBindings) {
862
					if (compilationUnitDeclaration != null && this.resolveBindings) {
(-)dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java (-2 / +2 lines)
Lines 362-368 Link Here
362
				
362
				
363
				// convert AST
363
				// convert AST
364
				CompilationUnit node = convert(compilationUnitDeclaration, parser.scanner.getSource(), apiLevel, options, false/*don't resolve binding*/, null/*no owner needed*/, null/*no binding table needed*/, monitor);
364
				CompilationUnit node = convert(compilationUnitDeclaration, parser.scanner.getSource(), apiLevel, options, false/*don't resolve binding*/, null/*no owner needed*/, null/*no binding table needed*/, monitor);
365
				node.setJavaElement(compilationUnits[i]);
365
				node.setTypeRoot(compilationUnits[i]);
366
				
366
				
367
				// accept AST
367
				// accept AST
368
				astRequestor.acceptAST(compilationUnits[i], node);
368
				astRequestor.acceptAST(compilationUnits[i], node);
Lines 703-709 Link Here
703
						ast.setBindingResolver(resolver);
703
						ast.setBindingResolver(resolver);
704
						converter.setAST(ast);
704
						converter.setAST(ast);
705
						CompilationUnit compilationUnit = converter.convert(unit, contents);
705
						CompilationUnit compilationUnit = converter.convert(unit, contents);
706
						compilationUnit.setJavaElement(source);
706
						compilationUnit.setTypeRoot(source);
707
						compilationUnit.setLineEndTable(compilationResult.getLineSeparatorPositions());
707
						compilationUnit.setLineEndTable(compilationResult.getLineSeparatorPositions());
708
						ast.setDefaultNodeFlag(0);
708
						ast.setDefaultNodeFlag(0);
709
						ast.setOriginalModificationCount(ast.modificationCount());
709
						ast.setOriginalModificationCount(ast.modificationCount());
(-)dom/org/eclipse/jdt/core/dom/AST.java (-1 / +1 lines)
Lines 269-275 Link Here
269
	
269
	
270
		CompilationUnit unit = converter.convert(compilationUnitDeclaration, source);
270
		CompilationUnit unit = converter.convert(compilationUnitDeclaration, source);
271
		unit.setLineEndTable(compilationUnitDeclaration.compilationResult.getLineSeparatorPositions());
271
		unit.setLineEndTable(compilationUnitDeclaration.compilationResult.getLineSeparatorPositions());
272
		unit.setJavaElement(workingCopy);
272
		unit.setTypeRoot(workingCopy);
273
		ast.setDefaultNodeFlag(savedDefaultNodeFlag);
273
		ast.setDefaultNodeFlag(savedDefaultNodeFlag);
274
		return unit;
274
		return unit;
275
	}
275
	}
(-)dom/org/eclipse/jdt/core/dom/CompilationUnit.java (-12 / +22 lines)
Lines 18-23 Link Here
18
import java.util.Map;
18
import java.util.Map;
19
19
20
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.ITypeRoot;
21
import org.eclipse.jdt.core.compiler.IProblem;
22
import org.eclipse.jdt.core.compiler.IProblem;
22
import org.eclipse.jdt.internal.compiler.parser.Scanner;
23
import org.eclipse.jdt.internal.compiler.parser.Scanner;
23
import org.eclipse.jdt.internal.compiler.util.Util;
24
import org.eclipse.jdt.internal.compiler.util.Util;
Lines 124-134 Link Here
124
	private DefaultCommentMapper commentMapper = null;
125
	private DefaultCommentMapper commentMapper = null;
125
	
126
	
126
	/**
127
	/**
127
	 * The Java element (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
128
	 * The Java type root (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
128
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java element.
129
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java type root.
129
	 * @since 3.1
130
	 */
130
	 */
131
	private IJavaElement element = null;
131
	private ITypeRoot typeRoot = null;
132
	
132
	
133
	/**
133
	/**
134
	 * The list of import declarations in textual order order; 
134
	 * The list of import declarations in textual order order; 
Lines 493-499 Link Here
493
	 * @since 3.1
493
	 * @since 3.1
494
	 */
494
	 */
495
	public IJavaElement getJavaElement() {
495
	public IJavaElement getJavaElement() {
496
		return this.element;
496
		return this.typeRoot;
497
	}
497
	}
498
	
498
	
499
	/**
499
	/**
Lines 611-616 Link Here
611
	public IProblem[] getProblems() {
611
	public IProblem[] getProblems() {
612
		return this.problems;
612
		return this.problems;
613
	}
613
	}
614
	
615
	/**
616
	 * The Java type root (a {@link org.eclipse.jdt.core.ICompilationUnit compilation unit} or a {@link org.eclipse.jdt.core.IClassFile class file}) 
617
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java type root.
618
	 * 
619
	 * @return the Java type root this compilation unit was created from, or <code>null</code> if none
620
	 * @since 3.3
621
	 */
622
	public ITypeRoot getTypeRoot() {
623
		return this.typeRoot;
624
	}
614
625
615
	/**
626
	/**
616
	 * Returns the live list of nodes for the import declarations of this 
627
	 * Returns the live list of nodes for the import declarations of this 
Lines 932-947 Link Here
932
			this.optionalCommentList = Collections.unmodifiableList(commentList);
943
			this.optionalCommentList = Collections.unmodifiableList(commentList);
933
		}
944
		}
934
	}
945
	}
935
		
946
936
	/**
947
	/**
937
	 * Sets the Java element (an <code>org.eclipse.jdt.core.ICompilationUnit</code> or an <code>org.eclipse.jdt.core.IClassFile</code>) 
948
	 * Sets the Java type root (a {@link org.eclipse.jdt.core.ICompilationUnit compilation unit} or a {@link org.eclipse.jdt.core.IClassFile class file})
938
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java element.
949
	 * this compilation unit was created from, or <code>null</code> if it was not created from a Java type root.
939
	 * 
950
	 * 
940
	 * @param element the Java element this compilation unit was created from
951
	 * @param typeRoot the Java type root this compilation unit was created from
941
	 * @since 3.1
942
	 */
952
	 */
943
	void setJavaElement(IJavaElement element) {
953
	void setTypeRoot(ITypeRoot typeRoot) {
944
		this.element = element;
954
		this.typeRoot = typeRoot;
945
	}
955
	}
946
	
956
	
947
	/**
957
	/**
(-)dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java (-2 / +4 lines)
Lines 21-26 Link Here
21
import org.eclipse.jdt.core.Flags;
21
import org.eclipse.jdt.core.Flags;
22
import org.eclipse.jdt.core.ICompilationUnit;
22
import org.eclipse.jdt.core.ICompilationUnit;
23
import org.eclipse.jdt.core.IImportDeclaration;
23
import org.eclipse.jdt.core.IImportDeclaration;
24
import org.eclipse.jdt.core.ITypeRoot;
24
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.Signature;
26
import org.eclipse.jdt.core.Signature;
26
import org.eclipse.jdt.core.compiler.CharOperation;
27
import org.eclipse.jdt.core.compiler.CharOperation;
Lines 183-189 Link Here
183
		if (astRoot == null) {
184
		if (astRoot == null) {
184
			throw new IllegalArgumentException("AST must not be null"); //$NON-NLS-1$
185
			throw new IllegalArgumentException("AST must not be null"); //$NON-NLS-1$
185
		}
186
		}
186
		if (!(astRoot.getJavaElement() instanceof ICompilationUnit)) {
187
		ITypeRoot typeRoot = astRoot.getTypeRoot();
188
		if (!(typeRoot instanceof ICompilationUnit)) {
187
			throw new IllegalArgumentException("AST must have been constructed from a Java element"); //$NON-NLS-1$
189
			throw new IllegalArgumentException("AST must have been constructed from a Java element"); //$NON-NLS-1$
188
		}
190
		}
189
		List existingImport= null;
191
		List existingImport= null;
Lines 202-208 Link Here
202
				existingImport.add(buf.toString());
204
				existingImport.add(buf.toString());
203
			}
205
			}
204
		}
206
		}
205
		return new ImportRewrite((ICompilationUnit) astRoot.getJavaElement(), astRoot, existingImport);
207
		return new ImportRewrite((ICompilationUnit) typeRoot, astRoot, existingImport);
206
	}
208
	}
207
		
209
		
208
	private ImportRewrite(ICompilationUnit cu, CompilationUnit astRoot, List existingImports) {
210
	private ImportRewrite(ICompilationUnit cu, CompilationUnit astRoot, List existingImports) {
(-)dom/org/eclipse/jdt/core/dom/rewrite/ASTRewrite.java (-2 / +4 lines)
Lines 15-20 Link Here
15
import java.util.Map;
15
import java.util.Map;
16
16
17
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.ICompilationUnit;
18
import org.eclipse.jdt.core.ITypeRoot;
18
import org.eclipse.jdt.core.JavaCore;
19
import org.eclipse.jdt.core.JavaCore;
19
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.core.dom.AST;
21
import org.eclipse.jdt.core.dom.AST;
Lines 231-240 Link Here
231
			throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit"); //$NON-NLS-1$
232
			throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit"); //$NON-NLS-1$
232
		}
233
		}
233
		CompilationUnit astRoot= (CompilationUnit) root;
234
		CompilationUnit astRoot= (CompilationUnit) root;
234
		if (!(astRoot.getJavaElement() instanceof ICompilationUnit)) {
235
		ITypeRoot typeRoot = astRoot.getTypeRoot();
236
		if (!(typeRoot instanceof ICompilationUnit)) {
235
			throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit"); //$NON-NLS-1$
237
			throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit"); //$NON-NLS-1$
236
		}
238
		}
237
		ICompilationUnit cu= (ICompilationUnit) astRoot.getJavaElement();
239
		ICompilationUnit cu= (ICompilationUnit) typeRoot;
238
		
240
		
239
		char[] content= cu.getBuffer().getCharacters();
241
		char[] content= cu.getBuffer().getCharacters();
240
		LineInformation lineInfo= LineInformation.create(astRoot);
242
		LineInformation lineInfo= LineInformation.create(astRoot);
(-)model/org/eclipse/jdt/core/IWorkingCopy.java (-1 / +1 lines)
Lines 172-178 Link Here
172
	 * @return the found primary type of this compilation unit, or <code>null</code> if no such a type exists
172
	 * @return the found primary type of this compilation unit, or <code>null</code> if no such a type exists
173
	 * @since 2.0
173
	 * @since 2.0
174
	 * 
174
	 * 
175
	 * @deprecated Use {@link ICompilationUnit#findPrimaryType()} instead.
175
	 * @deprecated Use {@link ITypeRoot#findPrimaryType()} instead.
176
	 */
176
	 */
177
	IType findPrimaryType();
177
	IType findPrimaryType();
178
	
178
	
(-)model/org/eclipse/jdt/core/IMember.java (+8 lines)
Lines 124-129 Link Here
124
 */
124
 */
125
int getOccurrenceCount();
125
int getOccurrenceCount();
126
/**
126
/**
127
 * Returns the Java type root in which this member is declared.
128
 * This is a handle-only method.
129
 * 
130
 * @return the Java type root in which this member is declared.
131
 * @since 3.3
132
 */
133
ITypeRoot getTypeRoot();
134
/**
127
 * Returns the local or anonymous type declared in this source member with the given simple name and/or
135
 * Returns the local or anonymous type declared in this source member with the given simple name and/or
128
 * with the specified position relative to the order they are defined in the source.
136
 * with the specified position relative to the order they are defined in the source.
129
 * The name is empty if it is an anonymous type.
137
 * The name is empty if it is an anonymous type.
(-)model/org/eclipse/jdt/core/ICompilationUnit.java (-23 / +1 lines)
Lines 30-36 Link Here
30
 * This interface is not intended to be implemented by clients.
30
 * This interface is not intended to be implemented by clients.
31
 * </p>
31
 * </p>
32
 */
32
 */
33
public interface ICompilationUnit extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation, ICodeAssist {
33
public interface ICompilationUnit extends ITypeRoot, IWorkingCopy, ISourceManipulation {
34
/**
34
/**
35
 * Constant indicating that a reconcile operation should not return an AST.
35
 * Constant indicating that a reconcile operation should not return an AST.
36
 * @since 3.0
36
 * @since 3.0
Lines 254-267 Link Here
254
 */
254
 */
255
IJavaElement[] findElements(IJavaElement element);
255
IJavaElement[] findElements(IJavaElement element);
256
/**
256
/**
257
 * Finds the primary type of this compilation unit (that is, the type with the same name as the
258
 * compilation unit), or <code>null</code> if no such a type exists.
259
 * 
260
 * @return the found primary type of this compilation unit, or <code>null</code> if no such a type exists
261
 * @since 3.0
262
 */
263
IType findPrimaryType();
264
/**
265
 * Finds the working copy for this compilation unit, given a {@link WorkingCopyOwner}. 
257
 * Finds the working copy for this compilation unit, given a {@link WorkingCopyOwner}. 
266
 * If no working copy has been created for this compilation unit associated with this
258
 * If no working copy has been created for this compilation unit associated with this
267
 * working copy owner, returns <code>null</code>.
259
 * working copy owner, returns <code>null</code>.
Lines 286-305 Link Here
286
 */
278
 */
287
IType[] getAllTypes() throws JavaModelException;
279
IType[] getAllTypes() throws JavaModelException;
288
/**
280
/**
289
 * Returns the smallest element within this compilation unit that 
290
 * includes the given source position (that is, a method, field, etc.), or
291
 * <code>null</code> if there is no element other than the compilation
292
 * unit itself at the given position, or if the given position is not
293
 * within the source range of this compilation unit.
294
 *
295
 * @param position a source position inside the compilation unit
296
 * @return the innermost Java element enclosing a given source position or <code>null</code>
297
 *	if none (excluding the compilation unit).
298
 * @throws JavaModelException if the compilation unit does not exist or if an
299
 *		exception occurs while accessing its corresponding resource
300
 */
301
IJavaElement getElementAt(int position) throws JavaModelException;
302
/**
303
 * Returns the first import declaration in this compilation unit with the given name.
281
 * Returns the first import declaration in this compilation unit with the given name.
304
 * This is a handle-only method. The import declaration may or may not exist. This
282
 * This is a handle-only method. The import declaration may or may not exist. This
305
 * is a convenience method - imports can also be accessed from a compilation unit's
283
 * is a convenience method - imports can also be accessed from a compilation unit's
(-)model/org/eclipse/jdt/core/IJavaElement.java (-15 / +22 lines)
Lines 36-130 Link Here
36
36
37
	/**
37
	/**
38
	 * Constant representing a Java model (workspace level object).
38
	 * Constant representing a Java model (workspace level object).
39
	 * A Java element with this type can be safely cast to <code>IJavaModel</code>.
39
	 * A Java element with this type can be safely cast to {@link IJavaModel}.
40
	 */
40
	 */
41
	int JAVA_MODEL = 1;
41
	int JAVA_MODEL = 1;
42
42
43
	/**
43
	/**
44
	 * Constant representing a Java project.
44
	 * Constant representing a Java project.
45
	 * A Java element with this type can be safely cast to <code>IJavaProject</code>.
45
	 * A Java element with this type can be safely cast to {@link IJavaProject}.
46
	 */
46
	 */
47
	int JAVA_PROJECT = 2;
47
	int JAVA_PROJECT = 2;
48
48
49
	/**
49
	/**
50
	 * Constant representing a package fragment root.
50
	 * Constant representing a package fragment root.
51
	 * A Java element with this type can be safely cast to <code>IPackageFragmentRoot</code>.
51
	 * A Java element with this type can be safely cast to {@link IPackageFragmentRoot}.
52
	 */
52
	 */
53
	int PACKAGE_FRAGMENT_ROOT = 3;
53
	int PACKAGE_FRAGMENT_ROOT = 3;
54
54
55
	/**
55
	/**
56
	 * Constant representing a package fragment.
56
	 * Constant representing a package fragment.
57
	 * A Java element with this type can be safely cast to <code>IPackageFragment</code>.
57
	 * A Java element with this type can be safely cast to {@link IPackageFragment}.
58
	 */
58
	 */
59
	int PACKAGE_FRAGMENT = 4;
59
	int PACKAGE_FRAGMENT = 4;
60
60
61
	/**
61
	/**
62
	 * Constant representing a Java compilation unit.
62
	 * Constant representing a Java compilation unit.
63
	 * A Java element with this type can be safely cast to <code>ICompilationUnit</code>.
63
	 * A Java element with this type can be safely cast to {@link ICompilationUnit}.
64
	 */
64
	 */
65
	int COMPILATION_UNIT = 5;
65
	int COMPILATION_UNIT = 5;
66
66
67
	/**
67
	/**
68
	 * Constant representing a class file.
68
	 * Constant representing a class file.
69
	 * A Java element with this type can be safely cast to <code>IClassFile</code>.
69
	 * A Java element with this type can be safely cast to {@link IClassFile}.
70
	 */
70
	 */
71
	int CLASS_FILE = 6;
71
	int CLASS_FILE = 6;
72
72
73
	/**
73
	/**
74
	 * Constant representing a type (a class or interface).
74
	 * Constant representing a type (a class or interface).
75
	 * A Java element with this type can be safely cast to <code>IType</code>.
75
	 * A Java element with this type can be safely cast to {@link IType}.
76
	 */
76
	 */
77
	int TYPE = 7;
77
	int TYPE = 7;
78
78
79
	/**
79
	/**
80
	 * Constant representing a field.
80
	 * Constant representing a field.
81
	 * A Java element with this type can be safely cast to <code>IField</code>.
81
	 * A Java element with this type can be safely cast to {@link IField}.
82
	 */
82
	 */
83
	int FIELD = 8;
83
	int FIELD = 8;
84
84
85
	/**
85
	/**
86
	 * Constant representing a method or constructor.
86
	 * Constant representing a method or constructor.
87
	 * A Java element with this type can be safely cast to <code>IMethod</code>.
87
	 * A Java element with this type can be safely cast to {@link IMethod}.
88
	 */
88
	 */
89
	int METHOD = 9;
89
	int METHOD = 9;
90
90
91
	/**
91
	/**
92
	 * Constant representing a stand-alone instance or class initializer.
92
	 * Constant representing a stand-alone instance or class initializer.
93
	 * A Java element with this type can be safely cast to <code>IInitializer</code>.
93
	 * A Java element with this type can be safely cast to {@link IInitializer}.
94
	 */
94
	 */
95
	int INITIALIZER = 10;
95
	int INITIALIZER = 10;
96
96
97
	/**
97
	/**
98
	 * Constant representing a package declaration within a compilation unit.
98
	 * Constant representing a package declaration within a compilation unit.
99
	 * A Java element with this type can be safely cast to <code>IPackageDeclaration</code>.
99
	 * A Java element with this type can be safely cast to {@link IPackageDeclaration}.
100
	 */
100
	 */
101
	int PACKAGE_DECLARATION = 11;
101
	int PACKAGE_DECLARATION = 11;
102
102
103
	/**
103
	/**
104
	 * Constant representing all import declarations within a compilation unit.
104
	 * Constant representing all import declarations within a compilation unit.
105
	 * A Java element with this type can be safely cast to <code>IImportContainer</code>.
105
	 * A Java element with this type can be safely cast to {@link IImportContainer}.
106
	 */
106
	 */
107
	int IMPORT_CONTAINER = 12;
107
	int IMPORT_CONTAINER = 12;
108
108
109
	/**
109
	/**
110
	 * Constant representing an import declaration within a compilation unit.
110
	 * Constant representing an import declaration within a compilation unit.
111
	 * A Java element with this type can be safely cast to <code>IImportDeclaration</code>.
111
	 * A Java element with this type can be safely cast to {@link IImportDeclaration}.
112
	 */
112
	 */
113
	int IMPORT_DECLARATION = 13;
113
	int IMPORT_DECLARATION = 13;
114
	
114
	
115
	/**
115
	/**
116
	 * Constant representing a local variable declaration.
116
	 * Constant representing a local variable declaration.
117
	 * A Java element with this type can be safely cast to <code>ILocalVariable</code>.
117
	 * A Java element with this type can be safely cast to {@link ILocalVariable}.
118
	 * @since 3.0
118
	 * @since 3.0
119
	 */
119
	 */
120
	int LOCAL_VARIABLE = 14;
120
	int LOCAL_VARIABLE = 14;
121
	
121
	
122
	/**
122
	/**
123
	 * Constant representing a type parameter declaration.
123
	 * Constant representing a type parameter declaration.
124
	 * A Java element with this type can be safely cast to <code>ITypeParameter</code>.
124
	 * A Java element with this type can be safely cast to {@link ITypeParameter}.
125
	 * @since 3.1
125
	 * @since 3.1
126
	 */
126
	 */
127
	int TYPE_PARAMETER = 15;
127
	int TYPE_PARAMETER = 15;
128
	
129
	/**
130
	 * Constant representing a Java type root.
131
	 * A Java element with this type can be safely cast to {@link ITypeRoot}.
132
	 * @since 3.3
133
	 */
134
	int TYPE_ROOT = 16;
128
135
129
	/**
136
	/**
130
	 * Returns whether this Java element exists in the model.
137
	 * Returns whether this Java element exists in the model.
(-)model/org/eclipse/jdt/core/IClassFile.java (-40 / +2 lines)
Lines 32-38 Link Here
32
 * @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, IProgressMonitor)
32
 * @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, IProgressMonitor)
33
 */
33
 */
34
 
34
 
35
public interface IClassFile extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist {
35
public interface IClassFile extends ITypeRoot {
36
	
36
	
37
/**
37
/**
38
 * Changes this class file handle into a working copy. A new {@link IBuffer} is
38
 * Changes this class file handle into a working copy. A new {@link IBuffer} is
Lines 80-100 Link Here
80
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
80
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
81
81
82
/**
82
/**
83
 * Returns the smallest element within this class file that 
84
 * includes the given source position (a method, field, etc.), or
85
 * <code>null</code> if there is no element other than the class file
86
 * itself at the given position, or if the given position is not
87
 * within the source range of this class file.
88
 *
89
 * @param position a source position inside the class file
90
 * @return the innermost Java element enclosing a given source position or <code>null</code>
91
 *  if none (excluding the class file).
92
 *
93
 * @exception JavaModelException if this element does not exist or if an
94
 *      exception occurs while accessing its corresponding resource
95
 */
96
IJavaElement getElementAt(int position) throws JavaModelException;
97
/**
98
 * Returns the type contained in this class file.
83
 * Returns the type contained in this class file.
99
 *
84
 *
100
 * @return the type contained in this class file
85
 * @return the type contained in this class file
Lines 105-133 Link Here
105
IType getType() throws JavaModelException;
90
IType getType() throws JavaModelException;
106
/**
91
/**
107
 * Returns a working copy on the source associated with this class file using the given 
92
 * Returns a working copy on the source associated with this class file using the given 
108
 * owner to create the buffer, or <code>null</code> if there is no source associated
109
 * with the class file.
110
 * <p>
111
 * The buffer will be automatically initialized with the source of the class file
112
 * upon creation.
113
 * <p>
114
 * The only valid operations on this working copy are <code>getBuffer()</code> or <code>getPrimary()</code>.
115
 *
116
 * @param owner the owner that creates a buffer that is used to get the content of the working copy
117
 *                 or <code>null</code> if the primary owner should be used
118
 * @param monitor a progress monitor used to report progress while opening this compilation unit
119
 *                 or <code>null</code> if no progress should be reported 
120
 * @return a  a working copy on the source associated with this class file
121
 * @exception JavaModelException if the source of this class file can
122
 *   not be determined. Reasons include:
123
 * <ul>
124
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
125
 * </ul>
126
 * @since 3.0
127
 */
128
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
129
/**
130
 * Returns a working copy on the source associated with this class file using the given 
131
 * factory to create the buffer, or <code>null</code> if there is no source associated
93
 * factory to create the buffer, or <code>null</code> if there is no source associated
132
 * with the class file.
94
 * with the class file.
133
 * <p>
95
 * <p>
Lines 147-153 Link Here
147
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
109
 * <li> This class file does not exist (ELEMENT_DOES_NOT_EXIST)</li>
148
 * </ul>
110
 * </ul>
149
 * @since 2.0
111
 * @since 2.0
150
 * @deprecated Use {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
112
 * @deprecated Use {@link ITypeRoot#getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} instead
151
 */
113
 */
152
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
114
IJavaElement getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException;
153
/**
115
/**
(-)model/org/eclipse/jdt/core/ITypeRoot.java (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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
25
 * @see IClassFile
26
 * @since 3.3
27
 */
28
public interface ITypeRoot extends IJavaElement, IParent, IOpenable, ISourceReference, ICodeAssist {
29
30
/**
31
 * Finds the primary type of this Java type root (that is, the type with the same name as the
32
 * compilation unit, or the type of a class file), or <code>null</code> if no such a type exists.
33
 * 
34
 * @return the found primary type of this Java type root, or <code>null</code> if no such a type exists
35
 */
36
IType findPrimaryType();
37
38
/**
39
 * Returns the smallest element within this Java type root that 
40
 * includes the given source position (that is, a method, field, etc.), or
41
 * <code>null</code> if there is no element other than the Java type root
42
 * itself at the given position, or if the given position is not
43
 * within the source range of the source of this Java type root.
44
 *
45
 * @param position a source position inside the Java type root
46
 * @return the innermost Java element enclosing a given source position or <code>null</code>
47
 *	if none (excluding the Java type root).
48
 * @throws JavaModelException if the Java type root does not exist or if an
49
 *	exception occurs while accessing its corresponding resource
50
 */
51
IJavaElement getElementAt(int position) throws JavaModelException;
52
	
53
/**
54
 * Returns a shared working copy on this compilation unit or class file using the given working copy owner to create
55
 * the buffer. If this is already a working copy of the given owner, the element itself is returned.
56
 * This API can only answer an already existing working copy if it is based on the same
57
 * original Java type root AND was using the same working copy owner (that is, as defined by {@link Object#equals}).	 
58
 * <p>
59
 * The life time of a shared working copy is as follows:
60
 * <ul>
61
 * <li>The first call to {@link #getWorkingCopy(WorkingCopyOwner, IProgressMonitor)} 
62
 * 	creates a new working copy for this element</li>
63
 * <li>Subsequent calls increment an internal counter.</li>
64
 * <li>A call to {@link ICompilationUnit#discardWorkingCopy()} decrements the internal counter.</li>
65
 * <li>When this counter is 0, the working copy is discarded.
66
 * </ul>
67
 * So users of this method must discard exactly once the working copy.
68
 * <p>
69
 * Note that the working copy owner will be used for the life time of the shared working copy, that is if the 
70
 * working copy is closed then reopened, this owner will be used.
71
 * The buffer will be automatically initialized with the original's Java type root content upon creation.
72
 * <p>
73
 * When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this
74
 * working copy.
75
 * </p><p>
76
 * Since 2.1, a working copy can be created on a not-yet existing compilation
77
 * unit. In particular, such a working copy can then be committed in order to create
78
 * the corresponding compilation unit.
79
 * </p><p>
80
 * Note that possible problems of this working copy are not reported using this method.
81
 * </p>
82
 * 
83
 * @param owner the working copy owner that creates a buffer that is used to get the content 
84
 * 				of the working copy
85
 * @param monitor a progress monitor used to report progress while opening this compilation unit
86
 *                 or <code>null</code> if no progress should be reported 
87
 * @throws JavaModelException if the contents of this element can
88
 *   	not be determined. 
89
 * @return a new working copy of this Java type root using the given owner to create
90
 *		the buffer, or this Java type root if it is already a working copy
91
 */
92
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
93
94
}

Return to bug 125504