1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 02:15:31 +02:00

Generic parameters and exception logging.

This commit is contained in:
Sergey Prigogin 2010-12-02 01:33:01 +00:00
parent e19da24804
commit caadfdc7d1
3 changed files with 88 additions and 96 deletions

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.core.sourcelookup; package org.eclipse.cdt.debug.core.sourcelookup;
@ -31,12 +31,11 @@ import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
* The source container for path mappings. * The source container for path mappings.
*/ */
public class MappingSourceContainer extends AbstractSourceContainer { public class MappingSourceContainer extends AbstractSourceContainer {
/** /**
* Unique identifier for the mapping source container type * Unique identifier for the mapping source container type
* (value <code>org.eclipse.cdt.debug.core.containerType.mapping</code>). * (value <code>org.eclipse.cdt.debug.core.containerType.mapping</code>).
*/ */
public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapping"; //$NON-NLS-1$ public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapping"; //$NON-NLS-1$
private String fName; private String fName;
private ArrayList<MapEntrySourceContainer> fContainers; private ArrayList<MapEntrySourceContainer> fContainers;
@ -44,7 +43,7 @@ public class MappingSourceContainer extends AbstractSourceContainer {
/** /**
* Constructor for MappingSourceContainer. * Constructor for MappingSourceContainer.
*/ */
public MappingSourceContainer( String name ) { public MappingSourceContainer(String name) {
fName = name; fName = name;
fContainers = new ArrayList<MapEntrySourceContainer>(); fContainers = new ArrayList<MapEntrySourceContainer>();
} }
@ -60,7 +59,7 @@ public class MappingSourceContainer extends AbstractSourceContainer {
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType() * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
*/ */
public ISourceContainerType getType() { public ISourceContainerType getType() {
return getSourceContainerType( TYPE_ID ); return getSourceContainerType(TYPE_ID);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -73,54 +72,49 @@ public class MappingSourceContainer extends AbstractSourceContainer {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String) * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
*/ */
public Object[] findSourceElements( String name ) throws CoreException { public Object[] findSourceElements(String name) throws CoreException {
return findSourceElements( name, getSourceContainers() ); return findSourceElements(name, getSourceContainers());
} }
protected Object[] findSourceElements( String name, ISourceContainer[] containers ) throws CoreException { protected Object[] findSourceElements(String name, ISourceContainer[] containers) throws CoreException {
List<Object> results = null; List<Object> results = null;
CoreException single = null; CoreException single = null;
MultiStatus multiStatus = null; MultiStatus multiStatus = null;
if ( isFindDuplicates() ) { if (isFindDuplicates()) {
results = new ArrayList<Object>(); results = new ArrayList<Object>();
} }
for( int i = 0; i < containers.length; i++ ) { for (int i = 0; i < containers.length; i++) {
ISourceContainer container = containers[i]; ISourceContainer container = containers[i];
try { try {
container.init(this.getDirector()); container.init(this.getDirector());
Object[] objects = container.findSourceElements( name ); Object[] objects = container.findSourceElements(name);
if ( objects.length > 0 ) { if (objects.length > 0) {
if ( isFindDuplicates() && results != null ) { if (isFindDuplicates() && results != null) {
for( int j = 0; j < objects.length; j++ ) { for (int j = 0; j < objects.length; j++) {
results.add( objects[j] ); results.add(objects[j]);
} }
} } else {
else { if (objects.length == 1) {
if ( objects.length == 1 ) {
return objects; return objects;
} }
return new Object[]{ objects[0] }; return new Object[]{ objects[0] };
} }
} }
} } catch (CoreException e) {
catch( CoreException e ) { if (single == null) {
if ( single == null ) {
single = e; single = e;
} } else if (multiStatus == null) {
else if ( multiStatus == null ) { multiStatus = new MultiStatus(DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{ single.getStatus() }, SourceLookupMessages.getString("MappingSourceContainer.0"), null); //$NON-NLS-1$
multiStatus = new MultiStatus( DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{ single.getStatus() }, SourceLookupMessages.getString( "MappingSourceContainer.0" ), null ); //$NON-NLS-1$ multiStatus.add(e.getStatus());
multiStatus.add( e.getStatus() ); } else {
} multiStatus.add(e.getStatus());
else {
multiStatus.add( e.getStatus() );
} }
} }
} }
if ( results == null ) { if (results == null) {
if ( multiStatus != null ) { if (multiStatus != null) {
throw new CoreException( multiStatus ); throw new CoreException(multiStatus);
} } else if (single != null) {
else if ( single != null ) {
throw single; throw single;
} }
return EMPTY; return EMPTY;
@ -132,29 +126,29 @@ public class MappingSourceContainer extends AbstractSourceContainer {
* @see org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer#getSourceContainers() * @see org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer#getSourceContainers()
*/ */
public ISourceContainer[] getSourceContainers() throws CoreException { public ISourceContainer[] getSourceContainers() throws CoreException {
return fContainers.toArray( new MapEntrySourceContainer[fContainers.size()] ); return fContainers.toArray(new MapEntrySourceContainer[fContainers.size()]);
} }
public void addMapEntry( MapEntrySourceContainer entry ) { public void addMapEntry(MapEntrySourceContainer entry) {
fContainers.add( entry ); fContainers.add(entry);
} }
public void addMapEntries( MapEntrySourceContainer[] entries ) { public void addMapEntries(MapEntrySourceContainer[] entries) {
fContainers.addAll( Arrays.asList( entries ) ); fContainers.addAll(Arrays.asList(entries));
} }
public void removeMapEntry( MapEntrySourceContainer entry ) { public void removeMapEntry(MapEntrySourceContainer entry) {
fContainers.remove( entry ); fContainers.remove(entry);
} }
public void removeMapEntries( MapEntrySourceContainer[] entries ) { public void removeMapEntries(MapEntrySourceContainer[] entries) {
fContainers.removeAll( Arrays.asList( entries ) ); fContainers.removeAll(Arrays.asList(entries));
} }
public void clear() { public void clear() {
Iterator<MapEntrySourceContainer> it = fContainers.iterator(); Iterator<MapEntrySourceContainer> it = fContainers.iterator();
while( it.hasNext() ) { while (it.hasNext()) {
((ISourceContainer)it.next()).dispose(); ((ISourceContainer) it.next()).dispose();
} }
fContainers.clear(); fContainers.clear();
} }
@ -165,40 +159,40 @@ public class MappingSourceContainer extends AbstractSourceContainer {
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
Iterator<MapEntrySourceContainer> it = fContainers.iterator(); Iterator<MapEntrySourceContainer> it = fContainers.iterator();
while( it.hasNext() ) { while (it.hasNext()) {
((ISourceContainer)it.next()).dispose(); ((ISourceContainer) it.next()).dispose();
} }
fContainers.clear(); fContainers.clear();
} }
public MappingSourceContainer copy() { public MappingSourceContainer copy() {
MappingSourceContainer copy = new MappingSourceContainer( fName ); MappingSourceContainer copy = new MappingSourceContainer(fName);
MapEntrySourceContainer[] entries = new MapEntrySourceContainer[fContainers.size()]; MapEntrySourceContainer[] entries = new MapEntrySourceContainer[fContainers.size()];
for ( int i = 0; i < entries.length; ++i ) { for (int i = 0; i < entries.length; ++i) {
copy.addMapEntry( fContainers.get( i ).copy() ); copy.addMapEntry(fContainers.get(i).copy());
} }
return copy; return copy;
} }
public void setName( String name ) { public void setName(String name) {
fName = name; fName = name;
} }
public IPath getCompilationPath( String sourceName ) { public IPath getCompilationPath(String sourceName) {
IPath path = new Path( sourceName ); IPath path = new Path(sourceName);
IPath result = null; IPath result = null;
try { try {
ISourceContainer[] containers = getSourceContainers(); ISourceContainer[] containers = getSourceContainers();
for ( int i = 0; i < containers.length; ++i ) { for (int i = 0; i < containers.length; ++i) {
MapEntrySourceContainer entry = (MapEntrySourceContainer)containers[i]; MapEntrySourceContainer entry = (MapEntrySourceContainer) containers[i];
IPath local = entry.getLocalPath(); IPath local = entry.getLocalPath();
if ( local.isPrefixOf( path ) ) { if (local.isPrefixOf(path)) {
result = entry.getBackendPath().append( path.removeFirstSegments( local.segmentCount() ) ); result = entry.getBackendPath().append(path.removeFirstSegments(local.segmentCount()));
break; break;
} }
} }
} } catch (CoreException e) {
catch( CoreException e ) { CDebugCorePlugin.log(e);
} }
return result; return result;
} }

View file

@ -47,7 +47,7 @@ public class CSourcePathComputerDelegate implements ISourcePathComputerDelegate
// First, get all the the containers in the global preferences (but add them last) // First, get all the the containers in the global preferences (but add them last)
ISourceContainer[] common = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().getSourceContainers(); ISourceContainer[] common = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().getSourceContainers();
List<ISourceContainer> containers = new ArrayList<ISourceContainer>(common.length + 2); List<ISourceContainer> containers = new ArrayList<ISourceContainer>(common.length + 3);
// Add a container that fetches files that are specified with an absolute path // Add a container that fetches files that are specified with an absolute path
containers.add(new AbsolutePathSourceContainer()); containers.add(new AbsolutePathSourceContainer());
@ -68,7 +68,7 @@ public class CSourcePathComputerDelegate implements ISourcePathComputerDelegate
for (ISourceContainer sc : common) { for (ISourceContainer sc : common) {
// If the container is a path-mapper, use a copy (why?) // If the container is a path-mapper, use a copy (why?)
if (sc.getType().getId().equals(MappingSourceContainer.TYPE_ID)) if (sc.getType().getId().equals(MappingSourceContainer.TYPE_ID))
sc = ((MappingSourceContainer)sc).copy(); sc = ((MappingSourceContainer) sc).copy();
containers.add(sc); containers.add(sc);
} }

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
@ -36,12 +36,11 @@ import com.ibm.icu.text.MessageFormat;
* The source container that maps a backend path to the local filesystem path. * The source container that maps a backend path to the local filesystem path.
*/ */
public class MapEntrySourceContainer extends AbstractSourceContainer { public class MapEntrySourceContainer extends AbstractSourceContainer {
/** /**
* Unique identifier for the map entry source container type * Unique identifier for the map entry source container type
* (value <code>org.eclipse.cdt.debug.core.containerType.mapEntry</code>). * (value <code>org.eclipse.cdt.debug.core.containerType.mapEntry</code>).
*/ */
public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapEntry"; //$NON-NLS-1$ public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapEntry"; //$NON-NLS-1$
private IPath fLocalPath; private IPath fLocalPath;
@ -58,7 +57,7 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
/** /**
* Constructor for MapEntrySourceContainer. * Constructor for MapEntrySourceContainer.
*/ */
public MapEntrySourceContainer( IPath backend, IPath local ) { public MapEntrySourceContainer(IPath backend, IPath local) {
fBackendPath = backend; fBackendPath = backend;
fLocalPath = local; fLocalPath = local;
} }
@ -73,7 +72,8 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
* @return converted string * @return converted string
*/ */
public static IPath createPath(String path) { public static IPath createPath(String path) {
if (path == null) return null; if (path == null)
return null;
if (path.contains("\\")) { //$NON-NLS-1$ if (path.contains("\\")) { //$NON-NLS-1$
// handle Windows slashes and canonicalize // handle Windows slashes and canonicalize
path = path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ path = path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
@ -88,8 +88,7 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
String device = path.substring(0, idx + 1); String device = path.substring(0, idx + 1);
path = path.substring(idx + 1); path = path.substring(idx + 1);
return new Path(path).setDevice(device); return new Path(path).setDevice(device);
} } else {
else {
// Cygwin or UNC path // Cygwin or UNC path
if (path.startsWith("//")) { //$NON-NLS-1$ if (path.startsWith("//")) { //$NON-NLS-1$
String network; String network;
@ -112,51 +111,50 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String) * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
*/ */
public Object[] findSourceElements( String name ) throws CoreException { public Object[] findSourceElements(String name) throws CoreException {
IPath path = createPath(name); IPath path = createPath(name);
if ( getBackendPath().isPrefixOf( path ) ) { if (getBackendPath().isPrefixOf(path)) {
path = path.removeFirstSegments( getBackendPath().segmentCount() ); path = path.removeFirstSegments(getBackendPath().segmentCount());
path = getLocalPath().append( path ); path = getLocalPath().append(path);
IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path ); IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
ArrayList list = new ArrayList(); ArrayList<IFile> list = new ArrayList<IFile>();
for( int j = 0; j < wsFiles.length; ++j ) { for (int j = 0; j < wsFiles.length; ++j) {
if ( wsFiles[j].exists() ) { if (wsFiles[j].exists()) {
list.add( wsFiles[j] ); list.add(wsFiles[j]);
if ( !isFindDuplicates() ) if (!isFindDuplicates())
break; break;
} }
} }
if ( list.size() > 0 ) if (list.size() > 0)
return list.toArray(); return list.toArray();
File file = path.toFile(); File file = path.toFile();
// The file is not already in the workspace so try to create an external translation unit for it. // The file is not already in the workspace so try to create an external translation unit for it.
ISourceLookupDirector director = getDirector(); ISourceLookupDirector director = getDirector();
if (director != null && file.exists() && file.isFile() ) if (director != null && file.exists() && file.isFile()) {
{
ILaunchConfiguration launchConfiguration = director.getLaunchConfiguration(); ILaunchConfiguration launchConfiguration = director.getLaunchConfiguration();
if (launchConfiguration != null) if (launchConfiguration != null) {
{
String projectName = launchConfiguration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ String projectName = launchConfiguration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
if (projectName.length() > 0) { if (projectName.length() > 0) {
ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName); ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName);
if (project != null) if (project != null) {
{
String id; String id;
try { try {
final IPath location= Path.fromOSString(file.getCanonicalPath()); final IPath location= Path.fromOSString(file.getCanonicalPath());
id = CoreModel.getRegistedContentTypeId(project.getProject(), location.lastSegment()); id = CoreModel.getRegistedContentTypeId(project.getProject(), location.lastSegment());
return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, location, id) }; return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, location, id) };
} catch (IOException e) { e.printStackTrace(); } } catch (IOException e) {
CDebugCorePlugin.log(e);
}
} }
} }
} }
} }
if ( file.exists() && file.isFile() ) { if (file.exists() && file.isFile()) {
return new Object[] { new LocalFileStorage( file ) }; return new Object[] { new LocalFileStorage(file) };
} }
} }
return EMPTY; return EMPTY;
@ -166,14 +164,14 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName() * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
*/ */
public String getName() { public String getName() {
return MessageFormat.format( "{0} - {1}", new String[] { getBackendPath().toOSString(), getLocalPath().toOSString() } ); //$NON-NLS-1$ return MessageFormat.format("{0} - {1}", new String[] { getBackendPath().toOSString(), getLocalPath().toOSString() }); //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType() * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
*/ */
public ISourceContainerType getType() { public ISourceContainerType getType() {
return getSourceContainerType( TYPE_ID ); return getSourceContainerType(TYPE_ID);
} }
public IPath getLocalPath() { public IPath getLocalPath() {
@ -184,11 +182,11 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
return fBackendPath; return fBackendPath;
} }
public void setLocalPath( IPath local ) { public void setLocalPath(IPath local) {
fLocalPath = local; fLocalPath = local;
} }
public void setBackendPath( IPath backend ) { public void setBackendPath(IPath backend) {
fBackendPath = backend; fBackendPath = backend;
} }
@ -196,14 +194,14 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
@Override @Override
public boolean equals( Object o ) { public boolean equals(Object o) {
if ( !(o instanceof MapEntrySourceContainer ) ) if (!(o instanceof MapEntrySourceContainer))
return false; return false;
MapEntrySourceContainer entry = (MapEntrySourceContainer)o; MapEntrySourceContainer entry = (MapEntrySourceContainer)o;
return ( entry.getBackendPath().equals( getBackendPath() ) && entry.getLocalPath().equals( getLocalPath() ) ); return (entry.getBackendPath().equals(getBackendPath()) && entry.getLocalPath().equals(getLocalPath()));
} }
public MapEntrySourceContainer copy() { public MapEntrySourceContainer copy() {
return new MapEntrySourceContainer( fBackendPath, fLocalPath ); return new MapEntrySourceContainer(fBackendPath, fLocalPath);
} }
} }