diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/MappingSourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/MappingSourceContainer.java index cf660686e83..4ab380c4112 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/MappingSourceContainer.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/MappingSourceContainer.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX Software Systems - Initial API and implementation + * QNX Software Systems - Initial API and implementation *******************************************************************************/ 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. */ public class MappingSourceContainer extends AbstractSourceContainer { - /** * Unique identifier for the mapping source container type * (value org.eclipse.cdt.debug.core.containerType.mapping). */ - 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 ArrayList fContainers; @@ -44,7 +43,7 @@ public class MappingSourceContainer extends AbstractSourceContainer { /** * Constructor for MappingSourceContainer. */ - public MappingSourceContainer( String name ) { + public MappingSourceContainer(String name) { fName = name; fContainers = new ArrayList(); } @@ -60,7 +59,7 @@ public class MappingSourceContainer extends AbstractSourceContainer { * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType() */ public ISourceContainerType getType() { - return getSourceContainerType( TYPE_ID ); + return getSourceContainerType(TYPE_ID); } /* (non-Javadoc) @@ -73,54 +72,49 @@ public class MappingSourceContainer extends AbstractSourceContainer { /* (non-Javadoc) * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String) */ - public Object[] findSourceElements( String name ) throws CoreException { - return findSourceElements( name, getSourceContainers() ); + public Object[] findSourceElements(String name) throws CoreException { + return findSourceElements(name, getSourceContainers()); } - protected Object[] findSourceElements( String name, ISourceContainer[] containers ) throws CoreException { + protected Object[] findSourceElements(String name, ISourceContainer[] containers) throws CoreException { List results = null; CoreException single = null; MultiStatus multiStatus = null; - if ( isFindDuplicates() ) { + if (isFindDuplicates()) { results = new ArrayList(); } - for( int i = 0; i < containers.length; i++ ) { + for (int i = 0; i < containers.length; i++) { ISourceContainer container = containers[i]; try { container.init(this.getDirector()); - Object[] objects = container.findSourceElements( name ); - if ( objects.length > 0 ) { - if ( isFindDuplicates() && results != null ) { - for( int j = 0; j < objects.length; j++ ) { - results.add( objects[j] ); + Object[] objects = container.findSourceElements(name); + if (objects.length > 0) { + if (isFindDuplicates() && results != null) { + for (int j = 0; j < objects.length; j++) { + results.add(objects[j]); } - } - else { - if ( objects.length == 1 ) { + } else { + if (objects.length == 1) { return objects; } return new Object[]{ objects[0] }; } } - } - catch( CoreException e ) { - if ( single == null ) { + } catch (CoreException e) { + if (single == null) { single = e; - } - 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.add( e.getStatus() ); - } - else { - multiStatus.add( e.getStatus() ); + } 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.add(e.getStatus()); + } else { + multiStatus.add(e.getStatus()); } } } - if ( results == null ) { - if ( multiStatus != null ) { - throw new CoreException( multiStatus ); - } - else if ( single != null ) { + if (results == null) { + if (multiStatus != null) { + throw new CoreException(multiStatus); + } else if (single != null) { throw single; } return EMPTY; @@ -132,29 +126,29 @@ public class MappingSourceContainer extends AbstractSourceContainer { * @see org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer#getSourceContainers() */ public ISourceContainer[] getSourceContainers() throws CoreException { - return fContainers.toArray( new MapEntrySourceContainer[fContainers.size()] ); + return fContainers.toArray(new MapEntrySourceContainer[fContainers.size()]); } - public void addMapEntry( MapEntrySourceContainer entry ) { - fContainers.add( entry ); + public void addMapEntry(MapEntrySourceContainer entry) { + fContainers.add(entry); } - public void addMapEntries( MapEntrySourceContainer[] entries ) { - fContainers.addAll( Arrays.asList( entries ) ); + public void addMapEntries(MapEntrySourceContainer[] entries) { + fContainers.addAll(Arrays.asList(entries)); } - public void removeMapEntry( MapEntrySourceContainer entry ) { - fContainers.remove( entry ); + public void removeMapEntry(MapEntrySourceContainer entry) { + fContainers.remove(entry); } - public void removeMapEntries( MapEntrySourceContainer[] entries ) { - fContainers.removeAll( Arrays.asList( entries ) ); + public void removeMapEntries(MapEntrySourceContainer[] entries) { + fContainers.removeAll(Arrays.asList(entries)); } public void clear() { Iterator it = fContainers.iterator(); - while( it.hasNext() ) { - ((ISourceContainer)it.next()).dispose(); + while (it.hasNext()) { + ((ISourceContainer) it.next()).dispose(); } fContainers.clear(); } @@ -165,40 +159,40 @@ public class MappingSourceContainer extends AbstractSourceContainer { public void dispose() { super.dispose(); Iterator it = fContainers.iterator(); - while( it.hasNext() ) { - ((ISourceContainer)it.next()).dispose(); + while (it.hasNext()) { + ((ISourceContainer) it.next()).dispose(); } fContainers.clear(); } public MappingSourceContainer copy() { - MappingSourceContainer copy = new MappingSourceContainer( fName ); + MappingSourceContainer copy = new MappingSourceContainer(fName); MapEntrySourceContainer[] entries = new MapEntrySourceContainer[fContainers.size()]; - for ( int i = 0; i < entries.length; ++i ) { - copy.addMapEntry( fContainers.get( i ).copy() ); + for (int i = 0; i < entries.length; ++i) { + copy.addMapEntry(fContainers.get(i).copy()); } return copy; } - public void setName( String name ) { + public void setName(String name) { fName = name; - } + } - public IPath getCompilationPath( String sourceName ) { - IPath path = new Path( sourceName ); + public IPath getCompilationPath(String sourceName) { + IPath path = new Path(sourceName); IPath result = null; try { ISourceContainer[] containers = getSourceContainers(); - for ( int i = 0; i < containers.length; ++i ) { - MapEntrySourceContainer entry = (MapEntrySourceContainer)containers[i]; + for (int i = 0; i < containers.length; ++i) { + MapEntrySourceContainer entry = (MapEntrySourceContainer) containers[i]; IPath local = entry.getLocalPath(); - if ( local.isPrefixOf( path ) ) { - result = entry.getBackendPath().append( path.removeFirstSegments( local.segmentCount() ) ); + if (local.isPrefixOf(path)) { + result = entry.getBackendPath().append(path.removeFirstSegments(local.segmentCount())); break; } } - } - catch( CoreException e ) { + } catch (CoreException e) { + CDebugCorePlugin.log(e); } return result; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java index cbdd01e0320..8b16d5ddc47 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java @@ -47,7 +47,7 @@ public class CSourcePathComputerDelegate implements ISourcePathComputerDelegate // First, get all the the containers in the global preferences (but add them last) ISourceContainer[] common = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().getSourceContainers(); - List containers = new ArrayList(common.length + 2); + List containers = new ArrayList(common.length + 3); // Add a container that fetches files that are specified with an absolute path containers.add(new AbsolutePathSourceContainer()); @@ -68,7 +68,7 @@ public class CSourcePathComputerDelegate implements ISourcePathComputerDelegate for (ISourceContainer sc : common) { // If the container is a path-mapper, use a copy (why?) if (sc.getType().getId().equals(MappingSourceContainer.TYPE_ID)) - sc = ((MappingSourceContainer)sc).copy(); + sc = ((MappingSourceContainer) sc).copy(); containers.add(sc); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java index 772534fad3e..39519e3b549 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX Software Systems - Initial API and implementation + * QNX Software Systems - Initial API and implementation *******************************************************************************/ 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. */ public class MapEntrySourceContainer extends AbstractSourceContainer { - /** * Unique identifier for the map entry source container type * (value org.eclipse.cdt.debug.core.containerType.mapEntry). */ - 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; @@ -58,7 +57,7 @@ public class MapEntrySourceContainer extends AbstractSourceContainer { /** * Constructor for MapEntrySourceContainer. */ - public MapEntrySourceContainer( IPath backend, IPath local ) { + public MapEntrySourceContainer(IPath backend, IPath local) { fBackendPath = backend; fLocalPath = local; } @@ -73,7 +72,8 @@ public class MapEntrySourceContainer extends AbstractSourceContainer { * @return converted string */ public static IPath createPath(String path) { - if (path == null) return null; + if (path == null) + return null; if (path.contains("\\")) { //$NON-NLS-1$ // handle Windows slashes and canonicalize 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); path = path.substring(idx + 1); return new Path(path).setDevice(device); - } - else { + } else { // Cygwin or UNC path if (path.startsWith("//")) { //$NON-NLS-1$ String network; @@ -112,51 +111,50 @@ public class MapEntrySourceContainer extends AbstractSourceContainer { /* (non-Javadoc) * @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); - if ( getBackendPath().isPrefixOf( path ) ) { - path = path.removeFirstSegments( getBackendPath().segmentCount() ); - path = getLocalPath().append( path ); + if (getBackendPath().isPrefixOf(path)) { + path = path.removeFirstSegments(getBackendPath().segmentCount()); + path = getLocalPath().append(path); - IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path ); - ArrayList list = new ArrayList(); - for( int j = 0; j < wsFiles.length; ++j ) { - if ( wsFiles[j].exists() ) { - list.add( wsFiles[j] ); - if ( !isFindDuplicates() ) + IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path); + ArrayList list = new ArrayList(); + for (int j = 0; j < wsFiles.length; ++j) { + if (wsFiles[j].exists()) { + list.add(wsFiles[j]); + if (!isFindDuplicates()) break; } } - if ( list.size() > 0 ) + if (list.size() > 0) return list.toArray(); File file = path.toFile(); // The file is not already in the workspace so try to create an external translation unit for it. ISourceLookupDirector director = getDirector(); - if (director != null && file.exists() && file.isFile() ) - { + if (director != null && file.exists() && file.isFile()) { ILaunchConfiguration launchConfiguration = director.getLaunchConfiguration(); - if (launchConfiguration != null) - { + 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) - { + if (project != null) { String id; try { final IPath location= Path.fromOSString(file.getCanonicalPath()); id = CoreModel.getRegistedContentTypeId(project.getProject(), location.lastSegment()); return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, location, id) }; - } catch (IOException e) { e.printStackTrace(); } + } catch (IOException e) { + CDebugCorePlugin.log(e); + } } } } } - if ( file.exists() && file.isFile() ) { - return new Object[] { new LocalFileStorage( file ) }; + if (file.exists() && file.isFile()) { + return new Object[] { new LocalFileStorage(file) }; } } return EMPTY; @@ -166,14 +164,14 @@ public class MapEntrySourceContainer extends AbstractSourceContainer { * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#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) * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType() */ public ISourceContainerType getType() { - return getSourceContainerType( TYPE_ID ); + return getSourceContainerType(TYPE_ID); } public IPath getLocalPath() { @@ -184,11 +182,11 @@ public class MapEntrySourceContainer extends AbstractSourceContainer { return fBackendPath; } - public void setLocalPath( IPath local ) { + public void setLocalPath(IPath local) { fLocalPath = local; } - public void setBackendPath( IPath backend ) { + public void setBackendPath(IPath backend) { fBackendPath = backend; } @@ -196,14 +194,14 @@ public class MapEntrySourceContainer extends AbstractSourceContainer { * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals( Object o ) { - if ( !(o instanceof MapEntrySourceContainer ) ) + public boolean equals(Object o) { + if (!(o instanceof MapEntrySourceContainer)) return false; 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() { - return new MapEntrySourceContainer( fBackendPath, fLocalPath ); + return new MapEntrySourceContainer(fBackendPath, fLocalPath); } }