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.IJavaModelStatusConstants;
18 import net.sourceforge.phpdt.core.IPackageFragment;
19 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
20 import net.sourceforge.phpdt.core.JavaCore;
21 import net.sourceforge.phpdt.core.JavaModelException;
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;
36 * @see IPackageFragmentRoot
38 public class PackageFragmentRoot extends Openable implements IPackageFragmentRoot {
41 * The delimiter between the source path and root path in the
42 * attachment server property.
44 protected final static char ATTACHMENT_PROPERTY_DELIMITER= '*';
46 * No source attachment property
48 protected final static String NO_SOURCE_ATTACHMENT = ""; //$NON-NLS-1$
50 * No source mapper singleton
52 // protected final static SourceMapper NO_SOURCE_MAPPER = new SourceMapper();
55 * The resource associated with this root.
56 * (an IResource or a java.io.File (for external jar only))
58 protected Object resource;
61 * Constructs a package fragment root which is the root of the java package
62 * directory hierarchy.
64 protected PackageFragmentRoot(IResource resource, JavaProject project, String name) {
66 this.resource = resource;
72 protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
74 // check whether this pkg fragment root can be opened
75 if (!resourceExists() ) { //|| !isOnClasspath()) {
76 throw newNotPresentException();
79 ((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
80 return computeChildren(info, newElements);
83 * Returns the root's kind - K_SOURCE or K_BINARY, defaults
84 * to K_SOURCE if it is not on the classpath.
86 * @exception NotPresentException if the project and root do
89 protected int determineKind(IResource underlyingResource) throws JavaModelException {
90 // IClasspathEntry[] entries= ((JavaProject)getJavaProject()).getExpandedClasspath(true);
91 // for (int i= 0; i < entries.length; i++) {
92 // IClasspathEntry entry= entries[i];
93 // if (entry.getPath().equals(underlyingResource.getFullPath())) {
94 // return entry.getContentKind();
97 return IPackageFragmentRoot.K_SOURCE;
100 * Compute the package fragment children of this package fragment root.
102 * @exception JavaModelException The resource associated with this package fragment root does not exist
104 protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws JavaModelException {
105 // Note the children are not opened (so not added to newElements) for a regular package fragment root
106 // Howver they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren)
108 // the underlying resource may be a folder or a project (in the case that the project folder
109 // is actually the package fragment root)
110 IResource underlyingResource = getResource();
111 if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
112 ArrayList vChildren = new ArrayList(5);
113 IContainer rootFolder = (IContainer) underlyingResource;
114 // char[][] inclusionPatterns = fullInclusionPatternChars();
115 char[][] exclusionPatterns = fullExclusionPatternChars();
116 computeFolderChildren(rootFolder, !Util.isExcluded(rootFolder, exclusionPatterns), "", vChildren, exclusionPatterns); //$NON-NLS-1$
118 IJavaElement[] children = new IJavaElement[vChildren.size()];
119 vChildren.toArray(children);
120 info.setChildren(children);
122 } catch (JavaModelException e) {
123 //problem resolving children; structure remains unknown
124 info.setChildren(new IJavaElement[]{});
130 * Starting at this folder, create package fragments and add the fragments that are not exclused
131 * to the collection of children.
133 * @exception JavaModelException The resource associated with this package fragment does not exist
135 protected void computeFolderChildren(IContainer folder, boolean isIncluded, String prefix, ArrayList vChildren, char[][] exclusionPatterns) throws JavaModelException {
136 //, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException {
139 IPackageFragment pkg = getPackageFragment(prefix);
143 JavaProject javaProject = (JavaProject)getJavaProject();
144 IResource[] members = folder.members();
145 boolean hasIncluded = isIncluded;
146 for (int i = 0, max = members.length; i < max; i++) {
147 IResource member = members[i];
148 String memberName = member.getName();
150 switch(member.getType()) {
152 case IResource.FOLDER:
153 if (Util.isValidFolderNameForPackage(memberName)) {
154 boolean isMemberIncluded = !Util.isExcluded(member, exclusionPatterns);
155 // keep looking inside as long as included already, or may have child included due to inclusion patterns
156 // if (isMemberIncluded || inclusionPatterns != null) {
157 // // eliminate binary output only if nested inside direct subfolders
158 // if (javaProject.contains(member)) {
160 // if (prefix.length() == 0) {
161 // newPrefix = memberName;
163 // newPrefix = prefix + "." + memberName; //$NON-NLS-1$
165 // computeFolderChildren((IFolder) member, isMemberIncluded, newPrefix, vChildren, inclusionPatterns, exclusionPatterns);
171 // inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
173 && Util.isValidCompilationUnitName(memberName)
174 && !Util.isExcluded(member, exclusionPatterns)) {
176 IPackageFragment pkg = getPackageFragment(prefix);
182 } catch(IllegalArgumentException e){
183 throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); // could be thrown by ElementTree when path is not found
184 } catch (CoreException e) {
185 throw new JavaModelException(e);
189 * @see IPackageFragmentRoot
191 //public void attachSource(IPath sourcePath, IPath rootPath, IProgressMonitor monitor) throws JavaModelException {
193 // verifyAttachSource(sourcePath);
194 // if (monitor != null) {
195 // monitor.beginTask(Util.bind("element.attachingSource"), 2); //$NON-NLS-1$
197 // SourceMapper oldMapper= getSourceMapper();
198 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
199 // boolean rootNeedsToBeClosed= false;
201 // if (sourcePath == null) {
202 // //source being detached
203 // rootNeedsToBeClosed= true;
204 // setSourceMapper(null);
205 // /* Disable deltas (see 1GDTUSD)
206 // // fire a delta to notify the UI about the source detachement.
207 // JavaModelManager manager = (JavaModelManager) JavaModelManager.getJavaModelManager();
208 // JavaModel model = (JavaModel) getJavaModel();
209 // JavaElementDelta attachedSourceDelta = new JavaElementDelta(model);
210 // attachedSourceDelta .sourceDetached(this); // this would be a PackageFragmentRoot
211 // manager.registerResourceDelta(attachedSourceDelta );
212 // manager.fire(); // maybe you want to fire the change later. Let us know about it.
216 // // fire a delta to notify the UI about the source attachement.
217 // JavaModelManager manager = (JavaModelManager) JavaModelManager.getJavaModelManager();
218 // JavaModel model = (JavaModel) getJavaModel();
219 // JavaElementDelta attachedSourceDelta = new JavaElementDelta(model);
220 // attachedSourceDelta .sourceAttached(this); // this would be a PackageFragmentRoot
221 // manager.registerResourceDelta(attachedSourceDelta );
222 // manager.fire(); // maybe you want to fire the change later. Let us know about it.
225 // //check if different from the current attachment
226 // IPath storedSourcePath= getSourceAttachmentPath();
227 // IPath storedRootPath= getSourceAttachmentRootPath();
228 // if (monitor != null) {
229 // monitor.worked(1);
231 // if (storedSourcePath != null) {
232 // if (!(storedSourcePath.equals(sourcePath) && (rootPath != null && rootPath.equals(storedRootPath)) || storedRootPath == null)) {
233 // rootNeedsToBeClosed= true;
236 // // check if source path is valid
237 // Object target = JavaModel.getTarget(workspace.getRoot(), sourcePath, false);
238 // if (target == null) {
239 // if (monitor != null) {
242 // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, sourcePath));
244 // SourceMapper mapper = createSourceMapper(sourcePath, rootPath);
245 // if (rootPath == null && mapper.rootPath != null) {
246 // // as a side effect of calling the SourceMapper constructor, the root path was computed
247 // rootPath = new Path(mapper.rootPath);
249 // setSourceMapper(mapper);
251 // if (sourcePath == null) {
252 // setSourceAttachmentProperty(null); //remove the property
254 // //set the property to the path of the mapped source
255 // setSourceAttachmentProperty(
256 // sourcePath.toString()
257 // + (rootPath == null ? "" : (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()))); //$NON-NLS-1$
259 // if (rootNeedsToBeClosed) {
260 // if (oldMapper != null) {
261 // oldMapper.close();
263 // BufferManager manager= BufferManager.getDefaultBufferManager();
264 // Enumeration openBuffers= manager.getOpenBuffers();
265 // while (openBuffers.hasMoreElements()) {
266 // IBuffer buffer= (IBuffer) openBuffers.nextElement();
267 // IOpenable possibleMember= buffer.getOwner();
268 // if (isAncestorOf((IJavaElement) possibleMember)) {
272 // if (monitor != null) {
273 // monitor.worked(1);
276 // } catch (JavaModelException e) {
277 // setSourceAttachmentProperty(null); // loose info - will be recomputed
280 // if (monitor != null) {
286 //SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) {
287 // SourceMapper mapper = new SourceMapper(
289 // rootPath == null ? null : rootPath.toOSString(),
290 // this.isExternal() ? JavaCore.getOptions() : this.getJavaProject().getOptions(true)); // only project options if associated with resource
294 * @see org.eclipse.jdt.core.IPackageFragmentRoot#delete
296 //public void delete(
297 // int updateResourceFlags,
298 // int updateModelFlags,
299 // IProgressMonitor monitor)
300 // throws JavaModelException {
302 // DeletePackageFragmentRootOperation op = new DeletePackageFragmentRootOperation(this, updateResourceFlags, updateModelFlags);
303 // runOperation(op, monitor);
307 * This root is being closed. If this root has an associated source attachment,
312 //protected void closing(Object info) throws JavaModelException { TODO remove after 2.1
313 // ((PackageFragmentRootInfo) info).sourceMapper = null;
314 // super.closing(info);
317 * Compute the package fragment children of this package fragment root.
319 * @exception JavaModelException The resource associated with this package fragment root does not exist
321 //protected boolean computeChildren(OpenableElementInfo info) throws JavaModelException {
323 // // the underlying resource may be a folder or a project (in the case that the project folder
324 // // is actually the package fragment root)
325 // IResource resource = getResource();
326 // if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.PROJECT) {
327 // ArrayList vChildren = new ArrayList(5);
328 // char[][] exclusionPatterns = fullExclusionPatternChars();
329 // computeFolderChildren((IContainer) resource, "", vChildren, exclusionPatterns); //$NON-NLS-1$
330 // IJavaElement[] children = new IJavaElement[vChildren.size()];
331 // vChildren.toArray(children);
332 // info.setChildren(children);
334 // } catch (JavaModelException e) {
335 // //problem resolving children; structure remains unknown
336 // info.setChildren(new IJavaElement[]{});
343 * Starting at this folder, create package fragments and add the fragments that are not exclused
344 * to the collection of children.
346 * @exception JavaModelException The resource associated with this package fragment does not exist
348 //protected void computeFolderChildren(IContainer folder, String prefix, ArrayList vChildren, char[][] exclusionPatterns) throws JavaModelException {
349 // IPackageFragment pkg = getPackageFragment(prefix);
350 // vChildren.add(pkg);
352 // JavaProject javaProject = (JavaProject)getJavaProject();
353 // IResource[] members = folder.members();
354 // for (int i = 0, max = members.length; i < max; i++) {
355 // IResource member = members[i];
356 // String memberName = member.getName();
357 // if (member.getType() == IResource.FOLDER
358 // && Util.isValidFolderNameForPackage(memberName)
359 // && !Util.isExcluded(member, exclusionPatterns)) {
361 // // eliminate binary output only if nested inside direct subfolders
362 // if (javaProject.contains(member)) {
364 // if (prefix.length() == 0) {
365 // newPrefix = memberName;
367 // newPrefix = prefix + "." + memberName; //$NON-NLS-1$
369 // computeFolderChildren((IFolder) member, newPrefix, vChildren, exclusionPatterns);
373 // } catch(IllegalArgumentException e){
374 // throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); // could be thrown by ElementTree when path is not found
375 // } catch (CoreException e) {
376 // throw new JavaModelException(e);
380 * Computes and returns the source attachment root path for the given source attachment path.
381 * Returns <code>null</code> if none could be found.
383 * @param sourceAttachmentPath the given absolute path to the source archive or folder
384 * @return the computed source attachment root path or <code>null</cde> if none could be found
385 * @throws JavaModelException
387 //public IPath computeSourceAttachmentRootPath(IPath sourceAttachmentPath) throws JavaModelException {
388 // IPath sourcePath = this.getSourceAttachmentPath();
389 // if (sourcePath == null) return null;
390 // SourceMapper mapper =
393 // null, // detect root path
394 // this.isExternal() ? JavaCore.getOptions() : this.getJavaProject().getOptions(true) // only project options if associated with resource
396 // if (mapper.rootPath == null) return null;
397 // return new Path(mapper.rootPath);
400 * @see org.eclipse.jdt.core.IPackageFragmentRoot#copy
403 // IPath destination,
404 // int updateResourceFlags,
405 // int updateModelFlags,
406 // IClasspathEntry sibling,
407 // IProgressMonitor monitor)
408 // throws JavaModelException {
410 // CopyPackageFragmentRootOperation op =
411 // new CopyPackageFragmentRootOperation(this, destination, updateResourceFlags, updateModelFlags, sibling);
412 // runOperation(op, monitor);
418 * Returns a new element info for this element.
420 protected Object createElementInfo() {
421 return new PackageFragmentRootInfo();
425 * @see IPackageFragmentRoot
427 //public IPackageFragment createPackageFragment(String name, boolean force, IProgressMonitor monitor) throws JavaModelException {
428 // CreatePackageFragmentOperation op = new CreatePackageFragmentOperation(this, name, force);
429 // runOperation(op, monitor);
430 // return getPackageFragment(name);
434 * Returns the root's kind - K_SOURCE or K_BINARY, defaults
435 * to K_SOURCE if it is not on the classpath.
437 * @exception NotPresentException if the project and root do
440 //protected int determineKind(IResource underlyingResource) throws JavaModelException {
441 // IClasspathEntry[] entries= ((JavaProject)getJavaProject()).getExpandedClasspath(true);
442 // for (int i= 0; i < entries.length; i++) {
443 // IClasspathEntry entry= entries[i];
444 // if (entry.getPath().equals(underlyingResource.getFullPath())) {
445 // return entry.getContentKind();
448 // return IPackageFragmentRoot.K_SOURCE;
452 * Compares two objects for equality;
453 * for <code>PackageFragmentRoot</code>s, equality is having the
454 * same <code>JavaModel</code>, same resources, and occurrence count.
457 public boolean equals(Object o) {
460 if (!(o instanceof PackageFragmentRoot))
462 PackageFragmentRoot other = (PackageFragmentRoot) o;
463 return getJavaModel().equals(other.getJavaModel()) &&
464 this.resource.equals(other.resource) &&
465 occurrenceCount == other.occurrenceCount;
471 //public boolean exists() {
472 // return super.exists()
473 // && isOnClasspath();
476 //public IClasspathEntry findSourceAttachmentRecommendation() {
478 // IPath rootPath = this.getPath();
479 // IClasspathEntry entry;
480 // IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
482 // // try on enclosing project first
483 // JavaProject parentProject = (JavaProject) getJavaProject();
485 // entry = parentProject.getClasspathEntryFor(rootPath);
486 // if (entry != null){
487 // Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
488 // if (target instanceof IFile){
489 // IFile file = (IFile) target;
490 // if (Util.isArchiveFileName(file.getName())){
493 // } else if (target instanceof IFolder) {
496 // if (target instanceof java.io.File){
497 // java.io.File file = (java.io.File) target;
498 // if (file.isFile()) {
499 // if (Util.isArchiveFileName(file.getName())){
503 // // external directory
508 // } catch(JavaModelException e){
511 // // iterate over all projects
512 // IJavaModel model = getJavaModel();
513 // IJavaProject[] jProjects = model.getJavaProjects();
514 // for (int i = 0, max = jProjects.length; i < max; i++){
515 // JavaProject jProject = (JavaProject) jProjects[i];
516 // if (jProject == parentProject) continue; // already done
518 // entry = jProject.getClasspathEntryFor(rootPath);
519 // if (entry != null){
520 // Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
521 // if (target instanceof IFile){
522 // IFile file = (IFile) target;
523 // if (Util.isArchiveFileName(file.getName())){
526 // } else if (target instanceof IFolder) {
529 // if (target instanceof java.io.File){
530 // java.io.File file = (java.io.File) target;
531 // if (file.isFile()) {
532 // if (Util.isArchiveFileName(file.getName())){
536 // // external directory
541 // } catch(JavaModelException e){
544 // } catch(JavaModelException e){
551 * Returns the exclusion patterns from the classpath entry associated with this root.
553 char[][] fullExclusionPatternChars() {
557 // if (this.isOpen() && this.getKind() != IPackageFragmentRoot.K_SOURCE) return null;
558 // ClasspathEntry entry = (ClasspathEntry)getRawClasspathEntry();
559 // if (entry == null) {
562 // return entry.fullExclusionPatternChars();
564 // } catch (JavaModelException e) {
572 protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
574 // ((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
575 // return computeChildren(info);
580 * @see JavaElement#getHandleMemento()
582 protected char getHandleMementoDelimiter() {
583 return JavaElement.JEM_PACKAGEFRAGMENTROOT;
588 public int getElementType() {
589 return PACKAGE_FRAGMENT_ROOT;
592 * @see JavaElement#getHandleMemento()
594 public String getHandleMemento(){
596 IResource resource = getResource();
597 if (resource != null) {
598 // internal jar or regular root
599 if (getResource().getProject().equals(getJavaProject().getProject())) {
600 path = resource.getProjectRelativePath();
602 path = resource.getFullPath();
608 StringBuffer buff= new StringBuffer(((JavaElement)getParent()).getHandleMemento());
609 buff.append(getHandleMementoDelimiter());
610 buff.append(path.toString());
611 return buff.toString();
614 * @see IPackageFragmentRoot
616 public int getKind() throws JavaModelException {
617 return ((PackageFragmentRootInfo)getElementInfo()).getRootKind();
621 * Returns an array of non-java resources contained in the receiver.
623 //public Object[] getNonJavaResources() throws JavaModelException {
624 // return ((PackageFragmentRootInfo) getElementInfo()).getNonJavaResources(getJavaProject(), getResource(), this);
628 * @see IPackageFragmentRoot
630 public IPackageFragment getPackageFragment(String packageName) {
631 if (packageName.indexOf(' ') != -1) { // tolerate package names with spaces (e.g. 'x . y') (http://bugs.eclipse.org/bugs/show_bug.cgi?id=21957)
632 char[][] compoundName = Util.toCompoundChars(packageName);
633 StringBuffer buffer = new StringBuffer(packageName.length());
634 for (int i = 0, length = compoundName.length; i < length; i++) {
635 buffer.append(CharOperation.trim(compoundName[i]));
640 packageName = buffer.toString();
642 return new PackageFragment(this, packageName);
646 * Returns the package name for the given folder
647 * (which is a decendent of this root).
649 protected String getPackageName(IFolder folder) throws JavaModelException {
650 IPath myPath= getPath();
651 IPath pkgPath= folder.getFullPath();
652 int mySegmentCount= myPath.segmentCount();
653 int pkgSegmentCount= pkgPath.segmentCount();
654 StringBuffer name = new StringBuffer(IPackageFragment.DEFAULT_PACKAGE_NAME);
655 for (int i= mySegmentCount; i < pkgSegmentCount; i++) {
656 if (i > mySegmentCount) {
659 name.append(pkgPath.segment(i));
661 return name.toString();
667 public IPath getPath() {
668 return getResource().getFullPath();
672 * @see IPackageFragmentRoot
674 //public IClasspathEntry getRawClasspathEntry() throws JavaModelException {
676 // IClasspathEntry rawEntry = null;
677 // IJavaProject project = this.getJavaProject();
678 // project.getResolvedClasspath(true); // force the reverse rawEntry cache to be populated
679 // JavaModelManager.PerProjectInfo perProjectInfo =
680 // JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project.getProject());
681 // if (perProjectInfo != null && perProjectInfo.resolvedPathToRawEntries != null) {
682 // rawEntry = (IClasspathEntry) perProjectInfo.resolvedPathToRawEntries.get(this.getPath());
690 public IResource getResource() {
691 return (IResource)this.resource;
695 * @see IPackageFragmentRoot
697 //public IPath getSourceAttachmentPath() throws JavaModelException {
698 // if (getKind() != K_BINARY) return null;
700 // String serverPathString= getSourceAttachmentProperty();
701 // if (serverPathString == null) {
704 // int index= serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER);
706 // // no root path specified
707 // return new Path(serverPathString);
709 // String serverSourcePathString= serverPathString.substring(0, index);
710 // return new Path(serverSourcePathString);
715 * Returns the server property for this package fragment root's
716 * source attachement.
718 //protected String getSourceAttachmentProperty() throws JavaModelException {
719 // String propertyString = null;
720 // QualifiedName qName= getSourceAttachmentPropertyName();
722 // propertyString = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qName);
724 // // if no existing source attachment information, then lookup a recommendation from classpath entries
725 // if (propertyString == null) {
726 // IClasspathEntry recommendation = findSourceAttachmentRecommendation();
727 // if (recommendation != null) {
728 // IPath rootPath = recommendation.getSourceAttachmentRootPath();
730 // recommendation.getSourceAttachmentPath().toString()
731 // + ((rootPath == null)
732 // ? "" : //$NON-NLS-1$
733 // (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()));
734 // setSourceAttachmentProperty(propertyString);
736 // // mark as being already looked up
737 // setSourceAttachmentProperty(NO_SOURCE_ATTACHMENT);
739 // } else if (NO_SOURCE_ATTACHMENT.equals(propertyString)) {
740 // // already looked up and no source attachment found
743 // return propertyString;
744 // } catch (CoreException ce) {
745 // throw new JavaModelException(ce);
750 * Returns the qualified name for the source attachment property
753 protected QualifiedName getSourceAttachmentPropertyName() throws JavaModelException {
754 return new QualifiedName(JavaCore.PLUGIN_ID, "sourceattachment: " + this.getPath().toOSString()); //$NON-NLS-1$
757 public void setSourceAttachmentProperty(String property) {
759 ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(this.getSourceAttachmentPropertyName(), property);
760 } catch (CoreException ce) {
765 * For use by <code>AttachSourceOperation</code> only.
766 * Sets the source mapper associated with this root.
768 //public void setSourceMapper(SourceMapper mapper) throws JavaModelException {
769 // ((PackageFragmentRootInfo) getElementInfo()).setSourceMapper(mapper);
775 * @see IPackageFragmentRoot
777 //public IPath getSourceAttachmentRootPath() throws JavaModelException {
778 // if (getKind() != K_BINARY) return null;
780 // String serverPathString= getSourceAttachmentProperty();
781 // if (serverPathString == null) {
784 // int index = serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER);
785 // if (index == -1) return null;
786 // String serverRootPathString= IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
787 // if (index != serverPathString.length() - 1) {
788 // serverRootPathString= serverPathString.substring(index + 1);
790 // return new Path(serverRootPathString);
796 //public SourceMapper getSourceMapper() {
797 // SourceMapper mapper;
799 // PackageFragmentRootInfo rootInfo = (PackageFragmentRootInfo) getElementInfo();
800 // mapper = rootInfo.getSourceMapper();
801 // if (mapper == null) {
802 // // first call to this method
803 // IPath sourcePath= getSourceAttachmentPath();
804 // if (sourcePath != null) {
805 // IPath rootPath= getSourceAttachmentRootPath();
806 // mapper = this.createSourceMapper(sourcePath, rootPath);
807 // if (rootPath == null && mapper.rootPath != null) {
808 // // as a side effect of calling the SourceMapper constructor, the root path was computed
809 // rootPath = new Path(mapper.rootPath);
811 // //set the property to the path of the mapped source
812 // this.setSourceAttachmentProperty(
813 // sourcePath.toString()
814 // + ATTACHMENT_PROPERTY_DELIMITER
815 // + rootPath.toString());
817 // rootInfo.setSourceMapper(mapper);
819 // // remember that no source is attached
820 // rootInfo.setSourceMapper(NO_SOURCE_MAPPER);
823 // } else if (mapper == NO_SOURCE_MAPPER) {
824 // // a previous call to this method found out that no source was attached
827 // } catch (JavaModelException e) {
828 // // no source can be attached
837 public IResource getUnderlyingResource() throws JavaModelException {
838 if (!exists()) throw newNotPresentException();
839 return getResource();
842 public int hashCode() {
843 return this.resource.hashCode();
847 * @see IPackageFragmentRoot
849 public boolean isArchive() {
854 * @see IPackageFragmentRoot
856 public boolean isExternal() {
861 * Returns whether this package fragment root is on the classpath of its project.
863 //protected boolean isOnClasspath() {
864 // if (this.getElementType() == IJavaElement.JAVA_PROJECT){
868 // IPath path = this.getPath();
870 // // check package fragment root on classpath of its project
871 // IJavaProject project = this.getJavaProject();
872 // IClasspathEntry[] classpath = project.getResolvedClasspath(true);
873 // for (int i = 0, length = classpath.length; i < length; i++) {
874 // IClasspathEntry entry = classpath[i];
875 // if (entry.getPath().equals(path)) {
879 // } catch(JavaModelException e){
880 // // could not read classpath, then assume it is outside
885 * @see org.eclipse.jdt.core.IPackageFragmentRoot#move
888 // IPath destination,
889 // int updateResourceFlags,
890 // int updateModelFlags,
891 // IClasspathEntry sibling,
892 // IProgressMonitor monitor)
893 // throws JavaModelException {
895 // MovePackageFragmentRootOperation op =
896 // new MovePackageFragmentRootOperation(this, destination, updateResourceFlags, updateModelFlags, sibling);
897 // runOperation(op, monitor);
901 //protected void openWhenClosed(IProgressMonitor pm) throws JavaModelException {
902 // if (!this.resourceExists()
903 // || !this.isOnClasspath()) {
904 // throw newNotPresentException();
906 // super.openWhenClosed(pm);
910 * Recomputes the children of this element, based on the current state
913 //public void refreshChildren() {
915 // OpenableElementInfo info= (OpenableElementInfo)getElementInfo();
916 // computeChildren(info);
917 // } catch (JavaModelException e) {
923 // * @see JavaElement#rootedAt(IJavaProject)
925 //public IJavaElement rootedAt(IJavaProject project) {
927 // new PackageFragmentRoot(
934 * @private Debugging purposes
936 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
937 buffer.append(this.tabString(tab));
938 if (getElementName().length() == 0) {
939 buffer.append("[project root]"); //$NON-NLS-1$
941 IPath path = getPath();
942 if (getJavaProject().getElementName().equals(path.segment(0))) {
943 buffer.append(path.removeFirstSegments(1).makeRelative());
949 buffer.append(" (not open)"); //$NON-NLS-1$
954 * Possible failures: <ul>
955 * <li>ELEMENT_NOT_PRESENT - the root supplied to the operation
957 * <li>INVALID_ELEMENT_TYPES - the root is not of kind K_BINARY
958 * <li>RELATIVE_PATH - the path supplied to this operation must be
962 //protected void verifyAttachSource(IPath sourcePath) throws JavaModelException {
964 // throw newNotPresentException();
965 // } else if (this.getKind() != K_BINARY) {
966 // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this));
967 // } else if (sourcePath != null && !sourcePath.isAbsolute()) {
968 // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.RELATIVE_PATH, sourcePath));