1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.Iterator;
18 import net.sourceforge.phpdt.core.IBuffer;
19 import net.sourceforge.phpdt.core.IBufferFactory;
20 import net.sourceforge.phpdt.core.ICompilationUnit;
21 import net.sourceforge.phpdt.core.IJavaElement;
22 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
23 import net.sourceforge.phpdt.core.IJavaProject;
24 import net.sourceforge.phpdt.core.IMember;
25 import net.sourceforge.phpdt.core.IMethod;
26 import net.sourceforge.phpdt.core.IOpenable;
27 import net.sourceforge.phpdt.core.IPackageDeclaration;
28 import net.sourceforge.phpdt.core.IPackageFragment;
29 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
30 import net.sourceforge.phpdt.core.IParent;
31 import net.sourceforge.phpdt.core.IProblemRequestor;
32 import net.sourceforge.phpdt.core.ISourceManipulation;
33 import net.sourceforge.phpdt.core.ISourceRange;
34 import net.sourceforge.phpdt.core.ISourceReference;
35 import net.sourceforge.phpdt.core.IType;
36 import net.sourceforge.phpdt.core.IWorkingCopy;
37 import net.sourceforge.phpdt.core.JavaModelException;
38 import net.sourceforge.phpdt.core.Signature;
39 import net.sourceforge.phpdt.core.compiler.CharOperation;
40 import net.sourceforge.phpdt.core.jdom.IDOMNode;
41 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
42 import net.sourceforge.phpdt.internal.compiler.SourceElementParser;
43 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
44 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
46 import org.eclipse.core.resources.IContainer;
47 import org.eclipse.core.resources.IFile;
48 import org.eclipse.core.resources.IMarker;
49 import org.eclipse.core.resources.IResource;
50 import org.eclipse.core.runtime.IPath;
51 import org.eclipse.core.runtime.IProgressMonitor;
52 import org.eclipse.core.runtime.Path;
55 * @see ICompilationUnit
58 public class CompilationUnit extends Openable implements ICompilationUnit, net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit {
60 public static boolean SHARED_WC_VERBOSE = false;
62 // TODO: Remove when we are certain that every client is ready for this fix
63 public static final boolean FIX_BUG25184 = true;
66 * Constructs a handle to a compilation unit with the given name in the
69 * @exception IllegalArgumentException if the name of the compilation unit
70 * does not end with ".java"
72 protected CompilationUnit(IPackageFragment parent, String name) {
73 super(COMPILATION_UNIT, parent, name);
74 if (!Util.isJavaFileName(name)) {
75 throw new IllegalArgumentException(net.sourceforge.phpdt.internal.core.Util.bind("convention.unit.notJavaName")); //$NON-NLS-1$
79 * Accepts the given visitor onto the parsed tree of this compilation unit, after
80 * having runned the name resolution.
81 * The visitor's corresponding <code>visit</code> method is called with the
82 * corresponding parse tree. If the visitor returns <code>true</code>, this method
83 * visits this parse node's members.
85 * @param visitor the visitor
86 * @exception JavaModelException if this method fails. Reasons include:
88 * <li> This element does not exist.</li>
89 * <li> The visitor failed with this exception.</li>
92 //public void accept(IAbstractSyntaxTreeVisitor visitor) throws JavaModelException {
93 // CompilationUnitVisitor.visit(this, visitor);
96 protected void buildStructure(OpenableElementInfo info, IProgressMonitor monitor) throws JavaModelException {
98 if (monitor != null && monitor.isCanceled()) return;
100 // remove existing (old) infos
103 HashMap newElements = new HashMap(11);
104 info.setIsStructureKnown(generateInfos(info, monitor, newElements, getResource()));
105 JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().remove(this);
106 for (Iterator iter = newElements.keySet().iterator(); iter.hasNext();) {
107 IJavaElement key = (IJavaElement) iter.next();
108 Object value = newElements.get(key);
109 JavaModelManager.getJavaModelManager().putInfo(key, value);
111 // add the info for this at the end, to ensure that a getInfo cannot reply null in case the LRU cache needs
112 // to be flushed. Might lead to performance issues.
113 // see PR 1G2K5S7: ITPJCORE:ALL - NPE when accessing source for a binary type
114 JavaModelManager.getJavaModelManager().putInfo(this, info);
118 // * @see ICodeAssist#codeComplete(int, ICompletionRequestor)
120 //public void codeComplete(int offset, ICompletionRequestor requestor) throws JavaModelException {
121 // codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, offset, requestor);
124 * @see ICodeAssist#codeSelect(int, int)
126 //public IJavaElement[] codeSelect(int offset, int length) throws JavaModelException {
127 // return super.codeSelect(this, offset, length);
130 * @see IWorkingCopy#commit(boolean, IProgressMonitor)
132 public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException {
133 throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this));
136 * @see ISourceManipulation#copy(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
138 public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
139 if (container == null) {
140 throw new IllegalArgumentException(Util.bind("operation.nullContainer")); //$NON-NLS-1$
142 IJavaElement[] elements = new IJavaElement[] {this};
143 IJavaElement[] containers = new IJavaElement[] {container};
144 String[] renamings = null;
145 if (rename != null) {
146 renamings = new String[] {rename};
148 getJavaModel().copy(elements, containers, null, renamings, force, monitor);
151 * Returns a new element info for this element.
153 protected OpenableElementInfo createElementInfo() {
154 return new CompilationUnitElementInfo();
157 // * @see ICompilationUnit#createImport(String, IJavaElement, IProgressMonitor)
159 //public IImportDeclaration createImport(String name, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException {
160 // CreateImportOperation op = new CreateImportOperation(name, this);
161 // if (sibling != null) {
162 // op.createBefore(sibling);
164 // runOperation(op, monitor);
165 // return getImport(name);
168 * @see ICompilationUnit#createPackageDeclaration(String, IProgressMonitor)
170 public IPackageDeclaration createPackageDeclaration(String name, IProgressMonitor monitor) throws JavaModelException {
172 CreatePackageDeclarationOperation op= new CreatePackageDeclarationOperation(name, this);
173 runOperation(op, monitor);
174 return getPackageDeclaration(name);
177 // * @see ICompilationUnit#createType(String, IJavaElement, boolean, IProgressMonitor)
179 //public IType createType(String content, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
181 // //autogenerate this compilation unit
182 // IPackageFragment pkg = (IPackageFragment) getParent();
183 // String source = ""; //$NON-NLS-1$
184 // if (pkg.getElementName().length() > 0) {
185 // //not the default package...add the package declaration
186 // source = "package " + pkg.getElementName() + ";" + org.eclipse.jdt.internal.compiler.util.Util.LINE_SEPARATOR + org.eclipse.jdt.internal.compiler.util.Util.LINE_SEPARATOR; //$NON-NLS-1$ //$NON-NLS-2$
188 // CreateCompilationUnitOperation op = new CreateCompilationUnitOperation(pkg, fName, source, force);
189 // runOperation(op, monitor);
191 // CreateTypeOperation op = new CreateTypeOperation(this, content, force);
192 // if (sibling != null) {
193 // op.createBefore(sibling);
195 // runOperation(op, monitor);
196 // return (IType) op.getResultElements()[0];
199 * @see ISourceManipulation#delete(boolean, IProgressMonitor)
201 public void delete(boolean force, IProgressMonitor monitor) throws JavaModelException {
202 IJavaElement[] elements= new IJavaElement[] {this};
203 getJavaModel().delete(elements, force, monitor);
206 * This is not a working copy, do nothing.
208 * @see IWorkingCopy#destroy()
210 public void destroy() {
215 * Returns true if this handle represents the same Java element
216 * as the given handle.
218 * <p>Compilation units must also check working copy state;
220 * @see Object#equals(java.lang.Object)
222 public boolean equals(Object o) {
223 return super.equals(o) && !((ICompilationUnit)o).isWorkingCopy();
226 * @see JavaElement#equalsDOMNode(IDOMNode)
228 protected boolean equalsDOMNode(IDOMNode node) throws JavaModelException {
229 String name = getElementName();
230 if (node.getNodeType() == IDOMNode.COMPILATION_UNIT && name != null ) {
231 String nodeName = node.getName();
232 if (nodeName == null) return false;
233 if (name.equals(nodeName)) {
236 // iterate through all the types inside the receiver and see if one of them can fit
237 IType[] types = getTypes();
238 String typeNodeName = nodeName.substring(0, nodeName.indexOf(".java")); //$NON-NLS-1$
239 for (int i = 0, max = types.length; i < max; i++) {
240 if (types[i].getElementName().equals(typeNodeName)) {
249 * @see IWorkingCopy#findElements(IJavaElement)
251 public IJavaElement[] findElements(IJavaElement element) {
252 ArrayList children = new ArrayList();
253 while (element != null && element.getElementType() != IJavaElement.COMPILATION_UNIT) {
254 children.add(element);
255 element = element.getParent();
257 if (element == null) return null;
258 IJavaElement currentElement = this;
259 for (int i = children.size()-1; i >= 0; i--) {
260 IJavaElement child = (IJavaElement)children.get(i);
261 switch (child.getElementType()) {
262 // case IJavaElement.PACKAGE_DECLARATION:
263 // currentElement = ((ICompilationUnit)currentElement).getPackageDeclaration(child.getElementName());
265 // case IJavaElement.IMPORT_CONTAINER:
266 // currentElement = ((ICompilationUnit)currentElement).getImportContainer();
268 // case IJavaElement.IMPORT_DECLARATION:
269 // currentElement = ((IImportContainer)currentElement).getImport(child.getElementName());
271 case IJavaElement.TYPE:
272 if (currentElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
273 currentElement = ((ICompilationUnit)currentElement).getType(child.getElementName());
275 currentElement = ((IType)currentElement).getType(child.getElementName());
278 // case IJavaElement.INITIALIZER:
279 // currentElement = ((IType)currentElement).getInitializer(((JavaElement)child).getOccurrenceCount());
281 case IJavaElement.FIELD:
282 currentElement = ((IType)currentElement).getField(child.getElementName());
284 case IJavaElement.METHOD:
285 return ((IType)currentElement).findMethods((IMethod)child);
289 if (currentElement != null && currentElement.exists()) {
290 return new IJavaElement[] {currentElement};
296 * @see IWorkingCopy#findPrimaryType()
298 public IType findPrimaryType() {
299 String typeName = Signature.getQualifier(this.getElementName());
300 IType primaryType= this.getType(typeName);
301 if (primaryType.exists()) {
308 * @see IWorkingCopy#findSharedWorkingCopy(IBufferFactory)
310 public IJavaElement findSharedWorkingCopy(IBufferFactory factory) {
312 // if factory is null, default factory must be used
313 if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
315 // In order to be shared, working copies have to denote the same compilation unit
316 // AND use the same buffer factory.
317 // Assuming there is a little set of buffer factories, then use a 2 level Map cache.
318 Map sharedWorkingCopies = JavaModelManager.getJavaModelManager().sharedWorkingCopies;
320 Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
321 if (perFactoryWorkingCopies == null) return null;
322 return (WorkingCopy)perFactoryWorkingCopies.get(this);
325 protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
327 // if (getParent() instanceof JarPackageFragment) {
328 // // ignore .java files in jar
329 // throw newNotPresentException();
331 // put the info now, because getting the contents requires it
332 JavaModelManager.getJavaModelManager().putInfo(this, info);
333 CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info;
335 // generate structure
336 CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo, newElements);
337 IProblemFactory factory = new DefaultProblemFactory();
338 SourceElementParser parser = new SourceElementParser(requestor, factory, new CompilerOptions(getJavaProject().getOptions(true)));
339 // SourceElementParser parser = new SourceElementParser(requestor, factory);
340 requestor.parser = parser;
341 parser.parseCompilationUnit(this, false);
342 if (isWorkingCopy()) {
343 CompilationUnit original = (CompilationUnit) getOriginalElement();
344 // might be IResource.NULL_STAMP if original does not exist
345 unitInfo.fTimestamp = ((IFile) original.getResource()).getModificationStamp();
347 return unitInfo.isStructureKnown();
351 * @see ICompilationUnit#getAllTypes()
353 public IType[] getAllTypes() throws JavaModelException {
354 IJavaElement[] types = getTypes();
356 ArrayList allTypes = new ArrayList(types.length);
357 ArrayList typesToTraverse = new ArrayList(types.length);
358 for (i = 0; i < types.length; i++) {
359 typesToTraverse.add(types[i]);
361 while (!typesToTraverse.isEmpty()) {
362 IType type = (IType) typesToTraverse.get(0);
363 typesToTraverse.remove(type);
365 types = type.getTypes();
366 for (i = 0; i < types.length; i++) {
367 typesToTraverse.add(types[i]);
370 IType[] arrayOfAllTypes = new IType[allTypes.size()];
371 allTypes.toArray(arrayOfAllTypes);
372 return arrayOfAllTypes;
375 * @see IMember#getCompilationUnit()
377 public ICompilationUnit getCompilationUnit() {
381 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
383 public char[] getContents() {
385 IBuffer buffer = this.getBuffer();
386 return buffer == null ? null : buffer.getCharacters();
387 } catch (JavaModelException e) {
388 return CharOperation.NO_CHAR;
392 * A compilation unit has a corresponding resource unless it is contained
395 * @see IJavaElement#getCorrespondingResource()
397 public IResource getCorrespondingResource() throws JavaModelException {
398 IPackageFragmentRoot root= (IPackageFragmentRoot)getParent().getParent();
399 if (root.isArchive()) {
402 return getUnderlyingResource();
406 * @see ICompilationUnit#getElementAt(int)
408 public IJavaElement getElementAt(int position) throws JavaModelException {
410 IJavaElement e= getSourceElementAt(position);
417 public char[] getFileName(){
418 return getElementName().toCharArray();
421 * @see JavaElement#getHandleMementoDelimiter()
423 protected char getHandleMementoDelimiter() {
424 return JavaElement.JEM_COMPILATIONUNIT;
427 * @see ICompilationUnit#getImport(String)
429 //public IImportDeclaration getImport(String name) {
430 // return new ImportDeclaration(getImportContainer(), name);
433 // * @see ICompilationUnit#getImportContainer()
435 //public IImportContainer getImportContainer() {
436 // return new ImportContainer(this);
441 * @see ICompilationUnit#getImports()
443 //public IImportDeclaration[] getImports() throws JavaModelException {
444 // IImportContainer container= getImportContainer();
445 // if (container.exists()) {
446 // IJavaElement[] elements= container.getChildren();
447 // IImportDeclaration[] imprts= new IImportDeclaration[elements.length];
448 // System.arraycopy(elements, 0, imprts, 0, elements.length);
450 // } else if (!exists()) {
451 // throw newNotPresentException();
453 // return new IImportDeclaration[0];
458 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
460 public char[] getMainTypeName(){
461 String name= getElementName();
463 name= name.substring(0, name.length() - 5);
464 return name.toCharArray();
467 * Returns <code>null</code>, this is not a working copy.
469 * @see IWorkingCopy#getOriginal(IJavaElement)
471 public IJavaElement getOriginal(IJavaElement workingCopyElement) {
475 * Returns <code>null</code>, this is not a working copy.
477 * @see IWorkingCopy#getOriginalElement()
479 public IJavaElement getOriginalElement() {
483 * @see ICompilationUnit#getPackageDeclaration(String)
485 public IPackageDeclaration getPackageDeclaration(String name) {
486 return new PackageDeclaration(this, name);
489 * @see ICompilationUnit#getPackageDeclarations()
491 public IPackageDeclaration[] getPackageDeclarations() throws JavaModelException {
492 ArrayList list = getChildrenOfType(PACKAGE_DECLARATION);
493 IPackageDeclaration[] array= new IPackageDeclaration[list.size()];
498 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getPackageName()
500 public char[][] getPackageName() {
504 * @see IJavaElement#getPath()
506 public IPath getPath() {
507 PackageFragmentRoot root = this.getPackageFragmentRoot();
508 if (root.isArchive()) {
509 return root.getPath();
511 return this.getParent().getPath().append(this.getElementName());
515 * @see IJavaElement#getResource()
517 public IResource getResource() {
518 PackageFragmentRoot root = this.getPackageFragmentRoot();
519 if (root.isArchive()) {
520 return root.getResource();
522 return ((IContainer)this.getParent().getResource()).getFile(new Path(this.getElementName()));
527 * @see ISourceReference#getSource()
529 public String getSource() throws JavaModelException {
530 IBuffer buffer = getBuffer();
531 if (buffer == null) return ""; //$NON-NLS-1$
532 return buffer.getContents();
535 * @see ISourceReference#getSourceRange()
537 public ISourceRange getSourceRange() throws JavaModelException {
538 return ((CompilationUnitElementInfo) getElementInfo()).getSourceRange();
541 * @see ICompilationUnit#getType(String)
543 public IType getType(String name) {
544 return new SourceType(this, name);
547 * @see ICompilationUnit#getTypes()
549 public IType[] getTypes() throws JavaModelException {
550 ArrayList list = getChildrenOfType(TYPE);
551 IType[] array= new IType[list.size()];
555 public IResource getUnderlyingResource() throws JavaModelException {
557 return super.getUnderlyingResource();
559 return getResource();
563 * @see IWorkingCopy#getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
565 public IJavaElement getSharedWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
567 // if factory is null, default factory must be used
568 if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
570 JavaModelManager manager = JavaModelManager.getJavaModelManager();
572 // In order to be shared, working copies have to denote the same compilation unit
573 // AND use the same buffer factory.
574 // Assuming there is a little set of buffer factories, then use a 2 level Map cache.
575 Map sharedWorkingCopies = manager.sharedWorkingCopies;
577 Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
578 if (perFactoryWorkingCopies == null){
579 perFactoryWorkingCopies = new HashMap();
580 sharedWorkingCopies.put(factory, perFactoryWorkingCopies);
582 WorkingCopy workingCopy = (WorkingCopy)perFactoryWorkingCopies.get(this);
583 if (workingCopy != null) {
584 workingCopy.useCount++;
586 if (SHARED_WC_VERBOSE) {
587 System.out.println("Incrementing use count of shared working copy " + workingCopy.toStringWithAncestors()); //$NON-NLS-1$
592 CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, problemRequestor);
593 runOperation(op, pm);
594 return op.getResultElements()[0];
598 * @see IWorkingCopy#getWorkingCopy()
600 public IJavaElement getWorkingCopy() throws JavaModelException {
601 return this.getWorkingCopy(null, null, null);
605 * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
607 public IJavaElement getWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
608 CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, null, factory, problemRequestor);
609 runOperation(op, pm);
610 return op.getResultElements()[0];
614 * @see Openable#hasBuffer()
616 protected boolean hasBuffer() {
620 * If I am not open, return true to avoid parsing.
622 * @see IParent#hasChildren()
624 public boolean hasChildren() throws JavaModelException {
626 // return getChildren().length > 0;
633 * Returns false, this is not a working copy.
635 * @see IWorkingCopy#isBasedOn(IResource)
637 public boolean isBasedOn(IResource resource) {
641 * @see IOpenable#isConsistent()
643 public boolean isConsistent() throws JavaModelException {
644 return JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().get(this) == null;
647 * @see Openable#isSourceElement()
649 protected boolean isSourceElement() {
653 * @see IWorkingCopy#isWorkingCopy()
655 public boolean isWorkingCopy() {
659 * @see IOpenable#makeConsistent(IProgressMonitor)
661 public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
662 if (!isConsistent()) { // TODO: this code isn't synchronized with regular opening of a working copy
663 // create a new info and make it the current info
664 OpenableElementInfo info = createElementInfo();
665 buildStructure(info, monitor);
670 * @see ISourceManipulation#move(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
672 public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
673 if (container == null) {
674 throw new IllegalArgumentException(Util.bind("operation.nullContainer")); //$NON-NLS-1$
676 IJavaElement[] elements= new IJavaElement[] {this};
677 IJavaElement[] containers= new IJavaElement[] {container};
679 String[] renamings= null;
680 if (rename != null) {
681 renamings= new String[] {rename};
683 getJavaModel().move(elements, containers, null, renamings, force, monitor);
687 * @see Openable#openBuffer(IProgressMonitor)
689 protected IBuffer openBuffer(IProgressMonitor pm) throws JavaModelException {
691 // create buffer - compilation units only use default buffer factory
692 BufferManager bufManager = getBufferManager();
693 IBuffer buffer = getBufferFactory().createBuffer(this);
694 if (buffer == null) return null;
696 // set the buffer source
697 if (buffer.getCharacters() == null){
698 IFile file = (IFile)this.getResource();
699 if (file == null || !file.exists()) throw newNotPresentException();
700 buffer.setContents(Util.getResourceContentsAsCharArray(file));
703 // add buffer to buffer cache
704 bufManager.addBuffer(buffer);
706 // listen to buffer changes
707 buffer.addBufferChangedListener(this);
711 protected void openParent(IProgressMonitor pm) throws JavaModelException {
713 super.openParent(pm);
716 super.openParent(pm);
717 } catch(JavaModelException e){
718 // allow parent to not exist for compilation units defined outside classpath
719 if (!e.isDoesNotExist()){
725 protected boolean parentExists() {
727 return super.parentExists();
729 return true; // tolerate units outside classpath
734 * @see IWorkingCopy#reconcile()
736 public IMarker[] reconcile() throws JavaModelException {
737 // Reconciling is not supported on non working copies
742 * @see IWorkingCopy#reconcile(boolean, IProgressMonitor)
744 public void reconcile(
745 boolean forceProblemDetection,
746 IProgressMonitor monitor)
747 throws JavaModelException {
748 // Reconciling is not supported on non working copies
752 * @see ISourceManipulation#rename(String, boolean, IProgressMonitor)
754 public void rename(String name, boolean force, IProgressMonitor monitor) throws JavaModelException {
756 throw new IllegalArgumentException(Util.bind("operation.nullName")); //$NON-NLS-1$
758 IJavaElement[] elements= new IJavaElement[] {this};
759 IJavaElement[] dests= new IJavaElement[] {this.getParent()};
760 String[] renamings= new String[] {name};
761 getJavaModel().rename(elements, dests, renamings, force, monitor);
764 * Does nothing - this is not a working copy.
766 * @see IWorkingCopy#restore()
768 public void restore () throws JavaModelException {
771 * @see ICodeAssist#codeComplete(int, ICodeCompletionRequestor)
772 * @deprecated - use codeComplete(int, ICompletionRequestor)
774 //public void codeComplete(int offset, final ICodeCompletionRequestor requestor) throws JavaModelException {
776 // if (requestor == null){
777 // codeComplete(offset, (ICompletionRequestor)null);
782 // new ICompletionRequestor(){
783 // public void acceptAnonymousType(char[] superTypePackageName,char[] superTypeName,char[][] parameterPackageNames,char[][] parameterTypeNames,char[][] parameterNames,char[] completionName,int modifiers,int completionStart,int completionEnd, int relevance){
785 // public void acceptClass(char[] packageName, char[] className, char[] completionName, int modifiers, int completionStart, int completionEnd, int relevance) {
786 // requestor.acceptClass(packageName, className, completionName, modifiers, completionStart, completionEnd);
788 // public void acceptError(IProblem error) {
789 // if (true) return; // was disabled in 1.0
792 // IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker(IJavaModelMarker.TRANSIENT_PROBLEM);
793 // marker.setAttribute(IJavaModelMarker.ID, error.getID());
794 // marker.setAttribute(IMarker.CHAR_START, error.getSourceStart());
795 // marker.setAttribute(IMarker.CHAR_END, error.getSourceEnd() + 1);
796 // marker.setAttribute(IMarker.LINE_NUMBER, error.getSourceLineNumber());
797 // marker.setAttribute(IMarker.MESSAGE, error.getMessage());
798 // marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
799 // requestor.acceptError(marker);
800 // } catch(CoreException e){
803 // public void acceptField(char[] declaringTypePackageName, char[] declaringTypeName, char[] name, char[] typePackageName, char[] typeName, char[] completionName, int modifiers, int completionStart, int completionEnd, int relevance) {
804 // requestor.acceptField(declaringTypePackageName, declaringTypeName, name, typePackageName, typeName, completionName, modifiers, completionStart, completionEnd);
806 // public void acceptInterface(char[] packageName,char[] interfaceName,char[] completionName,int modifiers,int completionStart,int completionEnd, int relevance) {
807 // requestor.acceptInterface(packageName, interfaceName, completionName, modifiers, completionStart, completionEnd);
809 // public void acceptKeyword(char[] keywordName,int completionStart,int completionEnd, int relevance){
810 // requestor.acceptKeyword(keywordName, completionStart, completionEnd);
812 // public void acceptLabel(char[] labelName,int completionStart,int completionEnd, int relevance){
813 // requestor.acceptLabel(labelName, completionStart, completionEnd);
815 // public void acceptLocalVariable(char[] name,char[] typePackageName,char[] typeName,int modifiers,int completionStart,int completionEnd, int relevance){
818 // public void acceptMethod(char[] declaringTypePackageName,char[] declaringTypeName,char[] selector,char[][] parameterPackageNames,char[][] parameterTypeNames,char[][] parameterNames,char[] returnTypePackageName,char[] returnTypeName,char[] completionName,int modifiers,int completionStart,int completionEnd, int relevance){
819 // // skip parameter names
820 // requestor.acceptMethod(declaringTypePackageName, declaringTypeName, selector, parameterPackageNames, parameterTypeNames, returnTypePackageName, returnTypeName, completionName, modifiers, completionStart, completionEnd);
822 // public void acceptMethodDeclaration(char[] declaringTypePackageName,char[] declaringTypeName,char[] selector,char[][] parameterPackageNames,char[][] parameterTypeNames,char[][] parameterNames,char[] returnTypePackageName,char[] returnTypeName,char[] completionName,int modifiers,int completionStart,int completionEnd, int relevance){
825 // public void acceptModifier(char[] modifierName,int completionStart,int completionEnd, int relevance){
826 // requestor.acceptModifier(modifierName, completionStart, completionEnd);
828 // public void acceptPackage(char[] packageName,char[] completionName,int completionStart,int completionEnd, int relevance){
829 // requestor.acceptPackage(packageName, completionName, completionStart, completionEnd);
831 // public void acceptType(char[] packageName,char[] typeName,char[] completionName,int completionStart,int completionEnd, int relevance){
832 // requestor.acceptType(packageName, typeName, completionName, completionStart, completionEnd);
834 // public void acceptVariableName(char[] typePackageName,char[] typeName,char[] name,char[] completionName,int completionStart,int completionEnd, int relevance){
840 * @see JavaElement#rootedAt(IJavaProject)
842 public IJavaElement rootedAt(IJavaProject project) {
845 (IPackageFragment)((JavaElement)fParent).rootedAt(project),