Lines 15-27
Link Here
|
15 |
import java.util.Map; |
15 |
import java.util.Map; |
16 |
|
16 |
|
17 |
import org.eclipse.core.resources.*; |
17 |
import org.eclipse.core.resources.*; |
18 |
import org.eclipse.core.resources.IContainer; |
|
|
19 |
import org.eclipse.core.resources.IFolder; |
20 |
import org.eclipse.core.resources.IResource; |
21 |
import org.eclipse.core.runtime.*; |
18 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.core.runtime.CoreException; |
|
|
23 |
import org.eclipse.core.runtime.IPath; |
24 |
import org.eclipse.core.runtime.IProgressMonitor; |
25 |
import org.eclipse.jdt.core.*; |
19 |
import org.eclipse.jdt.core.*; |
26 |
import org.eclipse.jdt.core.compiler.CharOperation; |
20 |
import org.eclipse.jdt.core.compiler.CharOperation; |
27 |
import org.eclipse.jdt.internal.core.util.MementoTokenizer; |
21 |
import org.eclipse.jdt.internal.core.util.MementoTokenizer; |
Lines 41-47
Link Here
|
41 |
/* |
35 |
/* |
42 |
* No source attachment property |
36 |
* No source attachment property |
43 |
*/ |
37 |
*/ |
44 |
protected final static String NO_SOURCE_ATTACHMENT = ""; //$NON-NLS-1$ |
38 |
public final static String NO_SOURCE_ATTACHMENT = ""; //$NON-NLS-1$ |
45 |
|
39 |
|
46 |
/** |
40 |
/** |
47 |
* The resource associated with this root. |
41 |
* The resource associated with this root. |
Lines 119-128
Link Here
|
119 |
setSourceMapper(mapper); |
113 |
setSourceMapper(mapper); |
120 |
} |
114 |
} |
121 |
if (sourcePath == null) { |
115 |
if (sourcePath == null) { |
122 |
setSourceAttachmentProperty(null); //remove the property |
116 |
Util.setSourceAttachmentProperty(getPath(), null); //remove the property |
123 |
} else { |
117 |
} else { |
124 |
//set the property to the path of the mapped source |
118 |
//set the property to the path of the mapped source |
125 |
setSourceAttachmentProperty( |
119 |
Util.setSourceAttachmentProperty( |
|
|
120 |
getPath(), |
126 |
sourcePath.toString() |
121 |
sourcePath.toString() |
127 |
+ (rootPath == null ? "" : (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()))); //$NON-NLS-1$ |
122 |
+ (rootPath == null ? "" : (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()))); //$NON-NLS-1$ |
128 |
} |
123 |
} |
Lines 144-150
Link Here
|
144 |
} |
139 |
} |
145 |
} |
140 |
} |
146 |
} catch (JavaModelException e) { |
141 |
} catch (JavaModelException e) { |
147 |
setSourceAttachmentProperty(null); // loose info - will be recomputed |
142 |
Util.setSourceAttachmentProperty(getPath(), null); // loose info - will be recomputed |
148 |
throw e; |
143 |
throw e; |
149 |
} finally { |
144 |
} finally { |
150 |
if (monitor != null) { |
145 |
if (monitor != null) { |
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 587-595
Link Here
|
587 |
IClasspathEntry rawEntry = null; |
579 |
IClasspathEntry rawEntry = null; |
588 |
JavaProject project = (JavaProject)this.getJavaProject(); |
580 |
JavaProject project = (JavaProject)this.getJavaProject(); |
589 |
project.getResolvedClasspath(); // force the reverse rawEntry cache to be populated |
581 |
project.getResolvedClasspath(); // force the reverse rawEntry cache to be populated |
590 |
Map resolvedPathToRawEntries = project.getPerProjectInfo().resolvedPathToRawEntries; |
582 |
Map rootPathToRawEntries = project.getPerProjectInfo().rootPathToRawEntries; |
591 |
if (resolvedPathToRawEntries != null) { |
583 |
if (rootPathToRawEntries != null) { |
592 |
rawEntry = (IClasspathEntry) resolvedPathToRawEntries.get(this.getPath()); |
584 |
rawEntry = (IClasspathEntry) rootPathToRawEntries.get(this.getPath()); |
593 |
} |
585 |
} |
594 |
return rawEntry; |
586 |
return rawEntry; |
595 |
} |
587 |
} |
Lines 607-675
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 |
|
610 |
String serverPathString= getSourceAttachmentProperty(); |
602 |
// 1) look source attachment property (set iff attachSource(...) was called |
611 |
if (serverPathString == null) { |
603 |
IPath path = getPath(); |
612 |
return null; |
604 |
String serverPathString= Util.getSourceAttachmentProperty(path); |
613 |
} |
605 |
if (serverPathString != null) { |
614 |
int index= serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
606 |
int index= serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
615 |
if (index < 0) { |
607 |
if (index < 0) { |
616 |
// no root path specified |
608 |
// no root path specified |
617 |
return new Path(serverPathString); |
609 |
return new Path(serverPathString); |
618 |
} else { |
610 |
} else { |
619 |
String serverSourcePathString= serverPathString.substring(0, index); |
611 |
String serverSourcePathString= serverPathString.substring(0, index); |
620 |
return new Path(serverSourcePathString); |
612 |
return new Path(serverSourcePathString); |
621 |
} |
|
|
622 |
} |
623 |
|
624 |
/** |
625 |
* Returns the server property for this package fragment root's |
626 |
* source attachement. |
627 |
*/ |
628 |
protected String getSourceAttachmentProperty() throws JavaModelException { |
629 |
String propertyString = null; |
630 |
QualifiedName qName= getSourceAttachmentPropertyName(); |
631 |
try { |
632 |
propertyString = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qName); |
633 |
|
634 |
// if no existing source attachment information, then lookup a recommendation from classpath entries |
635 |
if (propertyString == null) { |
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 |
} |
613 |
} |
653 |
return propertyString; |
|
|
654 |
} catch (CoreException ce) { |
655 |
throw new JavaModelException(ce); |
656 |
} |
614 |
} |
657 |
} |
|
|
658 |
|
659 |
/** |
660 |
* Returns the qualified name for the source attachment property |
661 |
* of this root. |
662 |
*/ |
663 |
protected QualifiedName getSourceAttachmentPropertyName() { |
664 |
return new QualifiedName(JavaCore.PLUGIN_ID, "sourceattachment: " + this.getPath().toOSString()); //$NON-NLS-1$ |
665 |
} |
666 |
|
615 |
|
667 |
public void setSourceAttachmentProperty(String property) { |
616 |
// 2) look at classpath entry |
668 |
try { |
617 |
IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(path); |
669 |
ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(this.getSourceAttachmentPropertyName(), property); |
618 |
IPath sourceAttachmentPath; |
670 |
} catch (CoreException ce) { |
619 |
if (entry != null && (sourceAttachmentPath = entry.getSourceAttachmentPath()) != null) |
671 |
// ignore |
620 |
return sourceAttachmentPath; |
|
|
621 |
|
622 |
// 3) look for a recommendation |
623 |
entry = findSourceAttachmentRecommendation(); |
624 |
if (entry != null && (sourceAttachmentPath = entry.getSourceAttachmentPath()) != null) { |
625 |
return sourceAttachmentPath; |
672 |
} |
626 |
} |
|
|
627 |
|
628 |
return null; |
673 |
} |
629 |
} |
674 |
|
630 |
|
675 |
/** |
631 |
/** |
Lines 688-704
Link Here
|
688 |
public IPath getSourceAttachmentRootPath() throws JavaModelException { |
644 |
public IPath getSourceAttachmentRootPath() throws JavaModelException { |
689 |
if (getKind() != K_BINARY) return null; |
645 |
if (getKind() != K_BINARY) return null; |
690 |
|
646 |
|
691 |
String serverPathString= getSourceAttachmentProperty(); |
647 |
// 1) look source attachment property (set iff attachSource(...) was called |
692 |
if (serverPathString == null) { |
648 |
IPath path = getPath(); |
693 |
return null; |
649 |
String serverPathString= Util.getSourceAttachmentProperty(path); |
694 |
} |
650 |
if (serverPathString != null) { |
695 |
int index = serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
651 |
int index = serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); |
696 |
if (index == -1) return null; |
652 |
if (index == -1) return null; |
697 |
String serverRootPathString= IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH; |
653 |
String serverRootPathString= IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH; |
698 |
if (index != serverPathString.length() - 1) { |
654 |
if (index != serverPathString.length() - 1) { |
699 |
serverRootPathString= serverPathString.substring(index + 1); |
655 |
serverRootPathString= serverPathString.substring(index + 1); |
700 |
} |
656 |
} |
701 |
return new Path(serverRootPathString); |
657 |
return new Path(serverRootPathString); |
|
|
658 |
} |
659 |
|
660 |
// 2) look at classpath entry |
661 |
IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(path); |
662 |
IPath sourceAttachmentRootPath; |
663 |
if (entry != null && (sourceAttachmentRootPath = entry.getSourceAttachmentRootPath()) != null) |
664 |
return sourceAttachmentRootPath; |
665 |
|
666 |
// 3) look for a recomendation |
667 |
entry = findSourceAttachmentRecommendation(); |
668 |
if (entry != null && (sourceAttachmentRootPath = entry.getSourceAttachmentRootPath()) != null) |
669 |
return sourceAttachmentRootPath; |
670 |
|
671 |
return null; |
702 |
} |
672 |
} |
703 |
|
673 |
|
704 |
/** |
674 |
/** |
Lines 717-733
Link Here
|
717 |
mapper = createSourceMapper(getPath(), rootPath); // attach root to itself |
687 |
mapper = createSourceMapper(getPath(), rootPath); // attach root to itself |
718 |
else |
688 |
else |
719 |
mapper = createSourceMapper(sourcePath, rootPath); |
689 |
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); |
690 |
rootInfo.setSourceMapper(mapper); |
732 |
} |
691 |
} |
733 |
} catch (JavaModelException e) { |
692 |
} catch (JavaModelException e) { |
Lines 780-791
Link Here
|
780 |
try { |
739 |
try { |
781 |
// check package fragment root on classpath of its project |
740 |
// check package fragment root on classpath of its project |
782 |
JavaProject project = (JavaProject) getJavaProject(); |
741 |
JavaProject project = (JavaProject) getJavaProject(); |
783 |
IClasspathEntry[] classpath = project.getResolvedClasspath(); |
742 |
IClasspathEntry entry = project.getClasspathEntryFor(path); |
784 |
for (int i = 0, length = classpath.length; i < length; i++) { |
743 |
if (entry != null) { |
785 |
IClasspathEntry entry = classpath[i]; |
744 |
return Status.OK_STATUS; |
786 |
if (entry.getPath().equals(path)) { |
|
|
787 |
return Status.OK_STATUS; |
788 |
} |
789 |
} |
745 |
} |
790 |
} catch(JavaModelException e){ |
746 |
} catch(JavaModelException e){ |
791 |
// could not read classpath, then assume it is outside |
747 |
// could not read classpath, then assume it is outside |