5a563732d00fc7924e3811f51d27b92e4b2403c0
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / CompilationUnit.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IBuffer;
14 import net.sourceforge.phpdt.core.ICompilationUnit;
15 import net.sourceforge.phpdt.core.IJavaElement;
16 import net.sourceforge.phpdt.core.IJavaProject;
17 import net.sourceforge.phpdt.core.IPackageFragment;
18 import net.sourceforge.phpdt.core.JavaModelException;
19 import net.sourceforge.phpdt.core.compiler.CharOperation;
20
21 import org.eclipse.core.resources.IContainer;
22 import org.eclipse.core.resources.IMarker;
23 import org.eclipse.core.resources.IResource;
24 import org.eclipse.core.runtime.IProgressMonitor;
25 import org.eclipse.core.runtime.Path;
26
27 /**
28  * @see ICompilationUnit
29  */
30
31 public class CompilationUnit extends Openable implements ICompilationUnit {
32         
33         public static boolean SHARED_WC_VERBOSE = false;
34         
35         // TODO: Remove when we are certain that every client is ready for this fix
36         public static final boolean FIX_BUG25184 = true;
37
38 /**
39  * Constructs a handle to a compilation unit with the given name in the
40  * specified package.
41  *
42  * @exception IllegalArgumentException if the name of the compilation unit
43  * does not end with ".java"
44  */
45 protected CompilationUnit(IPackageFragment parent, String name) {
46         super(COMPILATION_UNIT, parent, name);
47 //      if (!Util.isJavaFileName(name)) {
48 //              throw new IllegalArgumentException(org.eclipse.jdt.internal.core.Util.bind("convention.unit.notJavaName")); //$NON-NLS-1$
49 //      }
50 }
51 /**
52  * Accepts the given visitor onto the parsed tree of this compilation unit, after
53  * having runned the name resolution.
54  * The visitor's corresponding <code>visit</code> method is called with the
55  * corresponding parse tree. If the visitor returns <code>true</code>, this method
56  * visits this parse node's members.
57  *
58  * @param visitor the visitor
59  * @exception JavaModelException if this method fails. Reasons include:
60  * <ul>
61  * <li> This element does not exist.</li>
62  * <li> The visitor failed with this exception.</li>
63  * </ul>
64  */
65 //public void accept(IAbstractSyntaxTreeVisitor visitor) throws JavaModelException {
66 //      CompilationUnitVisitor.visit(this, visitor);
67 //} 
68 //
69 //protected void buildStructure(OpenableElementInfo info, IProgressMonitor monitor) throws JavaModelException {
70 //
71 //      if (monitor != null && monitor.isCanceled()) return;
72 //
73 //      // remove existing (old) infos
74 //      removeInfo();
75 //
76 //      HashMap newElements = new HashMap(11);
77 //      info.setIsStructureKnown(generateInfos(info, monitor, newElements, getResource()));
78 //      JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().remove(this);
79 //      for (Iterator iter = newElements.keySet().iterator(); iter.hasNext();) {
80 //              IJavaElement key = (IJavaElement) iter.next();
81 //              Object value = newElements.get(key);
82 //              JavaModelManager.getJavaModelManager().putInfo(key, value);
83 //      }
84 //      // add the info for this at the end, to ensure that a getInfo cannot reply null in case the LRU cache needs
85 //      // to be flushed. Might lead to performance issues.
86 //      // see PR 1G2K5S7: ITPJCORE:ALL - NPE when accessing source for a binary type
87 //      JavaModelManager.getJavaModelManager().putInfo(this, info);     
88 //}
89 //
90 ///**
91 // * @see ICodeAssist#codeComplete(int, ICompletionRequestor)
92 // */
93 //public void codeComplete(int offset, ICompletionRequestor requestor) throws JavaModelException {
94 //      codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, offset, requestor);
95 //}
96 ///**
97 // * @see ICodeAssist#codeSelect(int, int)
98 // */
99 //public IJavaElement[] codeSelect(int offset, int length) throws JavaModelException {
100 //      return super.codeSelect(this, offset, length);
101 //}
102 ///**
103 // * @see IWorkingCopy#commit(boolean, IProgressMonitor)
104 // */
105 //public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException {
106 //      throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this));
107 //}
108 /**
109  * @see ISourceManipulation#copy(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
110  */
111 //public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
112 //      if (container == null) {
113 //              throw new IllegalArgumentException(Util.bind("operation.nullContainer")); //$NON-NLS-1$
114 //      }
115 //      IJavaElement[] elements = new IJavaElement[] {this};
116 //      IJavaElement[] containers = new IJavaElement[] {container};
117 //      String[] renamings = null;
118 //      if (rename != null) {
119 //              renamings = new String[] {rename};
120 //      }
121 //      getJavaModel().copy(elements, containers, null, renamings, force, monitor);
122 //}
123 /**
124  * Returns a new element info for this element.
125  */
126 //protected OpenableElementInfo createElementInfo() {
127 //      return new CompilationUnitElementInfo();
128 //}
129 ///**
130 // * @see ICompilationUnit#createImport(String, IJavaElement, IProgressMonitor)
131 // */
132 //public IImportDeclaration createImport(String name, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException {
133 //      CreateImportOperation op = new CreateImportOperation(name, this);
134 //      if (sibling != null) {
135 //              op.createBefore(sibling);
136 //      }
137 //      runOperation(op, monitor);
138 //      return getImport(name);
139 //}
140 /**
141  * @see ICompilationUnit#createPackageDeclaration(String, IProgressMonitor)
142  */
143 //public IPackageDeclaration createPackageDeclaration(String name, IProgressMonitor monitor) throws JavaModelException {
144 //      
145 //      CreatePackageDeclarationOperation op= new CreatePackageDeclarationOperation(name, this);
146 //      runOperation(op, monitor);
147 //      return getPackageDeclaration(name);
148 //}
149 ///**
150 // * @see ICompilationUnit#createType(String, IJavaElement, boolean, IProgressMonitor)
151 // */
152 //public IType createType(String content, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
153 //      if (!exists()) {
154 //              //autogenerate this compilation unit
155 //              IPackageFragment pkg = (IPackageFragment) getParent();
156 //              String source = ""; //$NON-NLS-1$
157 //              if (pkg.getElementName().length() > 0) {
158 //                      //not the default package...add the package declaration
159 //                      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$
160 //              }
161 //              CreateCompilationUnitOperation op = new CreateCompilationUnitOperation(pkg, fName, source, force);
162 //              runOperation(op, monitor);
163 //      }
164 //      CreateTypeOperation op = new CreateTypeOperation(this, content, force);
165 //      if (sibling != null) {
166 //              op.createBefore(sibling);
167 //      }
168 //      runOperation(op, monitor);
169 //      return (IType) op.getResultElements()[0];
170 //}
171 /**
172  * @see ISourceManipulation#delete(boolean, IProgressMonitor)
173  */
174 //public void delete(boolean force, IProgressMonitor monitor) throws JavaModelException {
175 //      IJavaElement[] elements= new IJavaElement[] {this};
176 //      getJavaModel().delete(elements, force, monitor);
177 //}
178 /**
179  * This is not a working copy, do nothing.
180  *
181  * @see IWorkingCopy#destroy()
182  */
183 public void destroy() {
184 }
185
186
187 /**
188  * Returns true if this handle represents the same Java element
189  * as the given handle.
190  *
191  * <p>Compilation units must also check working copy state;
192  *
193  * @see Object#equals(java.lang.Object)
194  */
195 //public boolean equals(Object o) {
196 //      return super.equals(o) && !((ICompilationUnit)o).isWorkingCopy();
197 //}
198 ///**
199 // * @see JavaElement#equalsDOMNode(IDOMNode)
200 // */
201 //protected boolean equalsDOMNode(IDOMNode node) throws JavaModelException {
202 //      String name = getElementName();
203 //      if (node.getNodeType() == IDOMNode.COMPILATION_UNIT && name != null ) {
204 //              String nodeName = node.getName();
205 //              if (nodeName == null) return false;             
206 //              if (name.equals(nodeName)) {
207 //                      return true;
208 //              } else {
209 //                      // iterate through all the types inside the receiver and see if one of them can fit
210 //                      IType[] types = getTypes();
211 //                      String typeNodeName = nodeName.substring(0, nodeName.indexOf(".java")); //$NON-NLS-1$
212 //                      for (int i = 0, max = types.length; i < max; i++) {
213 //                              if (types[i].getElementName().equals(typeNodeName)) {
214 //                                      return true;
215 //                              }
216 //                      }
217 //              }
218 //      }
219 //      return false;
220 //}
221 /**
222  * @see IWorkingCopy#findElements(IJavaElement)
223  */
224 //public IJavaElement[] findElements(IJavaElement element) {
225 //      ArrayList children = new ArrayList();
226 //      while (element != null && element.getElementType() != IJavaElement.COMPILATION_UNIT) {
227 //              children.add(element);
228 //              element = element.getParent();
229 //      }
230 //      if (element == null) return null;
231 //      IJavaElement currentElement = this;
232 //      for (int i = children.size()-1; i >= 0; i--) {
233 //              IJavaElement child = (IJavaElement)children.get(i);
234 //              switch (child.getElementType()) {
235 //                      case IJavaElement.PACKAGE_DECLARATION:
236 //                              currentElement = ((ICompilationUnit)currentElement).getPackageDeclaration(child.getElementName());
237 //                              break;
238 //                      case IJavaElement.IMPORT_CONTAINER:
239 //                              currentElement = ((ICompilationUnit)currentElement).getImportContainer();
240 //                              break;
241 //                      case IJavaElement.IMPORT_DECLARATION:
242 //                              currentElement = ((IImportContainer)currentElement).getImport(child.getElementName());
243 //                              break;
244 //                      case IJavaElement.TYPE:
245 //                              if (currentElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
246 //                                      currentElement = ((ICompilationUnit)currentElement).getType(child.getElementName());
247 //                              } else {
248 //                                      currentElement = ((IType)currentElement).getType(child.getElementName());
249 //                              }
250 //                              break;
251 //                      case IJavaElement.INITIALIZER:
252 //                              currentElement = ((IType)currentElement).getInitializer(((JavaElement)child).getOccurrenceCount());
253 //                              break;
254 //                      case IJavaElement.FIELD:
255 //                              currentElement = ((IType)currentElement).getField(child.getElementName());
256 //                              break;
257 //                      case IJavaElement.METHOD:
258 //                              return ((IType)currentElement).findMethods((IMethod)child);
259 //              }
260 //              
261 //      }
262 //      if (currentElement != null && currentElement.exists()) {
263 //              return new IJavaElement[] {currentElement};
264 //      } else {
265 //              return null;
266 //      }
267 //}
268 /**
269  * @see IWorkingCopy#findPrimaryType()
270  */
271 //public IType findPrimaryType() {
272 //      String typeName = Signature.getQualifier(this.getElementName());
273 //      IType primaryType= this.getType(typeName);
274 //      if (primaryType.exists()) {
275 //              return primaryType;
276 //      }
277 //      return null;
278 //}
279
280 /**
281  * @see IWorkingCopy#findSharedWorkingCopy(IBufferFactory)
282  */
283 //public IJavaElement findSharedWorkingCopy(IBufferFactory factory) {
284 //
285 //      // if factory is null, default factory must be used
286 //      if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
287 //
288 //      // In order to be shared, working copies have to denote the same compilation unit 
289 //      // AND use the same buffer factory.
290 //      // Assuming there is a little set of buffer factories, then use a 2 level Map cache.
291 //      Map sharedWorkingCopies = JavaModelManager.getJavaModelManager().sharedWorkingCopies;
292 //      
293 //      Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
294 //      if (perFactoryWorkingCopies == null) return null;
295 //      return (WorkingCopy)perFactoryWorkingCopies.get(this);
296 //}
297
298 //protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
299 //
300 //      if (getParent() instanceof JarPackageFragment) {
301 //              // ignore .java files in jar
302 //              throw newNotPresentException();
303 //      } else {
304 //              // put the info now, because getting the contents requires it
305 //              JavaModelManager.getJavaModelManager().putInfo(this, info);
306 //              CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info;
307 //
308 //              // generate structure
309 //              CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo, newElements);
310 //              IProblemFactory factory = new DefaultProblemFactory();
311 //              SourceElementParser parser = new SourceElementParser(requestor, factory, new CompilerOptions(getJavaProject().getOptions(true)));
312 //              requestor.parser = parser;
313 //              parser.parseCompilationUnit(this, false);
314 //              if (isWorkingCopy()) {
315 //                      CompilationUnit original = (CompilationUnit) getOriginalElement();
316 //                      // might be IResource.NULL_STAMP if original does not exist
317 //                      unitInfo.fTimestamp = ((IFile) original.getResource()).getModificationStamp();
318 //              }
319 //              return unitInfo.isStructureKnown();
320 //      }
321 //}
322 /**
323  * @see ICompilationUnit#getAllTypes()
324  */
325 //public IType[] getAllTypes() throws JavaModelException {
326 //      IJavaElement[] types = getTypes();
327 //      int i;
328 //      ArrayList allTypes = new ArrayList(types.length);
329 //      ArrayList typesToTraverse = new ArrayList(types.length);
330 //      for (i = 0; i < types.length; i++) {
331 //              typesToTraverse.add(types[i]);
332 //      }
333 //      while (!typesToTraverse.isEmpty()) {
334 //              IType type = (IType) typesToTraverse.get(0);
335 //              typesToTraverse.remove(type);
336 //              allTypes.add(type);
337 //              types = type.getTypes();
338 //              for (i = 0; i < types.length; i++) {
339 //                      typesToTraverse.add(types[i]);
340 //              }
341 //      } 
342 //      IType[] arrayOfAllTypes = new IType[allTypes.size()];
343 //      allTypes.toArray(arrayOfAllTypes);
344 //      return arrayOfAllTypes;
345 //}
346 /**
347  * @see IMember#getCompilationUnit()
348  */
349 public ICompilationUnit getCompilationUnit() {
350         return this;
351 }
352 /**
353  * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
354  */
355 public char[] getContents() {
356         try {
357                 IBuffer buffer = this.getBuffer();
358                 return buffer == null ? null : buffer.getCharacters();
359         } catch (JavaModelException e) {
360                 return CharOperation.NO_CHAR;
361         }
362 }
363 /**
364  * A compilation unit has a corresponding resource unless it is contained
365  * in a jar.
366  *
367  * @see IJavaElement#getCorrespondingResource()
368  */
369 //public IResource getCorrespondingResource() throws JavaModelException {
370 //      IPackageFragmentRoot root= (IPackageFragmentRoot)getParent().getParent();
371 //      if (root.isArchive()) {
372 //              return null;
373 //      } else {
374 //              return getUnderlyingResource();
375 //      }
376 //}
377 ///**
378 // * @see ICompilationUnit#getElementAt(int)
379 // */
380 //public IJavaElement getElementAt(int position) throws JavaModelException {
381 //
382 //      IJavaElement e= getSourceElementAt(position);
383 //      if (e == this) {
384 //              return null;
385 //      } else {
386 //              return e;
387 //      }
388 //}
389 public char[] getFileName(){
390         return getElementName().toCharArray();
391 }
392 /**
393  * @see JavaElement#getHandleMementoDelimiter()
394  */
395 protected char getHandleMementoDelimiter() {
396         return JavaElement.JEM_COMPILATIONUNIT;
397 }
398 /**
399  * @see ICompilationUnit#getImport(String)
400  */
401 //public IImportDeclaration getImport(String name) {
402 //      return new ImportDeclaration(getImportContainer(), name);
403 //}
404 ///**
405 // * @see ICompilationUnit#getImportContainer()
406 // */
407 //public IImportContainer getImportContainer() {
408 //      return new ImportContainer(this);
409 //}
410
411
412 /**
413  * @see ICompilationUnit#getImports()
414  */
415 //public IImportDeclaration[] getImports() throws JavaModelException {
416 //      IImportContainer container= getImportContainer();
417 //      if (container.exists()) {
418 //              IJavaElement[] elements= container.getChildren();
419 //              IImportDeclaration[] imprts= new IImportDeclaration[elements.length];
420 //              System.arraycopy(elements, 0, imprts, 0, elements.length);
421 //              return imprts;
422 //      } else if (!exists()) {
423 //                      throw newNotPresentException();
424 //      } else {
425 //              return new IImportDeclaration[0];
426 //      }
427 //
428 //}
429 /**
430  * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName()
431  */
432 public char[] getMainTypeName(){
433         String name= getElementName();
434         //remove the .java
435         name= name.substring(0, name.length() - 5);
436         return name.toCharArray();
437 }
438 /**
439  * Returns <code>null</code>, this is not a working copy.
440  *
441  * @see IWorkingCopy#getOriginal(IJavaElement)
442  */
443 public IJavaElement getOriginal(IJavaElement workingCopyElement) {
444         return null;
445 }
446 /**
447  * Returns <code>null</code>, this is not a working copy.
448  *
449  * @see IWorkingCopy#getOriginalElement()
450  */
451 public IJavaElement getOriginalElement() {
452         return null;
453 }
454 /**
455  * @see ICompilationUnit#getPackageDeclaration(String)
456  */
457 //public IPackageDeclaration getPackageDeclaration(String name) {
458 //      return new PackageDeclaration(this, name);
459 //}
460 ///**
461 // * @see ICompilationUnit#getPackageDeclarations()
462 // */
463 //public IPackageDeclaration[] getPackageDeclarations() throws JavaModelException {
464 //      ArrayList list = getChildrenOfType(PACKAGE_DECLARATION);
465 //      IPackageDeclaration[] array= new IPackageDeclaration[list.size()];
466 //      list.toArray(array);
467 //      return array;
468 //}
469 /**
470  * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getPackageName()
471  */
472 public char[][] getPackageName() {
473         return null;
474 }
475 /**
476  * @see IJavaElement#getPath()
477  */
478 //public IPath getPath() {
479 //      PackageFragmentRoot root = this.getPackageFragmentRoot();
480 //      if (root.isArchive()) {
481 //              return root.getPath();
482 //      } else {
483 //              return this.getParent().getPath().append(this.getElementName());
484 //      }
485 //}
486 /**
487  * @see IJavaElement#getResource()
488  */
489 public IResource getResource() {
490         PackageFragmentRoot root = this.getPackageFragmentRoot();
491         if (root.isArchive()) {
492                 return root.getResource();
493         } else {
494                 return ((IContainer)this.getParent().getResource()).getFile(new Path(this.getElementName()));
495         }
496 }
497
498 /**
499  * @see ISourceReference#getSource()
500  */
501 public String getSource() throws JavaModelException {
502         IBuffer buffer = getBuffer();
503         if (buffer == null) return ""; //$NON-NLS-1$
504         return buffer.getContents();
505 }
506 /**
507  * @see ISourceReference#getSourceRange()
508  */
509 //public ISourceRange getSourceRange() throws JavaModelException {
510 //      return ((CompilationUnitElementInfo) getElementInfo()).getSourceRange();
511 //}
512 ///**
513 // * @see ICompilationUnit#getType(String)
514 // */
515 //public IType getType(String name) {
516 //      return new SourceType(this, name);
517 //}
518 ///**
519 // * @see ICompilationUnit#getTypes()
520 // */
521 //public IType[] getTypes() throws JavaModelException {
522 //      ArrayList list = getChildrenOfType(TYPE);
523 //      IType[] array= new IType[list.size()];
524 //      list.toArray(array);
525 //      return array;
526 //}
527 //public IResource getUnderlyingResource() throws JavaModelException {
528 //      if (FIX_BUG25184) {
529 //              return super.getUnderlyingResource();
530 //      } else {
531 //              return getResource();
532 //      }
533 //}
534 ///**
535 // * @see IWorkingCopy#getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
536 // */
537 //public IJavaElement getSharedWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
538 //      
539 //      // if factory is null, default factory must be used
540 //      if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory();
541 //
542 //      JavaModelManager manager = JavaModelManager.getJavaModelManager();
543 //      
544 //      // In order to be shared, working copies have to denote the same compilation unit 
545 //      // AND use the same buffer factory.
546 //      // Assuming there is a little set of buffer factories, then use a 2 level Map cache.
547 //      Map sharedWorkingCopies = manager.sharedWorkingCopies;
548 //      
549 //      Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
550 //      if (perFactoryWorkingCopies == null){
551 //              perFactoryWorkingCopies = new HashMap();
552 //              sharedWorkingCopies.put(factory, perFactoryWorkingCopies);
553 //      }
554 //      WorkingCopy workingCopy = (WorkingCopy)perFactoryWorkingCopies.get(this);
555 //      if (workingCopy != null) {
556 //              workingCopy.useCount++;
557 //
558 //              if (SHARED_WC_VERBOSE) {
559 //                      System.out.println("Incrementing use count of shared working copy " + workingCopy.toStringWithAncestors()); //$NON-NLS-1$
560 //              }
561 //
562 //              return workingCopy;
563 //      } else {
564 //              CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, problemRequestor);
565 //              runOperation(op, pm);
566 //              return op.getResultElements()[0];
567 //      }
568 //}
569 /**
570  * @see IWorkingCopy#getWorkingCopy()
571  */
572 //public IJavaElement getWorkingCopy() throws JavaModelException {
573 //      return this.getWorkingCopy(null, null, null);
574 //}
575
576 /**
577  * @see IWorkingCopy#getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
578  */
579 //public IJavaElement getWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException {
580 //      CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, null, factory, problemRequestor);
581 //      runOperation(op, pm);
582 //      return op.getResultElements()[0];
583 //}
584
585 /**
586  * @see Openable#hasBuffer()
587  */
588 protected boolean hasBuffer() {
589         return true;
590 }
591 /**
592  * If I am not open, return true to avoid parsing.
593  *
594  * @see IParent#hasChildren()
595  */
596 public boolean hasChildren() throws JavaModelException {
597 //      if (isOpen()) {
598 //              return getChildren().length > 0;
599 //      } else {
600 //              return true;
601 //      }
602   return false;
603 }
604 /**
605  * Returns false, this is not a working copy.
606  *
607  * @see IWorkingCopy#isBasedOn(IResource)
608  */
609 public boolean isBasedOn(IResource resource) {
610         return false;
611 }
612 /**
613  * @see IOpenable#isConsistent()
614  */
615 //public boolean isConsistent() throws JavaModelException {
616 //      return JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().get(this) == null;
617 //}
618 /**
619  * @see Openable#isSourceElement()
620  */
621 protected boolean isSourceElement() {
622         return true;
623 }
624 /**
625  * @see IWorkingCopy#isWorkingCopy()
626  */
627 public boolean isWorkingCopy() {
628         return false;
629 }
630 /**
631  * @see IOpenable#makeConsistent(IProgressMonitor)
632  */
633 //public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
634 //      if (!isConsistent()) { // TODO: this code isn't synchronized with regular opening of a working copy
635 //              // create a new info and make it the current info
636 //              OpenableElementInfo info = createElementInfo();
637 //              buildStructure(info, monitor);
638 //      }
639 //}
640
641 /**
642  * @see ISourceManipulation#move(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
643  */
644 //public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
645 //      if (container == null) {
646 //              throw new IllegalArgumentException(Util.bind("operation.nullContainer")); //$NON-NLS-1$
647 //      }
648 //      IJavaElement[] elements= new IJavaElement[] {this};
649 //      IJavaElement[] containers= new IJavaElement[] {container};
650 //      
651 //      String[] renamings= null;
652 //      if (rename != null) {
653 //              renamings= new String[] {rename};
654 //      }
655 //      getJavaModel().move(elements, containers, null, renamings, force, monitor);
656 //}
657
658 /**
659  * @see Openable#openBuffer(IProgressMonitor)
660  */
661 //protected IBuffer openBuffer(IProgressMonitor pm) throws JavaModelException {
662 //
663 //      // create buffer -  compilation units only use default buffer factory
664 //      BufferManager bufManager = getBufferManager();
665 //      IBuffer buffer = getBufferFactory().createBuffer(this);
666 //      if (buffer == null) return null;
667 //      
668 //      // set the buffer source
669 //      if (buffer.getCharacters() == null){
670 //              IFile file = (IFile)this.getResource();
671 //              if (file == null || !file.exists()) throw newNotPresentException();
672 //              buffer.setContents(Util.getResourceContentsAsCharArray(file));
673 //      }
674 //
675 //      // add buffer to buffer cache
676 //      bufManager.addBuffer(buffer);
677 //                      
678 //      // listen to buffer changes
679 //      buffer.addBufferChangedListener(this);
680 //      
681 //      return buffer;
682 //}
683 //protected void openParent(IProgressMonitor pm) throws JavaModelException {
684 //      if (FIX_BUG25184) {
685 //              super.openParent(pm);
686 //      } else {
687 //              try {
688 //                      super.openParent(pm);
689 //              } catch(JavaModelException e){
690 //                      // allow parent to not exist for compilation units defined outside classpath
691 //                      if (!e.isDoesNotExist()){ 
692 //                              throw e;
693 //                      }
694 //              }
695 //      }
696 //}
697 //protected boolean parentExists() {
698 //      if (FIX_BUG25184) {
699 //              return super.parentExists();
700 //      } else {
701 //              return true; // tolerate units outside classpath
702 //      }
703 //}
704
705 /**
706  * @see IWorkingCopy#reconcile()
707  */
708 public IMarker[] reconcile() throws JavaModelException {
709         // Reconciling is not supported on non working copies
710         return null;
711 }
712
713 /**
714  * @see IWorkingCopy#reconcile(boolean, IProgressMonitor)
715  */
716 public void reconcile(
717         boolean forceProblemDetection,
718         IProgressMonitor monitor)
719         throws JavaModelException {
720         // Reconciling is not supported on non working copies
721 }
722
723 /**
724  * @see ISourceManipulation#rename(String, boolean, IProgressMonitor)
725  */
726 //public void rename(String name, boolean force, IProgressMonitor monitor) throws JavaModelException {
727 //      if (name == null) {
728 //              throw new IllegalArgumentException(Util.bind("operation.nullName")); //$NON-NLS-1$
729 //      }
730 //      IJavaElement[] elements= new IJavaElement[] {this};
731 //      IJavaElement[] dests= new IJavaElement[] {this.getParent()};
732 //      String[] renamings= new String[] {name};
733 //      getJavaModel().rename(elements, dests, renamings, force, monitor);
734 //}
735 /**
736  * Does nothing - this is not a working copy.
737  *
738  * @see IWorkingCopy#restore()
739  */
740 public void restore () throws JavaModelException {
741 }
742 /**
743  * @see ICodeAssist#codeComplete(int, ICodeCompletionRequestor)
744  * @deprecated - use codeComplete(int, ICompletionRequestor)
745  */
746 //public void codeComplete(int offset, final ICodeCompletionRequestor requestor) throws JavaModelException {
747 //      
748 //      if (requestor == null){
749 //              codeComplete(offset, (ICompletionRequestor)null);
750 //              return;
751 //      }
752 //      codeComplete(
753 //              offset,
754 //              new ICompletionRequestor(){
755 //                      public void acceptAnonymousType(char[] superTypePackageName,char[] superTypeName,char[][] parameterPackageNames,char[][] parameterTypeNames,char[][] parameterNames,char[] completionName,int modifiers,int completionStart,int completionEnd, int relevance){
756 //                      }
757 //                      public void acceptClass(char[] packageName, char[] className, char[] completionName, int modifiers, int completionStart, int completionEnd, int relevance) {
758 //                              requestor.acceptClass(packageName, className, completionName, modifiers, completionStart, completionEnd);
759 //                      }
760 //                      public void acceptError(IProblem error) {
761 //                              if (true) return; // was disabled in 1.0
762 //
763 //                              try {
764 //                                      IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker(IJavaModelMarker.TRANSIENT_PROBLEM);
765 //                                      marker.setAttribute(IJavaModelMarker.ID, error.getID());
766 //                                      marker.setAttribute(IMarker.CHAR_START, error.getSourceStart());
767 //                                      marker.setAttribute(IMarker.CHAR_END, error.getSourceEnd() + 1);
768 //                                      marker.setAttribute(IMarker.LINE_NUMBER, error.getSourceLineNumber());
769 //                                      marker.setAttribute(IMarker.MESSAGE, error.getMessage());
770 //                                      marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
771 //                                      requestor.acceptError(marker);
772 //                              } catch(CoreException e){
773 //                              }
774 //                      }
775 //                      public void acceptField(char[] declaringTypePackageName, char[] declaringTypeName, char[] name, char[] typePackageName, char[] typeName, char[] completionName, int modifiers, int completionStart, int completionEnd, int relevance) {
776 //                              requestor.acceptField(declaringTypePackageName, declaringTypeName, name, typePackageName, typeName, completionName, modifiers, completionStart, completionEnd);
777 //                      }
778 //                      public void acceptInterface(char[] packageName,char[] interfaceName,char[] completionName,int modifiers,int completionStart,int completionEnd, int relevance) {
779 //                              requestor.acceptInterface(packageName, interfaceName, completionName, modifiers, completionStart, completionEnd);
780 //                      }
781 //                      public void acceptKeyword(char[] keywordName,int completionStart,int completionEnd, int relevance){
782 //                              requestor.acceptKeyword(keywordName, completionStart, completionEnd);
783 //                      }
784 //                      public void acceptLabel(char[] labelName,int completionStart,int completionEnd, int relevance){
785 //                              requestor.acceptLabel(labelName, completionStart, completionEnd);
786 //                      }
787 //                      public void acceptLocalVariable(char[] name,char[] typePackageName,char[] typeName,int modifiers,int completionStart,int completionEnd, int relevance){
788 //                              // ignore
789 //                      }
790 //                      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){
791 //                              // skip parameter names
792 //                              requestor.acceptMethod(declaringTypePackageName, declaringTypeName, selector, parameterPackageNames, parameterTypeNames, returnTypePackageName, returnTypeName, completionName, modifiers, completionStart, completionEnd);
793 //                      }
794 //                      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){
795 //                              // ignore
796 //                      }
797 //                      public void acceptModifier(char[] modifierName,int completionStart,int completionEnd, int relevance){
798 //                              requestor.acceptModifier(modifierName, completionStart, completionEnd);
799 //                      }
800 //                      public void acceptPackage(char[] packageName,char[] completionName,int completionStart,int completionEnd, int relevance){
801 //                              requestor.acceptPackage(packageName, completionName, completionStart, completionEnd);
802 //                      }
803 //                      public void acceptType(char[] packageName,char[] typeName,char[] completionName,int completionStart,int completionEnd, int relevance){
804 //                              requestor.acceptType(packageName, typeName, completionName, completionStart, completionEnd);
805 //                      }
806 //                      public void acceptVariableName(char[] typePackageName,char[] typeName,char[] name,char[] completionName,int completionStart,int completionEnd, int relevance){
807 //                              // ignore
808 //                      }
809 //              });
810 //}
811 /**
812  * @see JavaElement#rootedAt(IJavaProject)
813  */
814 public IJavaElement rootedAt(IJavaProject project) {
815         return
816                 new CompilationUnit(
817                         (IPackageFragment)((JavaElement)fParent).rootedAt(project), 
818                         fName);
819 }
820
821 }