cdt/cdt_6_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/executables/StandardSourceFileRemapping.java
author wpaul
Fri, 07 Aug 2009 13:47:27 -0500
changeset 60 3982fab6369e
parent 37 c2bce6dd59e7
permissions -rw-r--r--
fixed executables view merge problems - bug #'s 9562, 9568, 9571.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 * Nokia - Initial API and implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    10
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    11
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
package org.eclipse.cdt.debug.internal.core.executables;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import org.eclipse.cdt.debug.core.executables.ISourceFileRemapping;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    16
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import org.eclipse.core.runtime.CoreException;
60
3982fab6369e fixed executables view merge problems - bug #'s 9562, 9568, 9571.
wpaul
parents: 37
diff changeset
    19
import org.eclipse.core.runtime.IPath;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import org.eclipse.debug.core.DebugPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
import org.eclipse.debug.core.ILaunch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import org.eclipse.debug.core.ILaunchManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
import org.eclipse.debug.core.model.ISourceLocator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
public class StandardSourceFileRemapping implements ISourceFileRemapping {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
60
3982fab6369e fixed executables view merge problems - bug #'s 9562, 9568, 9571.
wpaul
parents: 37
diff changeset
    28
	public String remapSourceFile(IPath executable, String filePath) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
			Object[] foundElements = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().findSourceElements(filePath);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    32
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    33
			if (foundElements.length == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
				Object foundElement = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
				ILaunchManager launchMgr = DebugPlugin.getDefault().getLaunchManager();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
				ILaunch[] launches = launchMgr.getLaunches();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
				for (ILaunch launch : launches) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
					ISourceLocator locator = launch.getSourceLocator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
					if (locator instanceof ICSourceLocator || locator instanceof CSourceLookupDirector) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    40
						if (locator instanceof ICSourceLocator)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    41
							foundElement = ((ICSourceLocator) locator).findSourceElement(filePath);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    42
						else
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
							foundElement = ((CSourceLookupDirector) locator).getSourceElement(filePath);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    44
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
				if (foundElement != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
					foundElements = new Object[] { foundElement };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    48
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
			if (foundElements.length == 1 && foundElements[0] instanceof LocalFileStorage) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
				LocalFileStorage newLocation = (LocalFileStorage) foundElements[0];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    52
				filePath = newLocation.getFullPath().toOSString();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    53
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    55
		} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    57
		return filePath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
}