mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 225805. Few more tweaks for CProjectSourceContainer and SourceFoldersRelativePathSourceContainer
This commit is contained in:
parent
686dacabdb
commit
47f70de67b
2 changed files with 56 additions and 68 deletions
|
@ -56,10 +56,10 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
*/
|
*/
|
||||||
public static final String TYPE_ID =
|
public static final String TYPE_ID =
|
||||||
CDebugCorePlugin.getUniqueIdentifier() + ".containerType.project"; //$NON-NLS-1$
|
CDebugCorePlugin.getUniqueIdentifier() + ".containerType.project"; //$NON-NLS-1$
|
||||||
|
private final IProject fOwnProject; // Project assigned to this container at construction time.
|
||||||
private IProject fProject;
|
private IProject fProject;
|
||||||
private boolean fSearchReferencedProjects;
|
private boolean fSearchReferencedProjects;
|
||||||
private URI fRootURI;
|
private URI fRootURI;
|
||||||
private boolean fInitializedRootURI;
|
|
||||||
private IFileStore fRootFile;
|
private IFileStore fRootFile;
|
||||||
private IWorkspaceRoot fRoot;
|
private IWorkspaceRoot fRoot;
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
* @param referenced whether referenced projects should be considered
|
* @param referenced whether referenced projects should be considered
|
||||||
*/
|
*/
|
||||||
public CProjectSourceContainer(IProject project, boolean referenced) {
|
public CProjectSourceContainer(IProject project, boolean referenced) {
|
||||||
|
fOwnProject = project;
|
||||||
fProject = project;
|
fProject = project;
|
||||||
fSearchReferencedProjects = referenced;
|
fSearchReferencedProjects = referenced;
|
||||||
}
|
}
|
||||||
|
@ -83,19 +84,28 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
return fProject;
|
return fProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns the project associated with this source container either directly or through
|
public void init(ISourceLookupDirector director) {
|
||||||
* the current launch configuration.
|
super.init(director);
|
||||||
* @return an IProject instance or {@code null}.
|
|
||||||
*/
|
|
||||||
private IProject getResolvedProject() {
|
|
||||||
if (fProject != null)
|
|
||||||
return fProject;
|
|
||||||
ISourceLookupDirector director = getDirector();
|
|
||||||
if (director != null) {
|
if (director != null) {
|
||||||
return SourceUtils.getLaunchConfigurationProject(director);
|
fProject = SourceUtils.getLaunchConfigurationProject(director);
|
||||||
|
if (fProject != null) {
|
||||||
|
fRootURI = fProject.getLocationURI();
|
||||||
|
if (fRootURI == null)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
fRootFile = EFS.getStore(fRootURI);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
}
|
||||||
|
fRoot = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
fProject = fOwnProject;
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -117,9 +127,6 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
sources.add(file);
|
sources.add(file);
|
||||||
} else {
|
} else {
|
||||||
if (!fInitializedRootURI) {
|
|
||||||
initializeRootURI();
|
|
||||||
}
|
|
||||||
// See bug 82627 - perform case insensitive source lookup
|
// See bug 82627 - perform case insensitive source lookup
|
||||||
if (fRootURI == null) {
|
if (fRootURI == null) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
|
@ -168,8 +175,7 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getName()
|
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getName()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
IProject project = getResolvedProject();
|
return fProject != null ? fProject.getName() : InternalSourceLookupMessages.CProjectSourceContainer_0;
|
||||||
return project != null ? project.getName() : InternalSourceLookupMessages.CProjectSourceContainer_0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -198,11 +204,10 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
* @see org.eclipse.debug.internal.core.sourcelookup.containers.CompositeSourceContainer#createSourceContainers()
|
* @see org.eclipse.debug.internal.core.sourcelookup.containers.CompositeSourceContainer#createSourceContainers()
|
||||||
*/
|
*/
|
||||||
protected ISourceContainer[] createSourceContainers() throws CoreException {
|
protected ISourceContainer[] createSourceContainers() throws CoreException {
|
||||||
IProject project = getResolvedProject();
|
if (fProject != null && fProject.isOpen()) {
|
||||||
if (project != null && project.isOpen()) {
|
|
||||||
if (isSearchReferencedProjects()) {
|
if (isSearchReferencedProjects()) {
|
||||||
IProject[] projects = SourceUtils.getAllReferencedProjects(project);
|
IProject[] projects = SourceUtils.getAllReferencedProjects(fProject);
|
||||||
ISourceContainer[] folders = createFolderSourceContainers(project);
|
ISourceContainer[] folders = createFolderSourceContainers(fProject);
|
||||||
List<ISourceContainer> containers = new ArrayList<ISourceContainer>(folders.length + projects.length);
|
List<ISourceContainer> containers = new ArrayList<ISourceContainer>(folders.length + projects.length);
|
||||||
for (ISourceContainer folder : folders) {
|
for (ISourceContainer folder : folders) {
|
||||||
containers.add(folder);
|
containers.add(folder);
|
||||||
|
@ -216,7 +221,7 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
}
|
}
|
||||||
return containers.toArray(new ISourceContainer[containers.size()]);
|
return containers.toArray(new ISourceContainer[containers.size()]);
|
||||||
}
|
}
|
||||||
return createFolderSourceContainers(project);
|
return createFolderSourceContainers(fProject);
|
||||||
}
|
}
|
||||||
return new ISourceContainer[0];
|
return new ISourceContainer[0];
|
||||||
}
|
}
|
||||||
|
@ -242,29 +247,13 @@ public class CProjectSourceContainer extends CompositeSourceContainer {
|
||||||
* @param name path name
|
* @param name path name
|
||||||
*/
|
*/
|
||||||
private boolean validateFile(String name) {
|
private boolean validateFile(String name) {
|
||||||
IProject project = getResolvedProject();
|
if (fProject == null) {
|
||||||
if (project == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IPath path = project.getFullPath().append(name);
|
IPath path = fProject.getFullPath().append(name);
|
||||||
return ResourcesPlugin.getWorkspace().validatePath(path.toOSString(), IResource.FILE).isOK();
|
return ResourcesPlugin.getWorkspace().validatePath(path.toOSString(), IResource.FILE).isOK();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeRootURI() {
|
|
||||||
fInitializedRootURI = true;
|
|
||||||
IProject project = getResolvedProject();
|
|
||||||
if (project == null)
|
|
||||||
return;
|
|
||||||
fRootURI = project.getLocationURI();
|
|
||||||
if (fRootURI == null)
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
fRootFile = EFS.getStore(fRootURI);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
}
|
|
||||||
fRoot = ResourcesPlugin.getWorkspace().getRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether referenced projects are considered.
|
* Returns whether referenced projects are considered.
|
||||||
*
|
*
|
||||||
|
|
|
@ -53,7 +53,8 @@ public class SourceFoldersRelativePathSourceContainer extends CompositeSourceCon
|
||||||
public static final String TYPE_ID =
|
public static final String TYPE_ID =
|
||||||
CDebugCorePlugin.getUniqueIdentifier() + ".containerType.sourceFoldersRelativePath"; //$NON-NLS-1$
|
CDebugCorePlugin.getUniqueIdentifier() + ".containerType.sourceFoldersRelativePath"; //$NON-NLS-1$
|
||||||
|
|
||||||
private final IProject fProject;
|
private final IProject fOwnProject; // Project assigned to this container at construction time.
|
||||||
|
private IProject fProject;
|
||||||
private boolean fSearchReferencedProjects;
|
private boolean fSearchReferencedProjects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,10 +65,26 @@ public class SourceFoldersRelativePathSourceContainer extends CompositeSourceCon
|
||||||
* @param referenced whether referenced projects should be considered
|
* @param referenced whether referenced projects should be considered
|
||||||
*/
|
*/
|
||||||
public SourceFoldersRelativePathSourceContainer(IProject project, boolean referenced) {
|
public SourceFoldersRelativePathSourceContainer(IProject project, boolean referenced) {
|
||||||
|
fOwnProject = project;
|
||||||
fProject = project;
|
fProject = project;
|
||||||
fSearchReferencedProjects = referenced;
|
fSearchReferencedProjects = referenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(ISourceLookupDirector director) {
|
||||||
|
super.init(director);
|
||||||
|
if (director != null) {
|
||||||
|
fProject = SourceUtils.getLaunchConfigurationProject(director);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
fProject = fOwnProject;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#isComposite()
|
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#isComposite()
|
||||||
*/
|
*/
|
||||||
|
@ -88,10 +105,9 @@ public class SourceFoldersRelativePathSourceContainer extends CompositeSourceCon
|
||||||
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getName()
|
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getName()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
IProject project = getResolvedProject();
|
return fProject == null ?
|
||||||
return project == null ?
|
|
||||||
InternalSourceLookupMessages.SourceFoldersRelativePathSourceContainer_0 :
|
InternalSourceLookupMessages.SourceFoldersRelativePathSourceContainer_0 :
|
||||||
NLS.bind(InternalSourceLookupMessages.SourceFoldersRelativePathSourceContainer_1, project.getName());
|
NLS.bind(InternalSourceLookupMessages.SourceFoldersRelativePathSourceContainer_1, fProject.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -123,10 +139,9 @@ public class SourceFoldersRelativePathSourceContainer extends CompositeSourceCon
|
||||||
* @see org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer#getCompilationPath(java.lang.String)
|
* @see org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer#getCompilationPath(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IPath getCompilationPath(String sourceName) {
|
public IPath getCompilationPath(String sourceName) {
|
||||||
IProject project = getResolvedProject();
|
if (fProject == null)
|
||||||
if (project == null)
|
|
||||||
return null;
|
return null;
|
||||||
ICProject cProject = CModelManager.getDefault().create(project);
|
ICProject cProject = CModelManager.getDefault().create(fProject);
|
||||||
IPath path = new Path(sourceName);
|
IPath path = new Path(sourceName);
|
||||||
for (IFile file : ResourceLookup.findFilesForLocation(path)) {
|
for (IFile file : ResourceLookup.findFilesForLocation(path)) {
|
||||||
ISourceRoot root = cProject.findSourceRoot(file);
|
ISourceRoot root = cProject.findSourceRoot(file);
|
||||||
|
@ -141,28 +156,12 @@ public class SourceFoldersRelativePathSourceContainer extends CompositeSourceCon
|
||||||
return fProject;
|
return fProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the project associated with this source container either directly or through
|
|
||||||
* the current launch configuration.
|
|
||||||
* @return an IProject instance or {@code null}.
|
|
||||||
*/
|
|
||||||
private IProject getResolvedProject() {
|
|
||||||
if (fProject != null)
|
|
||||||
return fProject;
|
|
||||||
ISourceLookupDirector director = getDirector();
|
|
||||||
if (director != null) {
|
|
||||||
return SourceUtils.getLaunchConfigurationProject(director);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ISourceContainer[] createSourceContainers() throws CoreException {
|
protected ISourceContainer[] createSourceContainers() throws CoreException {
|
||||||
IProject project = getResolvedProject();
|
if (fProject != null && fProject.isOpen()) {
|
||||||
if (project != null && project.isOpen()) {
|
|
||||||
if (isSearchReferencedProjects()) {
|
if (isSearchReferencedProjects()) {
|
||||||
IProject[] projects = SourceUtils.getAllReferencedProjects(project);
|
IProject[] projects = SourceUtils.getAllReferencedProjects(fProject);
|
||||||
ISourceContainer[] folders = createCompilationDirectoryContainers(project);
|
ISourceContainer[] folders = createCompilationDirectoryContainers(fProject);
|
||||||
List<ISourceContainer> containers = new ArrayList<ISourceContainer>(folders.length + projects.length);
|
List<ISourceContainer> containers = new ArrayList<ISourceContainer>(folders.length + projects.length);
|
||||||
for (ISourceContainer folder : folders) {
|
for (ISourceContainer folder : folders) {
|
||||||
containers.add(folder);
|
containers.add(folder);
|
||||||
|
@ -177,7 +176,7 @@ public class SourceFoldersRelativePathSourceContainer extends CompositeSourceCon
|
||||||
}
|
}
|
||||||
return containers.toArray(new ISourceContainer[containers.size()]);
|
return containers.toArray(new ISourceContainer[containers.size()]);
|
||||||
}
|
}
|
||||||
return createCompilationDirectoryContainers(project);
|
return createCompilationDirectoryContainers(fProject);
|
||||||
}
|
}
|
||||||
return new ISourceContainer[0];
|
return new ISourceContainer[0];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue