Lines 38-48
Link Here
|
38 |
* attachment server property. |
38 |
* attachment server property. |
39 |
*/ |
39 |
*/ |
40 |
protected final static char ATTACHMENT_PROPERTY_DELIMITER= '*'; |
40 |
protected final static char ATTACHMENT_PROPERTY_DELIMITER= '*'; |
41 |
/* |
|
|
42 |
* No source attachment property |
43 |
*/ |
44 |
protected final static String NO_SOURCE_ATTACHMENT = ""; //$NON-NLS-1$ |
45 |
|
46 |
/** |
41 |
/** |
47 |
* The resource associated with this root. |
42 |
* The resource associated with this root. |
48 |
* (an IResource or a java.io.File (for external jar only)) |
43 |
* (an IResource or a java.io.File (for external jar only)) |
Lines 316-327
Link Here
|
316 |
* not exist. |
311 |
* not exist. |
317 |
*/ |
312 |
*/ |
318 |
protected int determineKind(IResource underlyingResource) throws JavaModelException { |
313 |
protected int determineKind(IResource underlyingResource) throws JavaModelException { |
319 |
IClasspathEntry[] entries= ((JavaProject)getJavaProject()).getResolvedClasspath(); |
314 |
IClasspathEntry entry = ((JavaProject)getJavaProject()).getClasspathEntryFor(underlyingResource.getFullPath()); |
320 |
for (int i= 0; i < entries.length; i++) { |
315 |
if (entry != null) { |
321 |
IClasspathEntry entry= entries[i]; |
316 |
return entry.getContentKind(); |
322 |
if (entry.getPath().equals(underlyingResource.getFullPath())) { |
|
|
323 |
return entry.getContentKind(); |
324 |
} |
325 |
} |
317 |
} |
326 |
return IPackageFragmentRoot.K_SOURCE; |
318 |
return IPackageFragmentRoot.K_SOURCE; |
327 |
} |
319 |
} |
Lines 349-355
Link Here
|
349 |
return super.exists() && validateOnClasspath().isOK(); |
341 |
return super.exists() && validateOnClasspath().isOK(); |
350 |
} |
342 |
} |
351 |
|
343 |
|
352 |
public IClasspathEntry findSourceAttachmentRecommendation() { |
344 |
private IClasspathEntry findSourceAttachmentRecommendation() { |
353 |
try { |
345 |
try { |
354 |
IPath rootPath = this.getPath(); |
346 |
IPath rootPath = this.getPath(); |
355 |
IClasspathEntry entry; |
347 |
IClasspathEntry entry; |
Lines 607-658
Link Here
|
607 |
public IPath getSourceAttachmentPath() throws JavaModelException { |
599 |
public IPath getSourceAttachmentPath() throws JavaModelException { |
608 |
if (getKind() != K_BINARY) return null; |
600 |
if (getKind() != K_BINARY) return null; |
609 |
|
601 |
|
|
|
602 |
// 1) look source attachment property (set iff attachSource(...) was called |
610 |
String serverPathString= getSourceAttachmentProperty(); |
603 |
String serverPathString= getSourceAttachmentProperty(); |
611 |
if (serverPathString == null) { |
604 |
if (serverPathString != null) { |
612 |
return null; |
605 |
int index= serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
|
|
606 |
if (index < 0) { |
607 |
// no root path specified |
608 |
return new Path(serverPathString); |
609 |
} else { |
610 |
String serverSourcePathString= serverPathString.substring(0, index); |
611 |
return new Path(serverSourcePathString); |
612 |
} |
613 |
} |
613 |
} |
614 |
int index= serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
614 |
|
615 |
if (index < 0) { |
615 |
// 2) look at classpath entry |
616 |
// no root path specified |
616 |
IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(getPath()); |
617 |
return new Path(serverPathString); |
617 |
IPath sourceAttachmentPath; |
618 |
} else { |
618 |
if (entry != null && (sourceAttachmentPath = entry.getSourceAttachmentPath()) != null) |
619 |
String serverSourcePathString= serverPathString.substring(0, index); |
619 |
return sourceAttachmentPath; |
620 |
return new Path(serverSourcePathString); |
620 |
|
|
|
621 |
// 3) look for a recommendation |
622 |
entry = findSourceAttachmentRecommendation(); |
623 |
if (entry != null && (sourceAttachmentPath = entry.getSourceAttachmentPath()) != null) { |
624 |
return sourceAttachmentPath; |
621 |
} |
625 |
} |
|
|
626 |
|
627 |
return null; |
622 |
} |
628 |
} |
623 |
|
629 |
|
624 |
/** |
630 |
/** |
625 |
* Returns the server property for this package fragment root's |
631 |
* Returns the server property for this package fragment root's |
626 |
* source attachement. |
632 |
* source attachement. |
627 |
*/ |
633 |
*/ |
628 |
protected String getSourceAttachmentProperty() throws JavaModelException { |
634 |
private String getSourceAttachmentProperty() throws JavaModelException { |
629 |
String propertyString = null; |
|
|
630 |
QualifiedName qName= getSourceAttachmentPropertyName(); |
631 |
try { |
635 |
try { |
632 |
propertyString = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qName); |
636 |
QualifiedName qName= getSourceAttachmentPropertyName(); |
633 |
|
637 |
return ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qName); |
634 |
// if no existing source attachment information, then lookup a recommendation from classpath entries |
638 |
} catch (CoreException e) { |
635 |
if (propertyString == null) { |
639 |
throw new JavaModelException(e); |
636 |
IClasspathEntry recommendation = findSourceAttachmentRecommendation(); |
|
|
637 |
if (recommendation != null) { |
638 |
IPath rootPath = recommendation.getSourceAttachmentRootPath(); |
639 |
propertyString = |
640 |
recommendation.getSourceAttachmentPath().toString() |
641 |
+ ((rootPath == null) |
642 |
? "" : //$NON-NLS-1$ |
643 |
(ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString())); |
644 |
setSourceAttachmentProperty(propertyString); |
645 |
} else { |
646 |
// mark as being already looked up |
647 |
setSourceAttachmentProperty(NO_SOURCE_ATTACHMENT); |
648 |
} |
649 |
} else if (NO_SOURCE_ATTACHMENT.equals(propertyString)) { |
650 |
// already looked up and no source attachment found |
651 |
return null; |
652 |
} |
653 |
return propertyString; |
654 |
} catch (CoreException ce) { |
655 |
throw new JavaModelException(ce); |
656 |
} |
640 |
} |
657 |
} |
641 |
} |
658 |
|
642 |
|
Lines 660-666
Link Here
|
660 |
* Returns the qualified name for the source attachment property |
644 |
* Returns the qualified name for the source attachment property |
661 |
* of this root. |
645 |
* of this root. |
662 |
*/ |
646 |
*/ |
663 |
protected QualifiedName getSourceAttachmentPropertyName() { |
647 |
private QualifiedName getSourceAttachmentPropertyName() { |
664 |
return new QualifiedName(JavaCore.PLUGIN_ID, "sourceattachment: " + this.getPath().toOSString()); //$NON-NLS-1$ |
648 |
return new QualifiedName(JavaCore.PLUGIN_ID, "sourceattachment: " + this.getPath().toOSString()); //$NON-NLS-1$ |
665 |
} |
649 |
} |
666 |
|
650 |
|
Lines 688-704
Link Here
|
688 |
public IPath getSourceAttachmentRootPath() throws JavaModelException { |
672 |
public IPath getSourceAttachmentRootPath() throws JavaModelException { |
689 |
if (getKind() != K_BINARY) return null; |
673 |
if (getKind() != K_BINARY) return null; |
690 |
|
674 |
|
|
|
675 |
// 1) look source attachment property (set iff attachSource(...) was called |
691 |
String serverPathString= getSourceAttachmentProperty(); |
676 |
String serverPathString= getSourceAttachmentProperty(); |
692 |
if (serverPathString == null) { |
677 |
if (serverPathString != null) { |
693 |
return null; |
678 |
int index = serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
694 |
} |
679 |
if (index == -1) return null; |
695 |
int index = serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
680 |
String serverRootPathString= IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH; |
696 |
if (index == -1) return null; |
681 |
if (index != serverPathString.length() - 1) { |
697 |
String serverRootPathString= IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH; |
682 |
serverRootPathString= serverPathString.substring(index + 1); |
698 |
if (index != serverPathString.length() - 1) { |
683 |
} |
699 |
serverRootPathString= serverPathString.substring(index + 1); |
684 |
return new Path(serverRootPathString); |
700 |
} |
685 |
} |
701 |
return new Path(serverRootPathString); |
686 |
|
|
|
687 |
// 2) look at classpath entry |
688 |
IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(getPath()); |
689 |
IPath sourceAttachmentRootPath; |
690 |
if (entry != null && (sourceAttachmentRootPath = entry.getSourceAttachmentRootPath()) != null) |
691 |
return sourceAttachmentRootPath; |
692 |
|
693 |
// 3) look for a recomendation |
694 |
entry = findSourceAttachmentRecommendation(); |
695 |
if (entry != null && (sourceAttachmentRootPath = entry.getSourceAttachmentRootPath()) != null) |
696 |
return sourceAttachmentRootPath; |
697 |
|
698 |
return null; |
702 |
} |
699 |
} |
703 |
|
700 |
|
704 |
/** |
701 |
/** |
Lines 717-733
Link Here
|
717 |
mapper = createSourceMapper(getPath(), rootPath); // attach root to itself |
714 |
mapper = createSourceMapper(getPath(), rootPath); // attach root to itself |
718 |
else |
715 |
else |
719 |
mapper = createSourceMapper(sourcePath, rootPath); |
716 |
mapper = createSourceMapper(sourcePath, rootPath); |
720 |
if (rootPath == null && mapper.rootPath != null) { |
|
|
721 |
// as a side effect of calling the SourceMapper constructor, the root path was computed |
722 |
rootPath = new Path(mapper.rootPath); |
723 |
|
724 |
//set the property to the path of the mapped source |
725 |
if (sourcePath != null) |
726 |
setSourceAttachmentProperty( |
727 |
sourcePath.toString() |
728 |
+ ATTACHMENT_PROPERTY_DELIMITER |
729 |
+ rootPath.toString()); |
730 |
} |
731 |
rootInfo.setSourceMapper(mapper); |
717 |
rootInfo.setSourceMapper(mapper); |
732 |
} |
718 |
} |
733 |
} catch (JavaModelException e) { |
719 |
} catch (JavaModelException e) { |
Lines 780-791
Link Here
|
780 |
try { |
766 |
try { |
781 |
// check package fragment root on classpath of its project |
767 |
// check package fragment root on classpath of its project |
782 |
JavaProject project = (JavaProject) getJavaProject(); |
768 |
JavaProject project = (JavaProject) getJavaProject(); |
783 |
IClasspathEntry[] classpath = project.getResolvedClasspath(); |
769 |
IClasspathEntry entry = project.getClasspathEntryFor(path); |
784 |
for (int i = 0, length = classpath.length; i < length; i++) { |
770 |
if (entry != null) { |
785 |
IClasspathEntry entry = classpath[i]; |
771 |
return Status.OK_STATUS; |
786 |
if (entry.getPath().equals(path)) { |
|
|
787 |
return Status.OK_STATUS; |
788 |
} |
789 |
} |
772 |
} |
790 |
} catch(JavaModelException e){ |
773 |
} catch(JavaModelException e){ |
791 |
// could not read classpath, then assume it is outside |
774 |
// could not read classpath, then assume it is outside |