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;
16 import net.sourceforge.phpdt.core.IJavaElement;
17 import net.sourceforge.phpdt.core.IJavaProject;
18 import net.sourceforge.phpdt.core.IPackageFragment;
19 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
20 import net.sourceforge.phpdt.core.JavaModelException;
21 import net.sourceforge.phpdt.core.JavaCore;
22 import net.sourceforge.phpdt.core.compiler.CharOperation;
23 import net.sourceforge.phpdt.internal.core.util.Util;
25 import org.eclipse.core.resources.IContainer;
26 import org.eclipse.core.resources.IFolder;
27 import org.eclipse.core.resources.IResource;
28 import org.eclipse.core.resources.ResourcesPlugin;
29 import org.eclipse.core.runtime.CoreException;
30 import org.eclipse.core.runtime.IPath;
31 import org.eclipse.core.runtime.IProgressMonitor;
32 import org.eclipse.core.runtime.QualifiedName;
33 import net.sourceforge.phpdt.core.IClasspathEntry;
34 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
35 import net.sourceforge.phpdt.internal.core.Openable;
36 import net.sourceforge.phpdt.internal.core.OpenableElementInfo;
38 import net.sourceforge.phpdt.internal.core.JavaProject;
39 import net.sourceforge.phpdt.internal.core.PackageFragmentRootInfo;
43 * @see IPackageFragmentRoot
45 public class PackageFragmentRoot extends Openable implements IPackageFragmentRoot {
48 * The delimiter between the source path and root path in the
49 * attachment server property.
51 protected final static char ATTACHMENT_PROPERTY_DELIMITER= '*';
53 * No source attachment property
55 protected final static String NO_SOURCE_ATTACHMENT = ""; //$NON-NLS-1$
57 * No source mapper singleton
59 // protected final static SourceMapper NO_SOURCE_MAPPER = new SourceMapper();
62 * The resource associated with this root.
63 * (an IResource or a java.io.File (for external jar only))
65 protected Object resource;
68 * Constructs a package fragment root which is the root of the java package
69 * directory hierarchy.
71 protected PackageFragmentRoot(IResource resource, JavaProject project, String name) {
73 this.resource = resource;
79 protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
81 // check whether this pkg fragment root can be opened
82 if (!resourceExists() ) { //|| !isOnClasspath()) {
83 throw newNotPresentException();
86 ((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
87 return computeChildren(info, newElements);
90 * Returns the root's kind - K_SOURCE or K_BINARY, defaults
91 * to K_SOURCE if it is not on the classpath.
93 * @exception NotPresentException if the project and root do
96 protected int determineKind(IResource underlyingResource) throws JavaModelException {
97 // IClasspathEntry[] entries= ((JavaProject)getJavaProject()).getExpandedClasspath(true);
98 // for (int i= 0; i < entries.length; i++) {
99 // IClasspathEntry entry= entries[i];
100 // if (entry.getPath().equals(underlyingResource.getFullPath())) {
101 // return entry.getContentKind();
104 return IPackageFragmentRoot.K_SOURCE;
107 * Compute the package fragment children of this package fragment root.
109 * @exception JavaModelException The resource associated with this package fragment root does not exist
111 protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws JavaModelException {
112 // Note the children are not opened (so not added to newElements) for a regular package fragment root
113 // Howver they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren)
115 // the underlying resource may be a folder or a project (in the case that the project folder
116 // is actually the package fragment root)
117 IResource underlyingResource = getResource();
118 if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
119 ArrayList vChildren = new ArrayList(5);
120 IContainer rootFolder = (IContainer) underlyingResource;
121 // char[][] inclusionPatterns = fullInclusionPatternChars();
122 char[][] exclusionPatterns = fullExclusionPatternChars();
123 computeFolderChildren(rootFolder, !Util.isExcluded(rootFolder, exclusionPatterns), "", vChildren, exclusionPatterns); //$NON-NLS-1$
125 IJavaElement[] children = new IJavaElement[vChildren.size()];
126 vChildren.toArray(children);
127 info.setChildren(children);
129 } catch (JavaModelException e) {
130 //problem resolving children; structure remains unknown
131 info.setChildren(new IJavaElement[]{});
137 * Starting at this folder, create package fragments and add the fragments that are not exclused
138 * to the collection of children.
140 * @exception JavaModelException The resource associated with this package fragment does not exist
142 protected void computeFolderChildren(IContainer folder, boolean isIncluded, String prefix, ArrayList vChildren, char[][] exclusionPatterns) throws JavaModelException {
143 //, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException {
146 IPackageFragment pkg = getPackageFragment(prefix);
150 JavaProject javaProject = (JavaProject)getJavaProject();
151 IResource[] members = folder.members();
152 boolean hasIncluded = isIncluded;
153 for (int i = 0, max = members.length; i < max; i++) {
154 IResource member = members[i];
155 String memberName = member.getName();
157 switch(member.getType()) {
159 case IResource.FOLDER:
160 if (Util.isValidFolderNameForPackage(memberName)) {
161 boolean isMemberIncluded = !Util.isExcluded(member, exclusionPatterns);
162 // keep looking inside as long as included already, or may have child included due to inclusion patterns
163 // if (isMemberIncluded || inclusionPatterns != null) {
164 // // eliminate binary output only if nested inside direct subfolders
165 // if (javaProject.contains(member)) {
167 // if (prefix.length() == 0) {
168 // newPrefix = memberName;
170 // newPrefix = prefix + "." + memberName; //$NON-NLS-1$
172 // computeFolderChildren((IFolder) member, isMemberIncluded, newPrefix, vChildren, inclusionPatterns, exclusionPatterns);
178 // inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
180 && Util.isValidCompilationUnitName(memberName)
181 && !Util.isExcluded(member, exclusionPatterns)) {
183 IPackageFragment pkg = getPackageFragment(prefix);
189 } catch(IllegalArgumentException e){
190 throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); // could be thrown by ElementTree when path is not found
191 } catch (CoreException e) {
192 throw new JavaModelException(e);
196 * @see IPackageFragmentRoot
198 //public void attachSource(IPath sourcePath, IPath rootPath, IProgressMonitor monitor) throws JavaModelException {
200 // verifyAttachSource(sourcePath);
201 // if (monitor != null) {
202 // monitor.beginTask(Util.bind("element.attachingSource"), 2); //$NON-NLS-1$
204 // SourceMapper oldMapper= getSourceMapper();
205 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
206 // boolean rootNeedsToBeClosed= false;
208 // if (sourcePath == null) {
209 // //source being detached
210 // rootNeedsToBeClosed= true;
211 // setSourceMapper(null);
212 // /* Disable deltas (see 1GDTUSD)
213 // // fire a delta to notify the UI about the source detachement.
214 // JavaModelManager manager = (JavaModelManager) JavaModelManager.getJavaModelManager();
215 // JavaModel model = (JavaModel) getJavaModel();
216 // JavaElementDelta attachedSourceDelta = new JavaElementDelta(model);
217 // attachedSourceDelta .sourceDetached(this); // this would be a PackageFragmentRoot
218 // manager.registerResourceDelta(attachedSourceDelta );
219 // manager.fire(); // maybe you want to fire the change later. Let us know about it.
223 // // fire a delta to notify the UI about the source attachement.
224 // JavaModelManager manager = (JavaModelManager) JavaModelManager.getJavaModelManager();
225 // JavaModel model = (JavaModel) getJavaModel();
226 // JavaElementDelta attachedSourceDelta = new JavaElementDelta(model);
227 // attachedSourceDelta .sourceAttached(this); // this would be a PackageFragmentRoot
228 // manager.registerResourceDelta(attachedSourceDelta );
229 // manager.fire(); // maybe you want to fire the change later. Let us know about it.
232 // //check if different from the current attachment
233 // IPath storedSourcePath= getSourceAttachmentPath();
234 // IPath storedRootPath= getSourceAttachmentRootPath();
235 // if (monitor != null) {
236 // monitor.worked(1);
238 // if (storedSourcePath != null) {
239 // if (!(storedSourcePath.equals(sourcePath) && (rootPath != null && rootPath.equals(storedRootPath)) || storedRootPath == null)) {
240 // rootNeedsToBeClosed= true;
243 // // check if source path is valid
244 // Object target = JavaModel.getTarget(workspace.getRoot(), sourcePath, false);
245 // if (target == null) {
246 // if (monitor != null) {
249 // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, sourcePath));
251 // SourceMapper mapper = createSourceMapper(sourcePath, rootPath);
252 // if (rootPath == null && mapper.rootPath != null) {
253 // // as a side effect of calling the SourceMapper constructor, the root path was computed
254 // rootPath = new Path(mapper.rootPath);
256 // setSourceMapper(mapper);
258 // if (sourcePath == null) {
259 // setSourceAttachmentProperty(null); //remove the property
261 // //set the property to the path of the mapped source
262 // setSourceAttachmentProperty(
263 // sourcePath.toString()
264 // + (rootPath == null ? "" : (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()))); //$NON-NLS-1$
266 // if (rootNeedsToBeClosed) {
267 // if (oldMapper != null) {
268 // oldMapper.close();
270 // BufferManager manager= BufferManager.getDefaultBufferManager();
271 // Enumeration openBuffers= manager.getOpenBuffers();
272 // while (openBuffers.hasMoreElements()) {
273 // IBuffer buffer= (IBuffer) openBuffers.nextElement();
274 // IOpenable possibleMember= buffer.getOwner();
275 // if (isAncestorOf((IJavaElement) possibleMember)) {
279 // if (monitor != null) {
280 // monitor.worked(1);
283 // } catch (JavaModelException e) {
284 // setSourceAttachmentProperty(null); // loose info - will be recomputed
287 // if (monitor != null) {
293 //SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) {
294 // SourceMapper mapper = new SourceMapper(
296 // rootPath == null ? null : rootPath.toOSString(),
297 // this.isExternal() ? JavaCore.getOptions() : this.getJavaProject().getOptions(true)); // only project options if associated with resource
301 * @see org.eclipse.jdt.core.IPackageFragmentRoot#delete
303 //public void delete(
304 // int updateResourceFlags,
305 // int updateModelFlags,
306 // IProgressMonitor monitor)
307 // throws JavaModelException {
309 // DeletePackageFragmentRootOperation op = new DeletePackageFragmentRootOperation(this, updateResourceFlags, updateModelFlags);
310 // runOperation(op, monitor);
314 * This root is being closed. If this root has an associated source attachment,
319 //protected void closing(Object info) throws JavaModelException { TODO remove after 2.1
320 // ((PackageFragmentRootInfo) info).sourceMapper = null;
321 // super.closing(info);
324 * Compute the package fragment children of this package fragment root.
326 * @exception JavaModelException The resource associated with this package fragment root does not exist
328 //protected boolean computeChildren(OpenableElementInfo info) throws JavaModelException {
330 // // the underlying resource may be a folder or a project (in the case that the project folder
331 // // is actually the package fragment root)
332 // IResource resource = getResource();
333 // if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.PROJECT) {
334 // ArrayList vChildren = new ArrayList(5);
335 // char[][] exclusionPatterns = fullExclusionPatternChars();
336 // computeFolderChildren((IContainer) resource, "", vChildren, exclusionPatterns); //$NON-NLS-1$
337 // IJavaElement[] children = new IJavaElement[vChildren.size()];
338 // vChildren.toArray(children);
339 // info.setChildren(children);
341 // } catch (JavaModelException e) {
342 // //problem resolving children; structure remains unknown
343 // info.setChildren(new IJavaElement[]{});
350 * Starting at this folder, create package fragments and add the fragments that are not exclused
351 * to the collection of children.
353 * @exception JavaModelException The resource associated with this package fragment does not exist
355 //protected void computeFolderChildren(IContainer folder, String prefix, ArrayList vChildren, char[][] exclusionPatterns) throws JavaModelException {
356 // IPackageFragment pkg = getPackageFragment(prefix);
357 // vChildren.add(pkg);
359 // JavaProject javaProject = (JavaProject)getJavaProject();
360 // IResource[] members = folder.members();
361 // for (int i = 0, max = members.length; i < max; i++) {
362 // IResource member = members[i];
363 // String memberName = member.getName();
364 // if (member.getType() == IResource.FOLDER
365 // && Util.isValidFolderNameForPackage(memberName)
366 // && !Util.isExcluded(member, exclusionPatterns)) {
368 // // eliminate binary output only if nested inside direct subfolders
369 // if (javaProject.contains(member)) {
371 // if (prefix.length() == 0) {
372 // newPrefix = memberName;
374 // newPrefix = prefix + "." + memberName; //$NON-NLS-1$
376 // computeFolderChildren((IFolder) member, newPrefix, vChildren, exclusionPatterns);
380 // } catch(IllegalArgumentException e){
381 // throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); // could be thrown by ElementTree when path is not found
382 // } catch (CoreException e) {
383 // throw new JavaModelException(e);
387 * Computes and returns the source attachment root path for the given source attachment path.
388 * Returns <code>null</code> if none could be found.
390 * @param sourceAttachmentPath the given absolute path to the source archive or folder
391 * @return the computed source attachment root path or <code>null</cde> if none could be found
392 * @throws JavaModelException
394 //public IPath computeSourceAttachmentRootPath(IPath sourceAttachmentPath) throws JavaModelException {
395 // IPath sourcePath = this.getSourceAttachmentPath();
396 // if (sourcePath == null) return null;
397 // SourceMapper mapper =
400 // null, // detect root path
401 // this.isExternal() ? JavaCore.getOptions() : this.getJavaProject().getOptions(true) // only project options if associated with resource
403 // if (mapper.rootPath == null) return null;
404 // return new Path(mapper.rootPath);
407 * @see org.eclipse.jdt.core.IPackageFragmentRoot#copy
410 // IPath destination,
411 // int updateResourceFlags,
412 // int updateModelFlags,
413 // IClasspathEntry sibling,
414 // IProgressMonitor monitor)
415 // throws JavaModelException {
417 // CopyPackageFragmentRootOperation op =
418 // new CopyPackageFragmentRootOperation(this, destination, updateResourceFlags, updateModelFlags, sibling);
419 // runOperation(op, monitor);
425 * Returns a new element info for this element.
427 protected Object createElementInfo() {
428 return new PackageFragmentRootInfo();
432 * @see IPackageFragmentRoot
434 //public IPackageFragment createPackageFragment(String name, boolean force, IProgressMonitor monitor) throws JavaModelException {
435 // CreatePackageFragmentOperation op = new CreatePackageFragmentOperation(this, name, force);
436 // runOperation(op, monitor);
437 // return getPackageFragment(name);
441 * Returns the root's kind - K_SOURCE or K_BINARY, defaults
442 * to K_SOURCE if it is not on the classpath.
444 * @exception NotPresentException if the project and root do
447 //protected int determineKind(IResource underlyingResource) throws JavaModelException {
448 // IClasspathEntry[] entries= ((JavaProject)getJavaProject()).getExpandedClasspath(true);
449 // for (int i= 0; i < entries.length; i++) {
450 // IClasspathEntry entry= entries[i];
451 // if (entry.getPath().equals(underlyingResource.getFullPath())) {
452 // return entry.getContentKind();
455 // return IPackageFragmentRoot.K_SOURCE;
459 * Compares two objects for equality;
460 * for <code>PackageFragmentRoot</code>s, equality is having the
461 * same <code>JavaModel</code>, same resources, and occurrence count.
464 public boolean equals(Object o) {
467 if (!(o instanceof PackageFragmentRoot))
469 PackageFragmentRoot other = (PackageFragmentRoot) o;
470 return getJavaModel().equals(other.getJavaModel()) &&
471 this.resource.equals(other.resource) &&
472 occurrenceCount == other.occurrenceCount;
478 //public boolean exists() {
479 // return super.exists()
480 // && isOnClasspath();
483 //public IClasspathEntry findSourceAttachmentRecommendation() {
485 // IPath rootPath = this.getPath();
486 // IClasspathEntry entry;
487 // IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
489 // // try on enclosing project first
490 // JavaProject parentProject = (JavaProject) getJavaProject();
492 // entry = parentProject.getClasspathEntryFor(rootPath);
493 // if (entry != null){
494 // Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
495 // if (target instanceof IFile){
496 // IFile file = (IFile) target;
497 // if (Util.isArchiveFileName(file.getName())){
500 // } else if (target instanceof IFolder) {
503 // if (target instanceof java.io.File){
504 // java.io.File file = (java.io.File) target;
505 // if (file.isFile()) {
506 // if (Util.isArchiveFileName(file.getName())){
510 // // external directory
515 // } catch(JavaModelException e){
518 // // iterate over all projects
519 // IJavaModel model = getJavaModel();
520 // IJavaProject[] jProjects = model.getJavaProjects();
521 // for (int i = 0, max = jProjects.length; i < max; i++){
522 // JavaProject jProject = (JavaProject) jProjects[i];
523 // if (jProject == parentProject) continue; // already done
525 // entry = jProject.getClasspathEntryFor(rootPath);
526 // if (entry != null){
527 // Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
528 // if (target instanceof IFile){
529 // IFile file = (IFile) target;
530 // if (Util.isArchiveFileName(file.getName())){
533 // } else if (target instanceof IFolder) {
536 // if (target instanceof java.io.File){
537 // java.io.File file = (java.io.File) target;
538 // if (file.isFile()) {
539 // if (Util.isArchiveFileName(file.getName())){
543 // // external directory
548 // } catch(JavaModelException e){
551 // } catch(JavaModelException e){
558 * Returns the exclusion patterns from the classpath entry associated with this root.
560 char[][] fullExclusionPatternChars() {
564 // if (this.isOpen() && this.getKind() != IPackageFragmentRoot.K_SOURCE) return null;
565 // ClasspathEntry entry = (ClasspathEntry)getRawClasspathEntry();
566 // if (entry == null) {
569 // return entry.fullExclusionPatternChars();
571 // } catch (JavaModelException e) {
579 protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
581 // ((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
582 // return computeChildren(info);
587 * @see JavaElement#getHandleMemento()
589 protected char getHandleMementoDelimiter() {
590 return JavaElement.JEM_PACKAGEFRAGMENTROOT;
595 public int getElementType() {
596 return PACKAGE_FRAGMENT_ROOT;
599 * @see JavaElement#getHandleMemento()
601 public String getHandleMemento(){
603 IResource resource = getResource();
604 if (resource != null) {
605 // internal jar or regular root
606 if (getResource().getProject().equals(getJavaProject().getProject())) {
607 path = resource.getProjectRelativePath();
609 path = resource.getFullPath();
615 StringBuffer buff= new StringBuffer(((JavaElement)getParent()).getHandleMemento());
616 buff.append(getHandleMementoDelimiter());
617 buff.append(path.toString());
618 return buff.toString();
621 * @see IPackageFragmentRoot
623 public int getKind() throws JavaModelException {
624 return ((PackageFragmentRootInfo)getElementInfo()).getRootKind();
628 * Returns an array of non-java resources contained in the receiver.
630 //public Object[] getNonJavaResources() throws JavaModelException {
631 // return ((PackageFragmentRootInfo) getElementInfo()).getNonJavaResources(getJavaProject(), getResource(), this);
635 * @see IPackageFragmentRoot
637 public IPackageFragment getPackageFragment(String packageName) {
638 if (packageName.indexOf(' ') != -1) { // tolerate package names with spaces (e.g. 'x . y') (http://bugs.eclipse.org/bugs/show_bug.cgi?id=21957)
639 char[][] compoundName = Util.toCompoundChars(packageName);
640 StringBuffer buffer = new StringBuffer(packageName.length());
641 for (int i = 0, length = compoundName.length; i < length; i++) {
642 buffer.append(CharOperation.trim(compoundName[i]));
647 packageName = buffer.toString();
649 return new PackageFragment(this, packageName);
653 * Returns the package name for the given folder
654 * (which is a decendent of this root).
656 protected String getPackageName(IFolder folder) throws JavaModelException {
657 IPath myPath= getPath();
658 IPath pkgPath= folder.getFullPath();
659 int mySegmentCount= myPath.segmentCount();
660 int pkgSegmentCount= pkgPath.segmentCount();
661 StringBuffer name = new StringBuffer(IPackageFragment.DEFAULT_PACKAGE_NAME);
662 for (int i= mySegmentCount; i < pkgSegmentCount; i++) {
663 if (i > mySegmentCount) {
666 name.append(pkgPath.segment(i));
668 return name.toString();
674 public IPath getPath() {
675 return getResource().getFullPath();
679 * @see IPackageFragmentRoot
681 //public IClasspathEntry getRawClasspathEntry() throws JavaModelException {
683 // IClasspathEntry rawEntry = null;
684 // IJavaProject project = this.getJavaProject();
685 // project.getResolvedClasspath(true); // force the reverse rawEntry cache to be populated
686 // JavaModelManager.PerProjectInfo perProjectInfo =
687 // JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project.getProject());
688 // if (perProjectInfo != null && perProjectInfo.resolvedPathToRawEntries != null) {
689 // rawEntry = (IClasspathEntry) perProjectInfo.resolvedPathToRawEntries.get(this.getPath());
697 public IResource getResource() {
698 return (IResource)this.resource;
702 * @see IPackageFragmentRoot
704 //public IPath getSourceAttachmentPath() throws JavaModelException {
705 // if (getKind() != K_BINARY) return null;
707 // String serverPathString= getSourceAttachmentProperty();
708 // if (serverPathString == null) {
711 // int index= serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER);
713 // // no root path specified
714 // return new Path(serverPathString);
716 // String serverSourcePathString= serverPathString.substring(0, index);
717 // return new Path(serverSourcePathString);
722 * Returns the server property for this package fragment root's
723 * source attachement.
725 //protected String getSourceAttachmentProperty() throws JavaModelException {
726 // String propertyString = null;
727 // QualifiedName qName= getSourceAttachmentPropertyName();
729 // propertyString = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qName);
731 // // if no existing source attachment information, then lookup a recommendation from classpath entries
732 // if (propertyString == null) {
733 // IClasspathEntry recommendation = findSourceAttachmentRecommendation();
734 // if (recommendation != null) {
735 // IPath rootPath = recommendation.getSourceAttachmentRootPath();
737 // recommendation.getSourceAttachmentPath().toString()
738 // + ((rootPath == null)
739 // ? "" : //$NON-NLS-1$
740 // (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()));
741 // setSourceAttachmentProperty(propertyString);
743 // // mark as being already looked up
744 // setSourceAttachmentProperty(NO_SOURCE_ATTACHMENT);
746 // } else if (NO_SOURCE_ATTACHMENT.equals(propertyString)) {
747 // // already looked up and no source attachment found
750 // return propertyString;
751 // } catch (CoreException ce) {
752 // throw new JavaModelException(ce);
757 * Returns the qualified name for the source attachment property
760 protected QualifiedName getSourceAttachmentPropertyName() throws JavaModelException {
761 return new QualifiedName(JavaCore.PLUGIN_ID, "sourceattachment: " + this.getPath().toOSString()); //$NON-NLS-1$
764 public void setSourceAttachmentProperty(String property) {
766 ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(this.getSourceAttachmentPropertyName(), property);
767 } catch (CoreException ce) {
772 * For use by <code>AttachSourceOperation</code> only.
773 * Sets the source mapper associated with this root.
775 //public void setSourceMapper(SourceMapper mapper) throws JavaModelException {
776 // ((PackageFragmentRootInfo) getElementInfo()).setSourceMapper(mapper);
782 * @see IPackageFragmentRoot
784 //public IPath getSourceAttachmentRootPath() throws JavaModelException {
785 // if (getKind() != K_BINARY) return null;
787 // String serverPathString= getSourceAttachmentProperty();
788 // if (serverPathString == null) {
791 // int index = serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER);
792 // if (index == -1) return null;
793 // String serverRootPathString= IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
794 // if (index != serverPathString.length() - 1) {
795 // serverRootPathString= serverPathString.substring(index + 1);
797 // return new Path(serverRootPathString);
803 //public SourceMapper getSourceMapper() {
804 // SourceMapper mapper;
806 // PackageFragmentRootInfo rootInfo = (PackageFragmentRootInfo) getElementInfo();
807 // mapper = rootInfo.getSourceMapper();
808 // if (mapper == null) {
809 // // first call to this method
810 // IPath sourcePath= getSourceAttachmentPath();
811 // if (sourcePath != null) {
812 // IPath rootPath= getSourceAttachmentRootPath();
813 // mapper = this.createSourceMapper(sourcePath, rootPath);
814 // if (rootPath == null && mapper.rootPath != null) {
815 // // as a side effect of calling the SourceMapper constructor, the root path was computed
816 // rootPath = new Path(mapper.rootPath);
818 // //set the property to the path of the mapped source
819 // this.setSourceAttachmentProperty(
820 // sourcePath.toString()
821 // + ATTACHMENT_PROPERTY_DELIMITER
822 // + rootPath.toString());
824 // rootInfo.setSourceMapper(mapper);
826 // // remember that no source is attached
827 // rootInfo.setSourceMapper(NO_SOURCE_MAPPER);
830 // } else if (mapper == NO_SOURCE_MAPPER) {
831 // // a previous call to this method found out that no source was attached
834 // } catch (JavaModelException e) {
835 // // no source can be attached
844 public IResource getUnderlyingResource() throws JavaModelException {
845 if (!exists()) throw newNotPresentException();
846 return getResource();
849 public int hashCode() {
850 return this.resource.hashCode();
854 * @see IPackageFragmentRoot
856 public boolean isArchive() {
861 * @see IPackageFragmentRoot
863 public boolean isExternal() {
868 * Returns whether this package fragment root is on the classpath of its project.
870 //protected boolean isOnClasspath() {
871 // if (this.getElementType() == IJavaElement.JAVA_PROJECT){
875 // IPath path = this.getPath();
877 // // check package fragment root on classpath of its project
878 // IJavaProject project = this.getJavaProject();
879 // IClasspathEntry[] classpath = project.getResolvedClasspath(true);
880 // for (int i = 0, length = classpath.length; i < length; i++) {
881 // IClasspathEntry entry = classpath[i];
882 // if (entry.getPath().equals(path)) {
886 // } catch(JavaModelException e){
887 // // could not read classpath, then assume it is outside
892 * @see org.eclipse.jdt.core.IPackageFragmentRoot#move
895 // IPath destination,
896 // int updateResourceFlags,
897 // int updateModelFlags,
898 // IClasspathEntry sibling,
899 // IProgressMonitor monitor)
900 // throws JavaModelException {
902 // MovePackageFragmentRootOperation op =
903 // new MovePackageFragmentRootOperation(this, destination, updateResourceFlags, updateModelFlags, sibling);
904 // runOperation(op, monitor);
908 //protected void openWhenClosed(IProgressMonitor pm) throws JavaModelException {
909 // if (!this.resourceExists()
910 // || !this.isOnClasspath()) {
911 // throw newNotPresentException();
913 // super.openWhenClosed(pm);
917 * Recomputes the children of this element, based on the current state
920 //public void refreshChildren() {
922 // OpenableElementInfo info= (OpenableElementInfo)getElementInfo();
923 // computeChildren(info);
924 // } catch (JavaModelException e) {
930 // * @see JavaElement#rootedAt(IJavaProject)
932 //public IJavaElement rootedAt(IJavaProject project) {
934 // new PackageFragmentRoot(
941 * @private Debugging purposes
943 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
944 buffer.append(this.tabString(tab));
945 if (getElementName().length() == 0) {
946 buffer.append("[project root]"); //$NON-NLS-1$
948 IPath path = getPath();
949 if (getJavaProject().getElementName().equals(path.segment(0))) {
950 buffer.append(path.removeFirstSegments(1).makeRelative());
956 buffer.append(" (not open)"); //$NON-NLS-1$
961 * Possible failures: <ul>
962 * <li>ELEMENT_NOT_PRESENT - the root supplied to the operation
964 * <li>INVALID_ELEMENT_TYPES - the root is not of kind K_BINARY
965 * <li>RELATIVE_PATH - the path supplied to this operation must be
969 //protected void verifyAttachSource(IPath sourcePath) throws JavaModelException {
971 // throw newNotPresentException();
972 // } else if (this.getKind() != K_BINARY) {
973 // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this));
974 // } else if (sourcePath != null && !sourcePath.isAbsolute()) {
975 // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.RELATIVE_PATH, sourcePath));