diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java
index f07010fc382..3102863ced6 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Nokia and others.
+ * Copyright (c) 2006, 2010 Nokia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,29 +8,17 @@
* Contributors:
* Nokia - Initial implementation (159833)
* Broadcom - http://bugs.eclipse.org/247853
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.debug.core.sourcelookup;
import java.io.File;
-import java.io.IOException;
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
-import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
-import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
-import org.eclipse.cdt.internal.core.resources.ResourceLookup;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.cdt.debug.internal.core.sourcelookup.SourceUtils;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
-import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
-import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
public class AbsolutePathSourceContainer extends AbstractSourceContainer {
/**
@@ -39,67 +27,6 @@ public class AbsolutePathSourceContainer extends AbstractSourceContainer {
*/
public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.absolutePath"; //$NON-NLS-1$
- private Object[] findSourceElementByFile(File file) {
- IFile[] wfiles = ResourceLookup.findFilesForLocation(new Path(file.getAbsolutePath()));
- if (wfiles.length > 0) {
- ResourceLookup.sortFilesByRelevance(wfiles, getProject());
- return wfiles;
- }
-
- try {
- // Check the canonical path as well to support case insensitive file
- // systems like Windows.
- wfiles = ResourceLookup.findFilesForLocation(new Path(file.getCanonicalPath()));
- if (wfiles.length > 0) {
- ResourceLookup.sortFilesByRelevance(wfiles, getProject());
- return wfiles;
- }
-
- // The file is not already in the workspace so try to create an external translation unit for it.
- ISourceLookupDirector director = getDirector();
- if (director != null) {
- ILaunchConfiguration launchConfiguration = director.getLaunchConfiguration();
- if (launchConfiguration != null) {
- String projectName = launchConfiguration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
- if (projectName.length() > 0) {
- ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName);
- if (project != null) {
- IPath path = Path.fromOSString(file.getCanonicalPath());
- String id = CoreModel.getRegistedContentTypeId(project.getProject(), path.lastSegment());
- return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, path, id) };
- }
- }
- }
- }
- } catch (IOException e) { // ignore if getCanonicalPath throws
- } catch (CoreException e) {
- }
-
- // If we can't create an ETU then fall back on LocalFileStorage.
- return new LocalFileStorage[] { new LocalFileStorage(file) };
- }
-
- /**
- * Find the project associated with the current launch configuration
- * @return IProject or null
- */
- private IProject getProject() {
- ISourceLookupDirector director = getDirector();
- if (director != null) {
- ILaunchConfiguration config = director.getLaunchConfiguration();
- if (config != null) {
- try {
- String name = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
- if (name.length() > 0)
- return ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- } catch (CoreException e) {
- // Don't care carry on search using other heuristics
- }
- }
- }
- return null;
- }
-
public boolean isValidAbsoluteFilePath(String name) {
return isValidAbsoluteFilePath(new File(name));
}
@@ -112,7 +39,7 @@ public class AbsolutePathSourceContainer extends AbstractSourceContainer {
if (name != null) {
File file = new File(name);
if (isValidAbsoluteFilePath(file)) {
- return findSourceElementByFile(file);
+ return SourceUtils.findSourceElements(file, getDirector());
}
}
return new Object[0];
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CompilationDirectorySourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CompilationDirectorySourceContainer.java
index dc5d71ac12f..cf14bcba272 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CompilationDirectorySourceContainer.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CompilationDirectorySourceContainer.java
@@ -12,6 +12,7 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
@@ -22,7 +23,6 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer;
-import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
/**
* A directory in the local file system that is used for running the C/C++ compiler. This container
@@ -33,7 +33,7 @@ import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
* the source container list.
*
* Source elements returned from findSourceElements(...)
are instances of
- * LocalFileStorage
.
+ * IFile
or LocalFileStorage
.
*
* Clients may instantiate this class. *
@@ -104,30 +104,30 @@ public class CompilationDirectorySourceContainer extends CompositeSourceContaine } /** - * Source elements returned from this method are instances ofLocalFileStorage
.
+ * Source elements returned from this method are instances of IFile
or LocalFileStorage
.
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(String)
*/
public Object[] findSourceElements(String name) throws CoreException {
- ArrayList