From bd51ec8825be1628e21b6f71a8eb0494341eb665 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 2 Dec 2010 20:45:54 +0000 Subject: [PATCH] NLS-style string resources. --- .../CDirectorySourceContainerType.java | 42 +- .../CDirectorySourceLocation.java | 467 +++++++---------- .../sourcelookup/CProjectSourceLocation.java | 170 ++---- .../core/sourcelookup/CSourceLocator.java | 494 ++++++++---------- .../sourcelookup/CSourceLookupDirector.java | 30 +- .../InternalSourceLookupMessages.java | 47 +- .../InternalSourceLookupMessages.properties | 47 +- .../MapEntrySourceContainerType.java | 10 +- .../MappingSourceContainerType.java | 67 ++- ...rogramRelativePathSourceContainerType.java | 13 +- .../core/sourcelookup/SourceUtils.java | 157 +++--- 11 files changed, 684 insertions(+), 860 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceContainerType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceContainerType.java index c6220305424..ca704a950e8 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceContainerType.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceContainerType.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; @@ -27,39 +27,39 @@ public class CDirectorySourceContainerType extends AbstractSourceContainerTypeDe /* (non-Javadoc) * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#createSourceContainer(java.lang.String) */ - public ISourceContainer createSourceContainer( String memento ) throws CoreException { - Node node = parseDocument( memento ); - if ( node.getNodeType() == Node.ELEMENT_NODE ) { - Element element = (Element)node; - if ( "directory".equals( element.getNodeName() ) ) { //$NON-NLS-1$ - String string = element.getAttribute( "path" ); //$NON-NLS-1$ - if ( string == null || string.length() == 0 ) { - abort( InternalSourceLookupMessages.getString( "CDirectorySourceContainerType.0" ), null ); //$NON-NLS-1$ + public ISourceContainer createSourceContainer(String memento) throws CoreException { + Node node = parseDocument(memento); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + if ("directory".equals(element.getNodeName())) { //$NON-NLS-1$ + String string = element.getAttribute("path"); //$NON-NLS-1$ + if (string == null || string.length() == 0) { + abort(InternalSourceLookupMessages.CDirectorySourceContainerType_0, null); } - String nest = element.getAttribute( "nest" ); //$NON-NLS-1$ - boolean nested = "true".equals( nest ); //$NON-NLS-1$ - return new DirectorySourceContainer( new Path( string ), nested ); + String nest = element.getAttribute("nest"); //$NON-NLS-1$ + boolean nested = "true".equals(nest); //$NON-NLS-1$ + return new DirectorySourceContainer(new Path(string), nested); } - abort( InternalSourceLookupMessages.getString( "CDirectorySourceContainerType.1" ), null ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.CDirectorySourceContainerType_1, null); } - abort( InternalSourceLookupMessages.getString( "CDirectorySourceContainerType.2" ), null ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.CDirectorySourceContainerType_2, null); return null; } /* (non-Javadoc) * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#getMemento(org.eclipse.debug.internal.core.sourcelookup.ISourceContainer) */ - public String getMemento( ISourceContainer container ) throws CoreException { + public String getMemento(ISourceContainer container) throws CoreException { DirectorySourceContainer folder = (DirectorySourceContainer)container; Document document = newDocument(); - Element element = document.createElement( "directory" ); //$NON-NLS-1$ - element.setAttribute( "path", folder.getDirectory().getAbsolutePath() ); //$NON-NLS-1$ + Element element = document.createElement("directory"); //$NON-NLS-1$ + element.setAttribute("path", folder.getDirectory().getAbsolutePath()); //$NON-NLS-1$ String nest = "false"; //$NON-NLS-1$ - if ( folder.isComposite() ) { + if (folder.isComposite()) { nest = "true"; //$NON-NLS-1$ } - element.setAttribute( "nest", nest ); //$NON-NLS-1$ - document.appendChild( element ); - return serializeDocument( document ); + element.setAttribute("nest", nest); //$NON-NLS-1$ + document.appendChild(element); + return serializeDocument(document); } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java index ce3ee1db0b6..a9bae3e18c1 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java @@ -14,7 +14,6 @@ import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.io.StringReader; -import com.ibm.icu.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; @@ -38,6 +37,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.util.NLS; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; @@ -50,8 +50,7 @@ import org.xml.sax.SAXException; * * @since Sep 23, 2002 */ -public class CDirectorySourceLocation implements IDirectorySourceLocation -{ +public class CDirectorySourceLocation implements IDirectorySourceLocation { private static final String ELEMENT_NAME = "cDirectorySourceLocation"; //$NON-NLS-1$ private static final String ATTR_DIRECTORY = "directory"; //$NON-NLS-1$ private static final String ATTR_ASSOCIATION = "association"; //$NON-NLS-1$ @@ -61,55 +60,46 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation * The root directory of this source location */ private IPath fDirectory; - /** - * The associted path of this source location. + * The associated path of this source location. */ - private IPath fAssociation = null; - - private boolean fSearchForDuplicateFiles = false; - - private boolean fSearchSubfolders = false; - - private File[] fFolders = null; + private IPath fAssociation; + private boolean fSearchForDuplicateFiles; + private boolean fSearchSubfolders; + private File[] fFolders; /** * Constructor for CDirectorySourceLocation. */ - public CDirectorySourceLocation() - { + public CDirectorySourceLocation() { } /** * Constructor for CDirectorySourceLocation. */ - public CDirectorySourceLocation( IPath directory, IPath association, boolean searchSubfolders ) - { - setDirectory( directory ); - setAssociation( association ); - setSearchSubfolders( searchSubfolders ); + public CDirectorySourceLocation(IPath directory, IPath association, boolean searchSubfolders) { + setDirectory(directory); + setAssociation(association); + setSearchSubfolders(searchSubfolders); } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#findSourceElement(String) */ - public Object findSourceElement( String name ) throws CoreException - { + public Object findSourceElement(String name) throws CoreException { Object result = null; - if ( !isEmpty( name ) && getDirectory() != null ) - { - File file = new File( name ); - if ( file.isAbsolute() ) - result = findFileByAbsolutePath( name ); - else - result = findFileByRelativePath( name ); - if ( result == null && getAssociation() != null ) - { - IPath path = new Path( name ); - if ( path.segmentCount() > 1 && getAssociation().isPrefixOf( path ) ) - { - path = getDirectory().append( path.removeFirstSegments( getAssociation().segmentCount() ) ); - result = findFileByAbsolutePath( path.toOSString() ); + if (!isEmpty(name) && getDirectory() != null) { + File file = new File(name); + if (file.isAbsolute()) { + result = findFileByAbsolutePath(name); + } else { + result = findFileByRelativePath(name); + } + if (result == null && getAssociation() != null) { + IPath path = new Path(name); + if (path.segmentCount() > 1 && getAssociation().isPrefixOf(path)) { + path = getDirectory().append(path.removeFirstSegments(getAssociation().segmentCount())); + result = findFileByAbsolutePath(path.toOSString()); } } } @@ -119,13 +109,12 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation /* (non-Javadoc) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) */ - public Object getAdapter( Class adapter ) - { - if ( adapter.equals( ICSourceLocation.class ) ) + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + if (adapter.equals(ICSourceLocation.class)) return this; - if ( adapter.equals( CDirectorySourceLocation.class ) ) + if (adapter.equals(CDirectorySourceLocation.class)) return this; - if ( adapter.equals( IPath.class ) ) + if (adapter.equals(IPath.class)) return getDirectory(); return null; } @@ -135,8 +124,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation * * @param directory a directory */ - private void setDirectory( IPath directory ) - { + private void setDirectory(IPath directory) { fDirectory = directory; } @@ -145,186 +133,162 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation * * @return directory */ - public IPath getDirectory() - { + public IPath getDirectory() { return fDirectory; } - public void getDirectory( IPath path ) - { + public void getDirectory(IPath path) { fDirectory = path; } - public void setAssociation( IPath association ) - { + public void setAssociation(IPath association) { fAssociation = association; } - public IPath getAssociation() - { + public IPath getAssociation() { return fAssociation; } - private Object findFileByAbsolutePath( String name ) - { - File file = new File( name ); - if ( !file.isAbsolute() ) + @SuppressWarnings("unchecked") + private Object findFileByAbsolutePath(String name) { + File file = new File(name); + if (!file.isAbsolute()) return null; File[] folders = getFolders(); - if ( folders != null ) - { - LinkedList list = new LinkedList(); - for ( int i = 0; i < folders.length; ++i ) - { - Object result = findFileByAbsolutePath( folders[i], name ); - if ( result instanceof List ) - { - if ( searchForDuplicateFiles() ) - list.addAll( (List)result ); - else + if (folders != null) { + LinkedList list = new LinkedList(); + for (int i = 0; i < folders.length; ++i) { + Object result = findFileByAbsolutePath(folders[i], name); + if (result instanceof List) { + if (searchForDuplicateFiles()) { + list.addAll((List) result); + } else { return list.getFirst(); - } - else if ( result != null ) - { - if ( searchForDuplicateFiles() ) - list.add( result ); - else + } + } else if (result != null) { + if (searchForDuplicateFiles()) { + list.add(result); + } else { return result; + } } } - if ( list.size() > 0 ) - return ( list.size() == 1 ) ? list.getFirst() : list; + if (list.size() > 0) + return (list.size() == 1) ? list.getFirst() : list; } return null; } - private Object findFileByAbsolutePath( File folder, String name ) - { - File file = new File( name ); - if ( !file.isAbsolute() ) + private Object findFileByAbsolutePath(File folder, String name) { + File file = new File(name); + if (!file.isAbsolute()) return null; - IPath filePath = new Path( name ); - IPath path = new Path( folder.getAbsolutePath() ); + IPath filePath = new Path(name); + IPath path = new Path(folder.getAbsolutePath()); IPath association = getAssociation(); - if ( !isPrefix( path, filePath ) || path.segmentCount() + 1 != filePath.segmentCount() ) - { - if ( association != null && isPrefix( association, filePath ) && association.segmentCount() + 1 == filePath.segmentCount() ) - filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) ); - else + if (!isPrefix(path, filePath) || path.segmentCount() + 1 != filePath.segmentCount()) { + if (association != null && + isPrefix(association, filePath) && association.segmentCount() + 1 == filePath.segmentCount()) { + filePath = path.append(filePath.removeFirstSegments(association.segmentCount())); + } else { return null; + } } // Try for a file in another workspace project - IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( filePath ); - LinkedList list = new LinkedList(); - for ( int j = 0; j < wsFiles.length; ++j ) - if ( wsFiles[j].exists() ) - { - if ( !searchForDuplicateFiles() ) + IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath); + LinkedList list = new LinkedList(); + for (int j = 0; j < wsFiles.length; ++j) + if (wsFiles[j].exists()) { + if (!searchForDuplicateFiles()) return wsFiles[j]; - list.add( wsFiles[j] ); + list.add(wsFiles[j]); } - if ( list.size() > 0 ) - return ( list.size() == 1 ) ? list.getFirst() : list; + if (list.size() > 0) + return (list.size() == 1) ? list.getFirst() : list; file = filePath.toFile(); - if ( file.exists() && file.isFile() ) - { - return createExternalFileStorage( filePath ); + if (file.exists() && file.isFile()) { + return createExternalFileStorage(filePath); } return null; } - private Object findFileByRelativePath( String fileName ) - { + @SuppressWarnings("unchecked") + private Object findFileByRelativePath(String fileName) { File[] folders = getFolders(); - if ( folders != null ) - { - LinkedList list = new LinkedList(); - for ( int i = 0; i < folders.length; ++i ) - { - Object result = findFileByRelativePath( folders[i], fileName ); - if ( result instanceof List ) - { - if ( searchForDuplicateFiles() ) - list.addAll( (List)result ); - else + if (folders != null) { + LinkedList list = new LinkedList(); + for (int i = 0; i < folders.length; ++i) { + Object result = findFileByRelativePath(folders[i], fileName); + if (result instanceof List) { + if (searchForDuplicateFiles()) { + list.addAll((List) result); + } else { return list.getFirst(); - } - else if ( result != null ) - { - if ( searchForDuplicateFiles() ) - list.add( result ); - else + } + } else if (result != null) { + if (searchForDuplicateFiles()) { + list.add(result); + } else { return result; + } } } - if ( list.size() > 0 ) - return ( list.size() == 1 ) ? list.getFirst() : list; + if (list.size() > 0) + return (list.size() == 1) ? list.getFirst() : list; } return null; } - private Object findFileByRelativePath( File folder, String fileName ) - { - IPath path = new Path( folder.getAbsolutePath() ); - path = path.append( fileName ); + private Object findFileByRelativePath(File folder, String fileName) { + IPath path = new Path(folder.getAbsolutePath()); + path = path.append(fileName); File file = path.toFile(); - if ( file.exists() && file.isFile() ) - { - path = new Path( file.getAbsolutePath() ); - IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path ); - LinkedList list = new LinkedList(); - for ( int j = 0; j < wsFiles.length; ++j ) - if ( wsFiles[j].exists() ) - { - if ( !searchForDuplicateFiles() ) + if (file.exists() && file.isFile()) { + path = new Path(file.getAbsolutePath()); + IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path); + LinkedList list = new LinkedList(); + for (int j = 0; j < wsFiles.length; ++j) + if (wsFiles[j].exists()) { + if (!searchForDuplicateFiles()) return wsFiles[j]; - list.add( wsFiles[j] ); + list.add(wsFiles[j]); } - if ( list.size() > 0 ) - return ( list.size() == 1 ) ? list.getFirst() : list; - return createExternalFileStorage( path ); + if (list.size() > 0) + return (list.size() == 1) ? list.getFirst() : list; + return createExternalFileStorage(path); } return null; } - private IStorage createExternalFileStorage( IPath path ) - { - return new FileStorage( path ); + private IStorage createExternalFileStorage(IPath path) { + return new FileStorage(path); } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getMemento() */ - public String getMemento() throws CoreException - { + public String getMemento() throws CoreException { Document document = null; Throwable ex = null; - try - { + try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - Element node = document.createElement( ELEMENT_NAME ); - document.appendChild( node ); - node.setAttribute( ATTR_DIRECTORY, getDirectory().toOSString() ); - if ( getAssociation() != null ) - node.setAttribute( ATTR_ASSOCIATION, getAssociation().toOSString() ); - node.setAttribute( ATTR_SEARCH_SUBFOLDERS, Boolean.valueOf( searchSubfolders() ).toString() ); - return CDebugUtils.serializeDocument( document ); - } - catch( ParserConfigurationException e ) - { + Element node = document.createElement(ELEMENT_NAME); + document.appendChild(node); + node.setAttribute(ATTR_DIRECTORY, getDirectory().toOSString()); + if (getAssociation() != null) + node.setAttribute(ATTR_ASSOCIATION, getAssociation().toOSString()); + node.setAttribute(ATTR_SEARCH_SUBFOLDERS, Boolean.valueOf(searchSubfolders()).toString()); + return CDebugUtils.serializeDocument(document); + } catch (ParserConfigurationException e) { ex = e; - } - catch( IOException e ) - { + } catch (IOException e) { + ex = e; + } catch (TransformerException e) { ex = e; } - catch( TransformerException e ) - { - ex = e; - } - abort( MessageFormat.format( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.0" ), new String[] { getDirectory().toOSString() } ), ex ); //$NON-NLS-1$ + abort(NLS.bind(InternalSourceLookupMessages.CDirectorySourceLocation_0, getDirectory().toOSString()), ex); // execution will not reach here return null; } @@ -332,204 +296,165 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#initializeFrom(java.lang.String) */ - public void initializeFrom( String memento ) throws CoreException - { + public void initializeFrom(String memento) throws CoreException { Exception ex = null; - try - { + try { Element root = null; DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - StringReader reader = new StringReader( memento ); - InputSource source = new InputSource( reader ); - root = parser.parse( source ).getDocumentElement(); + StringReader reader = new StringReader(memento); + InputSource source = new InputSource(reader); + root = parser.parse(source).getDocumentElement(); - String dir = root.getAttribute( ATTR_DIRECTORY ); - if ( isEmpty( dir ) ) - { - abort( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.1" ), null ); //$NON-NLS-1$ - } - else - { - IPath path = new Path( dir ); - if ( path.isValidPath( dir ) && path.toFile().isDirectory() && path.toFile().exists() ) - { - setDirectory( path ); - } - else - { - abort( MessageFormat.format( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.2" ), new String[] { dir } ), null ); //$NON-NLS-1$ + String dir = root.getAttribute(ATTR_DIRECTORY); + if (isEmpty(dir)) { + abort(InternalSourceLookupMessages.CDirectorySourceLocation_1, null); + } else { + IPath path = new Path(dir); + if (path.isValidPath(dir) && path.toFile().isDirectory() && path.toFile().exists()) { + setDirectory(path); + } else { + abort(NLS.bind(InternalSourceLookupMessages.CDirectorySourceLocation_2, dir), null); } } - dir = root.getAttribute( ATTR_ASSOCIATION ); - if ( isEmpty( dir ) ) - { - setAssociation( null ); - } - else - { - IPath path = new Path( dir ); - if ( path.isValidPath( dir ) ) - { - setAssociation( path ); - } - else - { - setAssociation( null ); + dir = root.getAttribute(ATTR_ASSOCIATION); + if (isEmpty(dir)) { + setAssociation(null); + } else { + IPath path = new Path(dir); + if (path.isValidPath(dir)) { + setAssociation(path); + } else { + setAssociation(null); } } - setSearchSubfolders( Boolean.valueOf( root.getAttribute( ATTR_SEARCH_SUBFOLDERS ) ).booleanValue() ); + setSearchSubfolders(Boolean.valueOf(root.getAttribute(ATTR_SEARCH_SUBFOLDERS)).booleanValue()); return; - } - catch( ParserConfigurationException e ) - { + } catch (ParserConfigurationException e) { + ex = e; + } catch (SAXException e) { + ex = e; + } catch (IOException e) { ex = e; } - catch( SAXException e ) - { - ex = e; - } - catch( IOException e ) - { - ex = e; - } - abort( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.3" ), ex ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.CDirectorySourceLocation_3, ex); } /** * Throws an internal error exception */ - private void abort( String message, Throwable e ) throws CoreException - { - IStatus s = new Status( IStatus.ERROR, + private void abort(String message, Throwable e) throws CoreException { + IStatus s = new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, - e ); - throw new CoreException( s ); + e); + throw new CoreException(s); } - private boolean isEmpty( String string ) - { + private boolean isEmpty(String string) { return string == null || string.length() == 0; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ - public boolean equals( Object obj ) - { - if ( obj instanceof IDirectorySourceLocation ) - { + public boolean equals(Object obj) { + if (obj instanceof IDirectorySourceLocation) { IPath dir = ((IDirectorySourceLocation)obj).getDirectory(); IPath association = ((IDirectorySourceLocation)obj).getAssociation(); - if ( dir == null ) + if (dir == null) return false; - boolean result = dir.equals( getDirectory() ); - if ( result ) - { - if ( association == null && getAssociation() == null ) + boolean result = dir.equals(getDirectory()); + if (result) { + if (association == null && getAssociation() == null) return true; - if ( association != null ) - return association.equals( getAssociation() ); + if (association != null) + return association.equals(getAssociation()); } } return false; } - private boolean isPrefix( IPath prefix, IPath path ) - { + private boolean isPrefix(IPath prefix, IPath path) { int segCount = prefix.segmentCount(); - if ( segCount >= path.segmentCount() ) + if (segCount >= path.segmentCount()) return false; String prefixString = prefix.toOSString(); - String pathString = path.removeLastSegments( path.segmentCount() - segCount ).toOSString(); - return prefixString.equalsIgnoreCase( pathString ); + String pathString = path.removeLastSegments(path.segmentCount() - segCount).toOSString(); + return prefixString.equalsIgnoreCase(pathString); } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean) */ - public void setSearchForDuplicateFiles( boolean search ) - { + public void setSearchForDuplicateFiles(boolean search) { fSearchForDuplicateFiles = search; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles() */ - public boolean searchForDuplicateFiles() - { + public boolean searchForDuplicateFiles() { return fSearchForDuplicateFiles; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation#searchSubfolders() */ - public boolean searchSubfolders() - { + public boolean searchSubfolders() { return fSearchSubfolders; } - public void setSearchSubfolders( boolean search ) - { + public void setSearchSubfolders(boolean search) { resetFolders(); fSearchSubfolders = search; } - protected File[] getFolders() - { - if ( fFolders == null ) + protected File[] getFolders() { + if (fFolders == null) initializeFolders(); return fFolders; } - protected void resetFolders() - { + protected void resetFolders() { fFolders = null; } - private void initializeFolders() - { - if ( getDirectory() != null ) - { - ArrayList list = new ArrayList(); + private void initializeFolders() { + if (getDirectory() != null) { + ArrayList list = new ArrayList(); File root = getDirectory().toFile(); - list.add( root ); - if ( searchSubfolders() ) - list.addAll( getFileFolders( root ) ); - fFolders = (File[])list.toArray( new File[list.size()] ); + list.add(root); + if (searchSubfolders()) + list.addAll(getFileFolders(root)); + fFolders = list.toArray(new File[list.size()]); } } - private List getFileFolders( File file ) - { - ArrayList list = new ArrayList(); - File[] folders = file.listFiles( - new FileFilter() - { - public boolean accept( File pathname ) - { + private List getFileFolders(File file) { + ArrayList list = new ArrayList(); + File[] folders = file.listFiles( + new FileFilter() { + public boolean accept(File pathname) { return pathname.isDirectory(); } - } ); - list.addAll( Arrays.asList( folders ) ); - for ( int i = 0; i < folders.length; ++i ) - list.addAll( getFileFolders( folders[i] ) ); + }); + list.addAll(Arrays.asList(folders)); + for (int i = 0; i < folders.length; ++i) + list.addAll(getFileFolders(folders[i])); return list; } /* (non-Javadoc) * @see java.lang.Object#toString() */ - public String toString() - { - return ( getDirectory() != null ) ? getDirectory().toOSString() : ""; //$NON-NLS-1$ + public String toString() { + return (getDirectory() != null) ? getDirectory().toOSString() : ""; //$NON-NLS-1$ } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#dispose() */ - public void dispose() - { + public void dispose() { } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java index 0ba9e86ba1c..0b33d398a2a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java @@ -49,8 +49,7 @@ import org.xml.sax.SAXException; * * @since Sep 23, 2002 */ -public class CProjectSourceLocation implements IProjectSourceLocation -{ +public class CProjectSourceLocation implements IProjectSourceLocation { private static final String ELEMENT_NAME = "cProjectSourceLocation"; //$NON-NLS-1$ private static final String ATTR_PROJECT = "project"; //$NON-NLS-1$ private static final String ATTR_GENERIC = "generic"; //$NON-NLS-1$ @@ -59,38 +58,21 @@ public class CProjectSourceLocation implements IProjectSourceLocation * The project associated with this source location */ private IProject fProject; - private IResource[] fFolders; - private HashMap fCache = new HashMap( 20 ); - private HashSet fNotFoundCache = new HashSet( 20 ); - private boolean fGenerated = true; - private boolean fSearchForDuplicateFiles = false; - /** - * Constructor for CProjectSourceLocation. - */ - public CProjectSourceLocation() - { + public CProjectSourceLocation() { } - /** - * Constructor for CProjectSourceLocation. - */ - public CProjectSourceLocation( IProject project ) - { + public CProjectSourceLocation( IProject project ) { setProject( project ); fGenerated = true; } - /** - * Constructor for CProjectSourceLocation. - */ - public CProjectSourceLocation( IProject project, boolean generated ) - { + public CProjectSourceLocation( IProject project, boolean generated ) { setProject( project ); fGenerated = generated; } @@ -101,19 +83,15 @@ public class CProjectSourceLocation implements IProjectSourceLocation public Object findSourceElement( String name ) throws CoreException { Object result = null; - if ( !isEmpty( name ) && getProject() != null && !notFoundCacheLookup( name ) ) - { + if ( !isEmpty( name ) && getProject() != null && !notFoundCacheLookup( name ) ) { result = cacheLookup( name ); - if ( result == null ) - { + if ( result == null ) { result = doFindSourceElement( name ); - if ( result != null ) - { + if ( result != null ) { cacheSourceElement( name, result ); } } - if ( result == null ) - { + if ( result == null ) { cacheNotFound( name ); } } @@ -123,8 +101,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation /* (non-Javadoc) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) */ - public Object getAdapter( Class adapter ) - { + public Object getAdapter( Class adapter ) { if ( adapter.equals( ICSourceLocation.class ) ) return this; if ( adapter.equals( CProjectSourceLocation.class ) ) @@ -139,8 +116,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation * * @param project the project */ - private void setProject( IProject project ) - { + private void setProject( IProject project ) { fProject = project; } @@ -149,27 +125,22 @@ public class CProjectSourceLocation implements IProjectSourceLocation * * @return project */ - public IProject getProject() - { + public IProject getProject() { return fProject; } - private Object doFindSourceElement( String name ) - { + private Object doFindSourceElement( String name ) { File file = new File( name ); return ( file.isAbsolute() ) ? findFileByAbsolutePath( file ) : findFileByRelativePath( name ); } - private Object findFileByAbsolutePath( File file ) - { + private Object findFileByAbsolutePath( File file ) { LinkedList list = new LinkedList(); - if ( file.exists() ) - { + if ( file.exists() ) { IPath path = new Path( file.getAbsolutePath() ); IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path ); for ( int i = 0; i < wsFiles.length; ++i ) - if ( wsFiles[i].getProject().equals( getProject() ) && wsFiles[i].exists() ) - { + if ( wsFiles[i].getProject().equals( getProject() ) && wsFiles[i].exists() ) { if ( !searchForDuplicateFiles() ) return wsFiles[i]; list.add( wsFiles[i] ); @@ -178,24 +149,20 @@ public class CProjectSourceLocation implements IProjectSourceLocation return ( list.size() > 0 ) ? ( ( list.size() == 1 ) ? list.getFirst() : list ) : null; } - private Object findFileByRelativePath( String fileName ) - { + private Object findFileByRelativePath( String fileName ) { IResource[] folders = getFolders(); LinkedList list = new LinkedList(); - for ( int i = 0; i < folders.length; ++i ) - { + for ( int i = 0; i < folders.length; ++i ) { if ( list.size() > 0 && !searchForDuplicateFiles() ) break; IPath path = folders[i].getLocation(); if ( path != null ) { path = path.append( fileName ); File file = new File( path.toOSString() ); - if ( file.exists() ) - { + if ( file.exists() ) { IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path ); for ( int j = 0; j < wsFiles.length; ++j ) - if ( wsFiles[j].exists() ) - { + if ( wsFiles[j].exists() ) { if ( !searchForDuplicateFiles() ) return wsFiles[j]; list.add( wsFiles[j] ); @@ -206,28 +173,23 @@ public class CProjectSourceLocation implements IProjectSourceLocation return ( list.size() > 0 ) ? ( ( list.size() == 1 ) ? list.getFirst() : list ) : null; } - private Object cacheLookup( String name ) - { + private Object cacheLookup( String name ) { return fCache.get( name ); } - private boolean notFoundCacheLookup( String name ) - { + private boolean notFoundCacheLookup( String name ) { return fNotFoundCache.contains( name ); } - private void cacheSourceElement( String name, Object element ) - { + private void cacheSourceElement( String name, Object element ) { fCache.put( name, element ); } - private void cacheNotFound( String name ) - { + private void cacheNotFound( String name ) { fNotFoundCache.add( name ); } - public void dispose() - { + public void dispose() { fCache.clear(); fNotFoundCache.clear(); } @@ -247,20 +209,15 @@ public class CProjectSourceLocation implements IProjectSourceLocation node.setAttribute( ATTR_PROJECT, getProject().getName() ); node.setAttribute( ATTR_GENERIC, Boolean.valueOf( isGeneric() ).toString() ); return CDebugUtils.serializeDocument( document ); - } - catch( ParserConfigurationException e ) + } catch( ParserConfigurationException e ) { ex = e; - } - catch( IOException e ) - { + } catch( IOException e ) { + ex = e; + } catch( TransformerException e ) { ex = e; } - catch( TransformerException e ) - { - ex = e; - } - abort( MessageFormat.format( InternalSourceLookupMessages.getString( "CProjectSourceLocation.0" ), new String[] { getProject().getName() } ), ex ); //$NON-NLS-1$ + abort( MessageFormat.format( InternalSourceLookupMessages.CProjectSourceLocation_0, new String[] { getProject().getName() } ), ex ); //$NON-NLS-1$ // execution will not reach here return null; } @@ -280,9 +237,8 @@ public class CProjectSourceLocation implements IProjectSourceLocation root = parser.parse( source ).getDocumentElement(); String name = root.getAttribute( ATTR_PROJECT ); - if ( isEmpty( name ) ) - { - abort( InternalSourceLookupMessages.getString( "CProjectSourceLocation.1" ), null ); //$NON-NLS-1$ + if ( isEmpty( name ) ) { + abort( InternalSourceLookupMessages.CProjectSourceLocation_1, null ); //$NON-NLS-1$ } else { @@ -294,20 +250,14 @@ public class CProjectSourceLocation implements IProjectSourceLocation isGeneric = Boolean.FALSE.toString(); setGenerated( isGeneric.equals( Boolean.TRUE.toString() ) ); return; - } - catch( ParserConfigurationException e ) - { + } catch( ParserConfigurationException e ) { + ex = e; + } catch( SAXException e ) { + ex = e; + } catch( IOException e ) { ex = e; } - catch( SAXException e ) - { - ex = e; - } - catch( IOException e ) - { - ex = e; - } - abort( InternalSourceLookupMessages.getString( "CProjectSourceLocation.2" ), ex ); //$NON-NLS-1$ + abort( InternalSourceLookupMessages.CProjectSourceLocation_2, ex ); //$NON-NLS-1$ } /** @@ -323,49 +273,40 @@ public class CProjectSourceLocation implements IProjectSourceLocation throw new CoreException( s ); } - private boolean isEmpty( String string ) - { + private boolean isEmpty( String string ) { return string == null || string.length() == 0; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation#isGenerated() */ - public boolean isGeneric() - { + public boolean isGeneric() { return fGenerated; } - public void setGenerated( boolean b ) - { + public void setGenerated( boolean b ) { fGenerated = b; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ - public boolean equals( Object obj ) - { + public boolean equals( Object obj ) { if ( obj instanceof IProjectSourceLocation && getProject() != null ) return getProject().equals( ((IProjectSourceLocation)obj).getProject() ); return false; } - private void initializeFolders() - { + private void initializeFolders() { final LinkedList list = new LinkedList(); - if ( getProject() != null && getProject().exists() ) - { + if ( getProject() != null && getProject().exists() ) { list.add( getProject() ); - try - { + try { getProject().accept( - new IResourceProxyVisitor() - { + new IResourceProxyVisitor() { public boolean visit( IResourceProxy proxy ) throws CoreException { - switch( proxy.getType() ) - { + switch( proxy.getType() ) { case IResource.FILE: return false; case IResource.FOLDER: @@ -377,13 +318,10 @@ public class CProjectSourceLocation implements IProjectSourceLocation }, IResource.NONE ); - } - catch( CoreException e ) - { + } catch( CoreException e ) { } } - synchronized( this ) - { + synchronized( this ) { if ( fFolders == null ) { fFolders = (IResource[])list.toArray( new IResource[list.size()] ); @@ -391,8 +329,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation } } - protected IResource[] getFolders() - { + protected IResource[] getFolders() { if ( fFolders == null ) initializeFolders(); return fFolders; @@ -401,23 +338,20 @@ public class CProjectSourceLocation implements IProjectSourceLocation /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles() */ - public boolean searchForDuplicateFiles() - { + public boolean searchForDuplicateFiles() { return fSearchForDuplicateFiles; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean) */ - public void setSearchForDuplicateFiles( boolean search ) - { + public void setSearchForDuplicateFiles( boolean search ) { fCache.clear(); fNotFoundCache.clear(); fSearchForDuplicateFiles = search; } - public String toString() - { + public String toString() { return ( getProject() != null ) ? fProject.toString() : ""; //$NON-NLS-1$ } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java index c6b33ae65ec..f0081914540 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.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; @@ -56,27 +56,19 @@ import org.xml.sax.SAXException; * Default source locator. */ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator, IResourceChangeListener { - private static final String SOURCE_LOCATOR_NAME = "cSourceLocator"; //$NON-NLS-1$ - private static final String DISABLED_GENERIC_PROJECT_NAME = "disabledGenericProject"; //$NON-NLS-1$ - private static final String ADDITIONAL_SOURCE_LOCATION_NAME = "additionalSourceLocation"; //$NON-NLS-1$ - private static final String SOURCE_LOCATION_NAME = "cSourceLocation"; //$NON-NLS-1$ - private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ - private static final String ATTR_MEMENTO = "memento"; //$NON-NLS-1$ - private static final String ATTR_PROJECT_NAME = "projectName"; //$NON-NLS-1$ - private static final String ATTR_DUPLICATE_FILES = "duplicateFiles"; //$NON-NLS-1$ /** * The project associated with this locator. */ - private IProject fProject = null; + private IProject fProject; /** * The array of source locations associated with this locator. @@ -86,20 +78,20 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato /** * The array of projects referenced by main project. */ - private List fReferencedProjects = new ArrayList( 10 ); + private List fReferencedProjects = new ArrayList(10); /** * The flag specifies whether to search for all source elements, or just the first match. */ - private boolean fDuplicateFiles = false; + private boolean fDuplicateFiles; /** * Constructor for CSourceLocator. */ - public CSourceLocator( IProject project ) { - setProject( project ); + public CSourceLocator(IProject project) { + setProject(project); setReferencedProjects(); - setSourceLocations( getDefaultSourceLocations() ); + setSourceLocations(getDefaultSourceLocations()); } /* @@ -107,8 +99,8 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato * * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame) */ - public Object getSourceElement( IStackFrame stackFrame ) { - return getInput( stackFrame ); + public Object getSourceElement(IStackFrame stackFrame) { + return getInput(stackFrame); } /* @@ -116,31 +108,30 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato * * @see org.eclipse.cdt.debug.core.ICSourceLocator#getLineNumber(IStackFrameInfo) */ - public int getLineNumber( IStackFrame frame ) { + public int getLineNumber(IStackFrame frame) { return (frame instanceof ICStackFrame) ? ((ICStackFrame)frame).getFrameLineNumber() : 0; } - protected Object getInput( IStackFrame f ) { - if ( f instanceof ICStackFrame ) { + protected Object getInput(IStackFrame f) { + if (f instanceof ICStackFrame) { ICStackFrame frame = (ICStackFrame)f; - LinkedList list = new LinkedList(); + LinkedList list = new LinkedList(); Object result = null; String fileName = frame.getFile(); - if ( fileName != null && fileName.length() > 0 ) { + if (fileName != null && fileName.length() > 0) { ICSourceLocation[] locations = getSourceLocations(); - for( int i = 0; i < locations.length; ++i ) { + for (int i = 0; i < locations.length; ++i) { try { - result = locations[i].findSourceElement( fileName ); - } - catch( CoreException e ) { + result = locations[i].findSourceElement(fileName); + } catch (CoreException e) { // do nothing } - if ( result != null ) { - if ( result instanceof List ) - list.addAll( (List)result ); + if (result != null) { + if (result instanceof List) + list.addAll((List) result); else - list.add( result ); - if ( !searchForDuplicateFiles() ) + list.add(result); + if (!searchForDuplicateFiles()) break; } } @@ -155,23 +146,22 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato * * @see org.eclipse.cdt.debug.core.ICSourceLocator#contains(IResource) */ - public boolean contains( IResource resource ) { + public boolean contains(IResource resource) { ICSourceLocation[] locations = getSourceLocations(); - for( int i = 0; i < locations.length; ++i ) { - if ( resource instanceof IProject ) { - if ( locations[i] instanceof CProjectSourceLocation && ((CProjectSourceLocation)locations[i]).getProject().equals( resource ) ) { + for (int i = 0; i < locations.length; ++i) { + if (resource instanceof IProject) { + if (locations[i] instanceof CProjectSourceLocation && ((CProjectSourceLocation)locations[i]).getProject().equals(resource)) { return true; } } - if ( resource instanceof IFile ) { + if (resource instanceof IFile) { try { - Object result = locations[i].findSourceElement( resource.getLocation().toOSString() ); - if ( result instanceof IFile && ((IFile)result).equals( resource ) ) + Object result = locations[i].findSourceElement(resource.getLocation().toOSString()); + if (result instanceof IFile && ((IFile) result).equals(resource)) return true; - if ( result instanceof List && ((List)result).contains( resource ) ) + if (result instanceof List && ((List) result).contains(resource)) return true; - } - catch( CoreException e ) { + } catch (CoreException e) { } } } @@ -189,10 +179,9 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato /* * (non-Javadoc) - * * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#setSourceLocations(ICSourceLocation[]) */ - public void setSourceLocations( ICSourceLocation[] locations ) { + public void setSourceLocations(ICSourceLocation[] locations) { fSourceLocations = locations; } @@ -205,37 +194,36 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato * @return a collection of source locations for all required projects * @exception CoreException */ - public static ICSourceLocation[] getDefaultSourceLocations( IProject project ) { - ArrayList list = new ArrayList(); - if ( project != null && project.exists() ) { - list.add( SourceLookupFactory.createProjectSourceLocation( project ) ); - addReferencedSourceLocations( list, project ); + public static ICSourceLocation[] getDefaultSourceLocations(IProject project) { + ArrayList list = new ArrayList(); + if (project != null && project.exists()) { + list.add(SourceLookupFactory.createProjectSourceLocation(project)); + addReferencedSourceLocations(list, project); } - return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ); + return list.toArray(new ICSourceLocation[list.size()]); } - private static void addReferencedSourceLocations( List list, IProject project ) { - if ( project != null ) { + private static void addReferencedSourceLocations(List list, IProject project) { + if (project != null) { try { IProject[] projects = project.getReferencedProjects(); - for( int i = 0; i < projects.length; i++ ) { - if ( projects[i].exists() && !containsProject( list, projects[i] ) ) { - list.add( SourceLookupFactory.createProjectSourceLocation( projects[i] ) ); - addReferencedSourceLocations( list, projects[i] ); + for (int i = 0; i < projects.length; i++) { + if (projects[i].exists() && !containsProject(list, projects[i])) { + list.add(SourceLookupFactory.createProjectSourceLocation(projects[i])); + addReferencedSourceLocations(list, projects[i]); } } - } - catch( CoreException e ) { + } catch (CoreException e) { // do nothing } } } - private static boolean containsProject( List list, IProject project ) { - Iterator it = list.iterator(); - while( it.hasNext() ) { + private static boolean containsProject(List list, IProject project) { + Iterator it = list.iterator(); + while (it.hasNext()) { CProjectSourceLocation location = (CProjectSourceLocation)it.next(); - if ( project.equals( location.getProject() ) ) + if (project.equals(location.getProject())) return true; } return false; @@ -246,18 +234,17 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato * * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#findSourceElement(String) */ - public Object findSourceElement( String fileName ) { + public Object findSourceElement(String fileName) { Object result = null; - if ( fileName != null && fileName.length() > 0 ) { + if (fileName != null && fileName.length() > 0) { ICSourceLocation[] locations = getSourceLocations(); - for( int i = 0; i < locations.length; ++i ) { + for (int i = 0; i < locations.length; ++i) { try { - result = locations[i].findSourceElement( fileName ); - } - catch( CoreException e ) { + result = locations[i].findSourceElement(fileName); + } catch (CoreException e) { // do nothing } - if ( result != null ) + if (result != null) break; } } @@ -274,24 +261,21 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato Throwable ex = null; try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - Element node = document.createElement( SOURCE_LOCATOR_NAME ); - document.appendChild( node ); + Element node = document.createElement(SOURCE_LOCATOR_NAME); + document.appendChild(node); ICSourceLocation[] locations = getSourceLocations(); - saveDisabledGenericSourceLocations( locations, document, node ); - saveAdditionalSourceLocations( locations, document, node ); - node.setAttribute( ATTR_DUPLICATE_FILES, Boolean.valueOf( searchForDuplicateFiles() ).toString() ); - return CDebugUtils.serializeDocument( document ); - } - catch( ParserConfigurationException e ) { + saveDisabledGenericSourceLocations(locations, document, node); + saveAdditionalSourceLocations(locations, document, node); + node.setAttribute(ATTR_DUPLICATE_FILES, Boolean.valueOf(searchForDuplicateFiles()).toString()); + return CDebugUtils.serializeDocument(document); + } catch (ParserConfigurationException e) { + ex = e; + } catch (IOException e) { + ex = e; + } catch (TransformerException e) { ex = e; } - catch( IOException e ) { - ex = e; - } - catch( TransformerException e ) { - ex = e; - } - abort( InternalSourceLookupMessages.getString( "CSourceLocator.0" ), ex ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.CSourceLocator_0, ex); // execution will not reach here return null; } @@ -301,8 +285,8 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato * * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration) */ - public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException { - setSourceLocations( getDefaultSourceLocations() ); + public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { + setSourceLocations(getDefaultSourceLocations()); } /* @@ -310,160 +294,151 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato * * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String) */ - public void initializeFromMemento( String memento ) throws CoreException { + public void initializeFromMemento(String memento) throws CoreException { Exception ex = null; try { Element root = null; DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - StringReader reader = new StringReader( memento ); - InputSource source = new InputSource( reader ); - root = parser.parse( source ).getDocumentElement(); - if ( !root.getNodeName().equalsIgnoreCase( SOURCE_LOCATOR_NAME ) ) { - abort( InternalSourceLookupMessages.getString( "CSourceLocator.1" ) , null ); //$NON-NLS-1$ + StringReader reader = new StringReader(memento); + InputSource source = new InputSource(reader); + root = parser.parse(source).getDocumentElement(); + if (!root.getNodeName().equalsIgnoreCase(SOURCE_LOCATOR_NAME)) { + abort(InternalSourceLookupMessages.CSourceLocator_1 , null); } - List sourceLocations = new ArrayList(); + List sourceLocations = new ArrayList(); // Add locations based on referenced projects IProject project = getProject(); - if ( project != null && project.exists() && project.isOpen() ) - sourceLocations.addAll( Arrays.asList( getDefaultSourceLocations() ) ); - removeDisabledLocations( root, sourceLocations ); - addAdditionalLocations( root, sourceLocations ); + if (project != null && project.exists() && project.isOpen()) + sourceLocations.addAll(Arrays.asList(getDefaultSourceLocations())); + removeDisabledLocations(root, sourceLocations); + addAdditionalLocations(root, sourceLocations); // To support old launch configuration - addOldLocations( root, sourceLocations ); - setSourceLocations( (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ) ); - setSearchForDuplicateFiles( Boolean.valueOf( root.getAttribute( ATTR_DUPLICATE_FILES ) ).booleanValue() ); + addOldLocations(root, sourceLocations); + setSourceLocations(sourceLocations.toArray(new ICSourceLocation[sourceLocations.size()])); + setSearchForDuplicateFiles(Boolean.valueOf(root.getAttribute(ATTR_DUPLICATE_FILES)).booleanValue()); return; - } - catch( ParserConfigurationException e ) { + } catch (ParserConfigurationException e) { + ex = e; + } catch (SAXException e) { + ex = e; + } catch (IOException e) { ex = e; } - catch( SAXException e ) { - ex = e; - } - catch( IOException e ) { - ex = e; - } - abort( InternalSourceLookupMessages.getString( "CSourceLocator.2" ), ex ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.CSourceLocator_2, ex); } - private void removeDisabledLocations( Element root, List sourceLocations ) { + private void removeDisabledLocations(Element root, List sourceLocations) { NodeList list = root.getChildNodes(); int length = list.getLength(); - HashSet disabledProjects = new HashSet( length ); - for( int i = 0; i < length; ++i ) { - Node node = list.item( i ); + HashSet disabledProjects = new HashSet(length); + for (int i = 0; i < length; ++i) { + Node node = list.item(i); short type = node.getNodeType(); - if ( type == Node.ELEMENT_NODE ) { + if (type == Node.ELEMENT_NODE) { Element entry = (Element)node; - if ( entry.getNodeName().equalsIgnoreCase( DISABLED_GENERIC_PROJECT_NAME ) ) { - String projectName = entry.getAttribute( ATTR_PROJECT_NAME ); - if ( isEmpty( projectName ) ) { - CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." ); //$NON-NLS-1$ + if (entry.getNodeName().equalsIgnoreCase(DISABLED_GENERIC_PROJECT_NAME)) { + String projectName = entry.getAttribute(ATTR_PROJECT_NAME); + if (isEmpty(projectName)) { + CDebugCorePlugin.log("Unable to restore C/C++ source locator - invalid format."); //$NON-NLS-1$ } - disabledProjects.add( projectName.trim() ); + disabledProjects.add(projectName.trim()); } } } - Iterator it = sourceLocations.iterator(); - while( it.hasNext() ) { - ICSourceLocation location = (ICSourceLocation)it.next(); - if ( location instanceof IProjectSourceLocation && disabledProjects.contains( ((IProjectSourceLocation)location).getProject().getName() ) ) + Iterator it = sourceLocations.iterator(); + while (it.hasNext()) { + ICSourceLocation location = it.next(); + if (location instanceof IProjectSourceLocation && disabledProjects.contains(((IProjectSourceLocation)location).getProject().getName())) it.remove(); } } - private void addAdditionalLocations( Element root, List sourceLocations ) throws CoreException { + private void addAdditionalLocations(Element root, List sourceLocations) throws CoreException { Bundle bundle = CDebugCorePlugin.getDefault().getBundle(); - MultiStatus status = new MultiStatus( CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, InternalSourceLookupMessages.getString( "CSourceLocator.3" ), null ); //$NON-NLS-1$ + MultiStatus status = new MultiStatus(CDebugCorePlugin.getUniqueIdentifier(), + CDebugCorePlugin.INTERNAL_ERROR, InternalSourceLookupMessages.CSourceLocator_3, null); NodeList list = root.getChildNodes(); int length = list.getLength(); - for( int i = 0; i < length; ++i ) { - Node node = list.item( i ); + for (int i = 0; i < length; ++i) { + Node node = list.item(i); short type = node.getNodeType(); - if ( type == Node.ELEMENT_NODE ) { + if (type == Node.ELEMENT_NODE) { Element entry = (Element)node; - if ( entry.getNodeName().equalsIgnoreCase( ADDITIONAL_SOURCE_LOCATION_NAME ) ) { - String className = entry.getAttribute( ATTR_CLASS ); - String data = entry.getAttribute( ATTR_MEMENTO ); - if ( isEmpty( className ) ) { - CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." ); //$NON-NLS-1$ + if (entry.getNodeName().equalsIgnoreCase(ADDITIONAL_SOURCE_LOCATION_NAME)) { + String className = entry.getAttribute(ATTR_CLASS); + String data = entry.getAttribute(ATTR_MEMENTO); + if (isEmpty(className)) { + CDebugCorePlugin.log("Unable to restore C/C++ source locator - invalid format."); //$NON-NLS-1$ continue; } - Class clazz = null; + Class clazz = null; try { - clazz = bundle.loadClass( className ); - } - catch( ClassNotFoundException e ) { - CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[]{ className } ) ); //$NON-NLS-1$ + clazz = bundle.loadClass(className); + } catch (ClassNotFoundException e) { + CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", new String[]{ className })); //$NON-NLS-1$ continue; } ICSourceLocation location = null; try { location = (ICSourceLocation)clazz.newInstance(); - } - catch( IllegalAccessException e ) { - CDebugCorePlugin.log( "Unable to restore source location." ); //$NON-NLS-1$ + } catch (IllegalAccessException e) { + CDebugCorePlugin.log("Unable to restore source location."); //$NON-NLS-1$ continue; - } - catch( InstantiationException e ) { - CDebugCorePlugin.log( "Unable to restore source location." ); //$NON-NLS-1$ + } catch (InstantiationException e) { + CDebugCorePlugin.log("Unable to restore source location."); //$NON-NLS-1$ continue; } try { - location.initializeFrom( data ); - sourceLocations.add( location ); - } - catch( CoreException e ) { - status.addAll( e.getStatus() ); + location.initializeFrom(data); + sourceLocations.add(location); + } catch (CoreException e) { + status.addAll(e.getStatus()); } } } } - if ( status.getSeverity() > IStatus.OK ) - throw new CoreException( status ); + if (status.getSeverity() > IStatus.OK) + throw new CoreException(status); } - private void addOldLocations( Element root, List sourceLocations ) throws CoreException { + private void addOldLocations(Element root, List sourceLocations) throws CoreException { Bundle bundle = CDebugCorePlugin.getDefault().getBundle(); NodeList list = root.getChildNodes(); int length = list.getLength(); - for( int i = 0; i < length; ++i ) { - Node node = list.item( i ); + for (int i = 0; i < length; ++i) { + Node node = list.item(i); short type = node.getNodeType(); - if ( type == Node.ELEMENT_NODE ) { + if (type == Node.ELEMENT_NODE) { Element entry = (Element)node; - if ( entry.getNodeName().equalsIgnoreCase( SOURCE_LOCATION_NAME ) ) { - String className = entry.getAttribute( ATTR_CLASS ); - String data = entry.getAttribute( ATTR_MEMENTO ); - if ( isEmpty( className ) ) { - CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." ); //$NON-NLS-1$ + if (entry.getNodeName().equalsIgnoreCase(SOURCE_LOCATION_NAME)) { + String className = entry.getAttribute(ATTR_CLASS); + String data = entry.getAttribute(ATTR_MEMENTO); + if (isEmpty(className)) { + CDebugCorePlugin.log("Unable to restore C/C++ source locator - invalid format."); //$NON-NLS-1$ continue; } - Class clazz = null; + Class clazz = null; try { - clazz = bundle.loadClass( className ); - } - catch( ClassNotFoundException e ) { - CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[]{ className } ) ); //$NON-NLS-1$ + clazz = bundle.loadClass(className); + } catch (ClassNotFoundException e) { + CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", new String[]{ className })); //$NON-NLS-1$ continue; } ICSourceLocation location = null; try { location = (ICSourceLocation)clazz.newInstance(); - } - catch( IllegalAccessException e ) { - CDebugCorePlugin.log( "Unable to restore source location." ); //$NON-NLS-1$ + } catch (IllegalAccessException e) { + CDebugCorePlugin.log("Unable to restore source location."); //$NON-NLS-1$ + continue; + } catch (InstantiationException e) { + CDebugCorePlugin.log("Unable to restore source location."); //$NON-NLS-1$ continue; } - catch( InstantiationException e ) { - CDebugCorePlugin.log( "Unable to restore source location." ); //$NON-NLS-1$ - continue; - } - location.initializeFrom( data ); - if ( !sourceLocations.contains( location ) ) { - if ( location instanceof CProjectSourceLocation ) - ((CProjectSourceLocation)location).setGenerated( isReferencedProject( ((CProjectSourceLocation)location).getProject() ) ); - sourceLocations.add( location ); + location.initializeFrom(data); + if (!sourceLocations.contains(location)) { + if (location instanceof CProjectSourceLocation) + ((CProjectSourceLocation)location).setGenerated(isReferencedProject(((CProjectSourceLocation)location).getProject())); + sourceLocations.add(location); } } } @@ -473,87 +448,83 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato /** * Throws an internal error exception */ - private void abort( String message, Throwable e ) throws CoreException { - IStatus s = new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, e ); - throw new CoreException( s ); + private void abort(String message, Throwable e) throws CoreException { + IStatus s = new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, e); + throw new CoreException(s); } - private boolean isEmpty( String string ) { + private boolean isEmpty(String string) { return string == null || string.trim().length() == 0; } - public void resourceChanged( IResourceChangeEvent event ) { - if ( event.getSource() instanceof IWorkspace && event.getDelta() != null ) { + public void resourceChanged(IResourceChangeEvent event) { + if (event.getSource() instanceof IWorkspace && event.getDelta() != null) { IResourceDelta[] deltas = event.getDelta().getAffectedChildren(); - if ( deltas != null ) { - ArrayList list = new ArrayList( deltas.length ); - for( int i = 0; i < deltas.length; ++i ) - if ( deltas[i].getResource() instanceof IProject ) - list.add( deltas[i].getResource() ); - resetSourceLocations( list ); + if (deltas != null) { + ArrayList list = new ArrayList(deltas.length); + for (int i = 0; i < deltas.length; ++i) + if (deltas[i].getResource() instanceof IProject) + list.add(deltas[i].getResource()); + resetSourceLocations(list); } } } - private void saveDisabledGenericSourceLocations( ICSourceLocation[] locations, Document doc, Element node ) { + private void saveDisabledGenericSourceLocations(ICSourceLocation[] locations, Document doc, Element node) { IProject project = getProject(); - if ( project != null && project.exists() && project.isOpen() ) { - List list = CDebugUtils.getReferencedProjects( project ); - HashSet names = new HashSet( list.size() + 1 ); - names.add( project.getName() ); - Iterator it = list.iterator(); - while( it.hasNext() ) { - names.add( ((IProject)it.next()).getName() ); + if (project != null && project.exists() && project.isOpen()) { + List list = CDebugUtils.getReferencedProjects(project); + HashSet names = new HashSet(list.size() + 1); + names.add(project.getName()); + for (IProject proj : list) { + names.add(proj.getName()); } - for( int i = 0; i < locations.length; ++i ) - if ( locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation)locations[i]).isGeneric() ) - names.remove( ((IProjectSourceLocation)locations[i]).getProject().getName() ); - it = names.iterator(); - while( it.hasNext() ) { - Element child = doc.createElement( DISABLED_GENERIC_PROJECT_NAME ); - child.setAttribute( ATTR_PROJECT_NAME, (String)it.next() ); - node.appendChild( child ); + for (int i = 0; i < locations.length; ++i) { + if (locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation) locations[i]).isGeneric()) + names.remove(((IProjectSourceLocation) locations[i]).getProject().getName()); + } + for (String name : names) { + Element child = doc.createElement(DISABLED_GENERIC_PROJECT_NAME); + child.setAttribute(ATTR_PROJECT_NAME, name); + node.appendChild(child); } } } - private void saveAdditionalSourceLocations( ICSourceLocation[] locations, Document doc, Element node ) { - for( int i = 0; i < locations.length; i++ ) { - if ( locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation)locations[i]).isGeneric() ) + private void saveAdditionalSourceLocations(ICSourceLocation[] locations, Document doc, Element node) { + for (int i = 0; i < locations.length; i++) { + if (locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation)locations[i]).isGeneric()) continue; - Element child = doc.createElement( ADDITIONAL_SOURCE_LOCATION_NAME ); - child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() ); + Element child = doc.createElement(ADDITIONAL_SOURCE_LOCATION_NAME); + child.setAttribute(ATTR_CLASS, locations[i].getClass().getName()); try { - child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() ); - } - catch( CoreException e ) { - CDebugCorePlugin.log( e ); + child.setAttribute(ATTR_MEMENTO, locations[i].getMemento()); + } catch (CoreException e) { + CDebugCorePlugin.log(e); continue; } - node.appendChild( child ); + node.appendChild(child); } } /* * (non-Javadoc) - * * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getProject() */ public IProject getProject() { return fProject; } - protected void setProject( IProject project ) { + protected void setProject(IProject project) { fProject = project; } - private boolean isReferencedProject( IProject ref ) { - if ( getProject() != null ) { + private boolean isReferencedProject(IProject ref) { + if (getProject() != null) { try { - return Arrays.asList( getProject().getReferencedProjects() ).contains( ref ); - } - catch( CoreException e ) { - CDebugCorePlugin.log( e ); + return Arrays.asList(getProject().getReferencedProjects()).contains(ref); + } catch (CoreException e) { + CDebugCorePlugin.log(e); } } return false; @@ -561,29 +532,26 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato private void setReferencedProjects() { fReferencedProjects.clear(); - fReferencedProjects = CDebugUtils.getReferencedProjects( getProject() ); + fReferencedProjects = CDebugUtils.getReferencedProjects(getProject()); } protected ICSourceLocation[] getDefaultSourceLocations() { - Iterator it = fReferencedProjects.iterator(); - ArrayList list = new ArrayList( fReferencedProjects.size() ); - if ( getProject() != null && getProject().exists() && getProject().isOpen() ) - list.add( SourceLookupFactory.createProjectSourceLocation( getProject() ) ); - while( it.hasNext() ) { - IProject project = (IProject)it.next(); - if ( project != null && project.exists() && project.isOpen() ) - list.add( SourceLookupFactory.createProjectSourceLocation( project ) ); + ArrayList list = new ArrayList(fReferencedProjects.size()); + if (getProject() != null && getProject().exists() && getProject().isOpen()) + list.add(SourceLookupFactory.createProjectSourceLocation(getProject())); + for (IProject project : fReferencedProjects) { + if (project != null && project.exists() && project.isOpen()) + list.add(SourceLookupFactory.createProjectSourceLocation(project)); } - return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ); + return list.toArray(new ICSourceLocation[list.size()]); } - private void resetSourceLocations( List affectedProjects ) { - if ( affectedProjects.size() != 0 && getProject() != null ) { - if ( !getProject().exists() || !getProject().isOpen() ) { + private void resetSourceLocations(List affectedProjects) { + if (affectedProjects.size() != 0 && getProject() != null) { + if (!getProject().exists() || !getProject().isOpen()) { removeGenericSourceLocations(); - } - else { - updateGenericSourceLocations( affectedProjects ); + } else { + updateGenericSourceLocations(affectedProjects); } } } @@ -591,39 +559,37 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato private void removeGenericSourceLocations() { fReferencedProjects.clear(); ICSourceLocation[] locations = getSourceLocations(); - ArrayList newLocations = new ArrayList( locations.length ); - for( int i = 0; i < locations.length; ++i ) - if ( !(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric() ) - newLocations.add( locations[i] ); - setSourceLocations( (ICSourceLocation[])newLocations.toArray( new ICSourceLocation[newLocations.size()] ) ); + ArrayList newLocations = new ArrayList(locations.length); + for (int i = 0; i < locations.length; ++i) { + if (!(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric()) + newLocations.add(locations[i]); + } + setSourceLocations(newLocations.toArray(new ICSourceLocation[newLocations.size()])); } - private void updateGenericSourceLocations( List affectedProjects ) { - List newRefs = CDebugUtils.getReferencedProjects( getProject() ); + private void updateGenericSourceLocations(List affectedProjects) { + List newRefs = CDebugUtils.getReferencedProjects(getProject()); ICSourceLocation[] locations = getSourceLocations(); - ArrayList newLocations = new ArrayList( locations.length ); - for( int i = 0; i < locations.length; ++i ) { - if ( !(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric() ) { - newLocations.add( locations[i] ); - } - else { + ArrayList newLocations = new ArrayList(locations.length); + for (int i = 0; i < locations.length; ++i) { + if (!(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric()) { + newLocations.add(locations[i]); + } else { IProject project = ((IProjectSourceLocation)locations[i]).getProject(); - if ( project.exists() && project.isOpen() ) { - if ( newRefs.contains( project ) || project.equals( getProject() ) ) { - newLocations.add( locations[i] ); - newRefs.remove( project ); + if (project.exists() && project.isOpen()) { + if (newRefs.contains(project) || project.equals(getProject())) { + newLocations.add(locations[i]); + newRefs.remove(project); } } } } - Iterator it = newRefs.iterator(); - while( it.hasNext() ) { - IProject project = (IProject)it.next(); - if ( !fReferencedProjects.contains( project ) ) - newLocations.add( SourceLookupFactory.createProjectSourceLocation( project ) ); + for (IProject project : newRefs) { + if (!fReferencedProjects.contains(project)) + newLocations.add(SourceLookupFactory.createProjectSourceLocation(project)); } fReferencedProjects = newRefs; - setSourceLocations( (ICSourceLocation[])newLocations.toArray( new ICSourceLocation[newLocations.size()] ) ); + setSourceLocations(newLocations.toArray(new ICSourceLocation[newLocations.size()])); } /* @@ -635,10 +601,10 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato return fDuplicateFiles; } - public void setSearchForDuplicateFiles( boolean search ) { + public void setSearchForDuplicateFiles(boolean search) { fDuplicateFiles = search; ICSourceLocation[] locations = getSourceLocations(); - for( int i = 0; i < locations.length; ++i ) - locations[i].setSearchForDuplicateFiles( search ); + for (int i = 0; i < locations.length; ++i) + locations[i].setSearchForDuplicateFiles(search); } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java index 70499e54a14..846c8f5682e 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java @@ -19,6 +19,7 @@ import java.util.Set; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer; +import org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.ProgramRelativePathSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; import org.eclipse.core.resources.IContainer; @@ -182,22 +183,21 @@ public class CSourceLookupDirector extends AbstractSourceLookupDirector { } private IPath getCompilationPath(ISourceContainer container, String sourceName) { - IPath path = null; - if (container instanceof MappingSourceContainer) { - path = ((MappingSourceContainer) container).getCompilationPath(sourceName); - } else { - try { - ISourceContainer[] containers; - containers = container.getSourceContainers(); - for (int i = 0; i < containers.length; ++i) { - path = getCompilationPath(containers[i], sourceName); - if (path != null) - break; - } - } catch (CoreException e) { - } + if (container instanceof IMappingSourceContainer) { + return ((IMappingSourceContainer) container).getCompilationPath(sourceName); } - return path; + + try { + ISourceContainer[] containers; + containers = container.getSourceContainers(); + for (int i = 0; i < containers.length; ++i) { + IPath path = getCompilationPath(containers[i], sourceName); + if (path != null) + return path; + } + } catch (CoreException e) { + } + return null; } // >> Bugzilla 279473 diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.java index cce8157d148..bbead0ae9bb 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.java @@ -6,28 +6,43 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX Software Systems - Initial API and implementation + * QNX Software Systems - Initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.debug.internal.core.sourcelookup; -import java.util.MissingResourceException; -import java.util.ResourceBundle; +import org.eclipse.osgi.util.NLS; -public class InternalSourceLookupMessages { +public class InternalSourceLookupMessages extends NLS { + public static String CDirectorySourceLocation_0; + public static String CDirectorySourceLocation_1; + public static String CDirectorySourceLocation_2; + public static String CDirectorySourceLocation_3; + public static String CDirectorySourceContainerType_0; + public static String CDirectorySourceContainerType_1; + public static String CDirectorySourceContainerType_2; + public static String CProjectSourceLocation_0; + public static String CProjectSourceLocation_1; + public static String CProjectSourceLocation_2; + public static String CSourceLocator_0; + public static String CSourceLocator_1; + public static String CSourceLocator_2; + public static String CSourceLocator_3; + public static String MapEntrySourceContainerType_0; + public static String MapEntrySourceContainerType_1; + public static String MapEntrySourceContainerType_2; + public static String MapEntrySourceContainerType_3; + public static String MappingSourceContainerType_0; + public static String MappingSourceContainerType_1; + public static String MappingSourceContainerType_2; + public static String SourceUtils_0; + public static String ProgramRelativePathSourceContainerType_1; - private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.internal.core.sourcelookup.InternalSourceLookupMessages";//$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); + static { + NLS.initializeMessages(InternalSourceLookupMessages.class.getName(), InternalSourceLookupMessages.class); + } private InternalSourceLookupMessages() { - } - - public static String getString( String key ) { - try { - return RESOURCE_BUNDLE.getString( key ); - } - catch( MissingResourceException e ) { - return '!' + key + '!'; - } + // Do not instantiate } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties index 83cb286c383..58aeadb5f8e 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties @@ -7,28 +7,29 @@ # # Contributors: # QNX Software Systems - initial API and implementation +# Sergey Prigogin (Google) ############################################################################### -CDirectorySourceLocation.0=Unable to create memento for C/C++ directory source location {0}. -CDirectorySourceLocation.1=Unable to initialize source location - missing directory path. -CDirectorySourceLocation.2=Unable to initialize source location - invalid directory path {0}. -CDirectorySourceLocation.3=Exception occurred initializing source location. -CDirectorySourceContainerType.0=Unable to restore directory source lookup entry - missing path attribute. -CDirectorySourceContainerType.1=Unable to restore directory source lookup entry - expecting directory element. -CDirectorySourceContainerType.2=Unable to restore directory source lookup entry - invalid memento. -CProjectSourceLocation.0=Unable to create memento for C/C++ project source location {0}. -CProjectSourceLocation.1=Unable to initialize source location - missing project name -CProjectSourceLocation.2=Exception occurred initializing source location. -CSourceLocator.0=Unable to create memento for C/C++ source locator. -CSourceLocator.1=Unable to restore C/C++ source locator - invalid format. -CSourceLocator.2=Exception occurred initializing source locator. -CSourceLocator.3=Error initializing directory source location. -MapEntrySourceContainerType.0=Source lookup: unable to restore map entry - missing backend path attribute. -MapEntrySourceContainerType.1=Source lookup: unable to restore map entry - missing local path attribute. -MapEntrySourceContainerType.2=Source lookup: unable to restore map entry - expecting map entry element. -MapEntrySourceContainerType.3=Source lookup: unable to restore map entry - invalid memento. -MappingSourceContainerType.0=Source lookup: unable to restore map entry - expecting memento attribute. -MappingSourceContainerType.1=Source lookup: unable to restore mapping - expecting mapping element. -MappingSourceContainerType.2=Source lookup: unable to restore mapping - invalid memento. -SourceUtils.0=Mapping -ProgramRelativePathSourceContainerType.1=Source lookup: unable to restore program relative source container - invalid memento. +CDirectorySourceLocation_0=Unable to create memento for C/C++ directory source location {0}. +CDirectorySourceLocation_1=Unable to initialize source location - missing directory path. +CDirectorySourceLocation_2=Unable to initialize source location - invalid directory path {0}. +CDirectorySourceLocation_3=Exception occurred initializing source location. +CDirectorySourceContainerType_0=Unable to restore directory source lookup entry - missing path attribute. +CDirectorySourceContainerType_1=Unable to restore directory source lookup entry - expecting directory element. +CDirectorySourceContainerType_2=Unable to restore directory source lookup entry - invalid memento. +CProjectSourceLocation_0=Unable to create memento for C/C++ project source location {0}. +CProjectSourceLocation_1=Unable to initialize source location - missing project name +CProjectSourceLocation_2=Exception occurred initializing source location. +CSourceLocator_0=Unable to create memento for C/C++ source locator. +CSourceLocator_1=Unable to restore C/C++ source locator - invalid format. +CSourceLocator_2=Exception occurred initializing source locator. +CSourceLocator_3=Error initializing directory source location. +MapEntrySourceContainerType_0=Source lookup: unable to restore map entry - missing backend path attribute. +MapEntrySourceContainerType_1=Source lookup: unable to restore map entry - missing local path attribute. +MapEntrySourceContainerType_2=Source lookup: unable to restore map entry - expecting map entry element. +MapEntrySourceContainerType_3=Source lookup: unable to restore map entry - invalid memento. +MappingSourceContainerType_0=Source lookup: unable to restore map entry - expecting memento attribute. +MappingSourceContainerType_1=Source lookup: unable to restore mapping - expecting mapping element. +MappingSourceContainerType_2=Source lookup: unable to restore mapping - invalid memento. +SourceUtils_0=Mapping +ProgramRelativePathSourceContainerType_1=Source lookup: unable to restore program relative source container - invalid memento. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.java index 7591910c102..50d4e9cd24e 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.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; @@ -38,18 +38,18 @@ public class MapEntrySourceContainerType extends AbstractSourceContainerTypeDele String path = element.getAttribute(BACKEND_PATH); IPath backend = new Path(path); if (!backend.isValidPath(path)) { - abort(InternalSourceLookupMessages.getString("MapEntrySourceContainerType.0"), null); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.MapEntrySourceContainerType_0, null); } path = element.getAttribute(LOCAL_PATH); IPath local = new Path(path); if (!local.isValidPath(path)) { - abort(InternalSourceLookupMessages.getString("MapEntrySourceContainerType.1"), null); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.MapEntrySourceContainerType_1, null); } return new MapEntrySourceContainer(backend, local); } - abort(InternalSourceLookupMessages.getString("MapEntrySourceContainerType.2"), null); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.MapEntrySourceContainerType_2, null); } - abort(InternalSourceLookupMessages.getString("MapEntrySourceContainerType.3"), null); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.MapEntrySourceContainerType_3, null); return null; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java index f25762f07d7..4d86e293144 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java @@ -6,12 +6,11 @@ * 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; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; import org.eclipse.core.runtime.CoreException; @@ -27,7 +26,6 @@ import org.w3c.dom.Node; * The mapping container type. */ public class MappingSourceContainerType extends AbstractSourceContainerTypeDelegate { - private final static String ELEMENT_MAPPING = "mapping"; //$NON-NLS-1$ private final static String ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$ private final static String ATTR_NAME = "name"; //$NON-NLS-1$ @@ -36,58 +34,57 @@ public class MappingSourceContainerType extends AbstractSourceContainerTypeDeleg /* (non-Javadoc) * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String) */ - public ISourceContainer createSourceContainer( String memento ) throws CoreException { - Node node = parseDocument( memento ); - if ( node.getNodeType() == Node.ELEMENT_NODE ) { - Element element = (Element)node; - if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) { - String name = element.getAttribute( ATTR_NAME ); - if ( name == null ) + public ISourceContainer createSourceContainer(String memento) throws CoreException { + Node node = parseDocument(memento); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + if (ELEMENT_MAPPING.equals(element.getNodeName())) { + String name = element.getAttribute(ATTR_NAME); + if (name == null) name = ""; //$NON-NLS-1$ - List entries = new ArrayList(); + List entries = new ArrayList(); Node childNode = element.getFirstChild(); - while( childNode != null ) { - if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { + while (childNode != null) { + if (childNode.getNodeType() == Node.ELEMENT_NODE) { Element child = (Element)childNode; - if ( ELEMENT_MAP_ENTRY.equals( child.getNodeName() ) ) { - String childMemento = child.getAttribute( ATTR_MEMENTO ); - if ( childMemento == null || childMemento.length() == 0 ) { - abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.0" ), null ); //$NON-NLS-1$ + if (ELEMENT_MAP_ENTRY.equals(child.getNodeName())) { + String childMemento = child.getAttribute(ATTR_MEMENTO); + if (childMemento == null || childMemento.length() == 0) { + abort(InternalSourceLookupMessages.MappingSourceContainerType_0, null); } - ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID ); - MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento ); - entries.add( entry ); + ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType(MapEntrySourceContainer.TYPE_ID); + MapEntrySourceContainer entry = (MapEntrySourceContainer) type.createSourceContainer(childMemento); + entries.add(entry); } } childNode = childNode.getNextSibling(); } - MappingSourceContainer container = new MappingSourceContainer( name ); - Iterator it = entries.iterator(); - while( it.hasNext() ) { - container.addMapEntry( (MapEntrySourceContainer)it.next() ); + MappingSourceContainer container = new MappingSourceContainer(name); + for (MapEntrySourceContainer entry : entries) { + container.addMapEntry(entry); } return container; } - abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.1" ), null ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.MappingSourceContainerType_1, null); } - abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.2" ), null ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.MappingSourceContainerType_2, null); return null; } /* (non-Javadoc) * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer) */ - public String getMemento( ISourceContainer container ) throws CoreException { + public String getMemento(ISourceContainer container) throws CoreException { Document document = newDocument(); - Element element = document.createElement( ELEMENT_MAPPING ); - element.setAttribute( ATTR_NAME, container.getName() ); + Element element = document.createElement(ELEMENT_MAPPING); + element.setAttribute(ATTR_NAME, container.getName()); ISourceContainer[] entries = ((MappingSourceContainer)container).getSourceContainers(); - for ( int i = 0; i < entries.length; ++i ) { - Element child = document.createElement( ELEMENT_MAP_ENTRY ); - child.setAttribute( ATTR_MEMENTO, entries[i].getType().getMemento( entries[i] ) ); - element.appendChild( child ); + for (int i = 0; i < entries.length; ++i) { + Element child = document.createElement(ELEMENT_MAP_ENTRY); + child.setAttribute(ATTR_MEMENTO, entries[i].getType().getMemento(entries[i])); + element.appendChild(child); } - document.appendChild( element ); - return serializeDocument( document ); + document.appendChild(element); + return serializeDocument(document); } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/ProgramRelativePathSourceContainerType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/ProgramRelativePathSourceContainerType.java index 729319dab17..cdd1b39ac6a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/ProgramRelativePathSourceContainerType.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/ProgramRelativePathSourceContainerType.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Freescale - Initial implementation + * Freescale - Initial implementation *******************************************************************************/ - package org.eclipse.cdt.debug.internal.core.sourcelookup; import org.eclipse.cdt.debug.core.sourcelookup.ProgramRelativePathSourceContainer; @@ -17,22 +16,20 @@ import org.eclipse.debug.core.sourcelookup.ISourceContainer; import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate; public class ProgramRelativePathSourceContainerType extends AbstractSourceContainerTypeDelegate { - private final static String ELEMENT_NAME = "programRelativePath"; //$NON-NLS-1$ public ISourceContainer createSourceContainer(String memento) throws CoreException { - if ( ELEMENT_NAME.equals( memento ) ) { + if (ELEMENT_NAME.equals(memento)) { return new ProgramRelativePathSourceContainer(); } - abort( InternalSourceLookupMessages.getString("ProgramRelativePathSourceContainerType.1"), null ); //$NON-NLS-1$ + abort(InternalSourceLookupMessages.ProgramRelativePathSourceContainerType_1, null); return null; } public String getMemento(ISourceContainer container) throws CoreException { - if (container instanceof ProgramRelativePathSourceContainer){ + if (container instanceof ProgramRelativePathSourceContainer) { return ELEMENT_NAME; - } - else{ + } else { return ""; //$NON-NLS-1$ } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java index b21c0593d33..38b831a90df 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java @@ -41,149 +41,138 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class SourceUtils { - private static final String NAME_COMMON_SOURCE_LOCATIONS = "commonSourceLocations"; //$NON-NLS-1$ - private static final String NAME_SOURCE_LOCATION = "sourceLocation"; //$NON-NLS-1$ - private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ - private static final String ATTR_MEMENTO = "memento"; //$NON-NLS-1$ - public static String getCommonSourceLocationsMemento( ICSourceLocation[] locations ) { + public static String getCommonSourceLocationsMemento(ICSourceLocation[] locations) { Document document = null; Throwable ex = null; try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - Element element = document.createElement( NAME_COMMON_SOURCE_LOCATIONS ); - document.appendChild( element ); - saveSourceLocations( document, element, locations ); - return CDebugUtils.serializeDocument( document ); - } - catch( ParserConfigurationException e ) { + Element element = document.createElement(NAME_COMMON_SOURCE_LOCATIONS); + document.appendChild(element); + saveSourceLocations(document, element, locations); + return CDebugUtils.serializeDocument(document); + } catch (ParserConfigurationException e) { + ex = e; + } catch (IOException e) { + ex = e; + } catch (TransformerException e) { ex = e; } - catch( IOException e ) { - ex = e; - } - catch( TransformerException e ) { - ex = e; - } - CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error saving common source settings.", ex ) ); //$NON-NLS-1$ + CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, + "Error saving common source settings.", ex)); //$NON-NLS-1$ return null; } - private static void saveSourceLocations( Document doc, Element node, ICSourceLocation[] locations ) { - for( int i = 0; i < locations.length; i++ ) { - Element child = doc.createElement( NAME_SOURCE_LOCATION ); - child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() ); + private static void saveSourceLocations(Document doc, Element node, ICSourceLocation[] locations) { + for(int i = 0; i < locations.length; i++) { + Element child = doc.createElement(NAME_SOURCE_LOCATION); + child.setAttribute(ATTR_CLASS, locations[i].getClass().getName()); try { - child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() ); - } - catch( CoreException e ) { - CDebugCorePlugin.log( e ); + child.setAttribute(ATTR_MEMENTO, locations[i].getMemento()); + } catch (CoreException e) { + CDebugCorePlugin.log(e); continue; } - node.appendChild( child ); + node.appendChild(child); } } - public static ICSourceLocation[] getCommonSourceLocationsFromMemento( String memento ) { + public static ICSourceLocation[] getCommonSourceLocationsFromMemento(String memento) { ICSourceLocation[] result = new ICSourceLocation[0]; - if ( !isEmpty( memento ) ) { + if (!isEmpty(memento)) { try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - StringReader reader = new StringReader( memento ); - InputSource source = new InputSource( reader ); - Element root = parser.parse( source ).getDocumentElement(); - if ( root.getNodeName().equalsIgnoreCase( NAME_COMMON_SOURCE_LOCATIONS ) ) - result = initializeSourceLocations( root ); - } - catch( ParserConfigurationException e ) { - CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$ - } - catch( SAXException e ) { - CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$ - } - catch( IOException e ) { - CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$ + StringReader reader = new StringReader(memento); + InputSource source = new InputSource(reader); + Element root = parser.parse(source).getDocumentElement(); + if (root.getNodeName().equalsIgnoreCase(NAME_COMMON_SOURCE_LOCATIONS)) + result = initializeSourceLocations(root); + } catch (ParserConfigurationException e) { + CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, + "Error initializing common source settings.", e)); //$NON-NLS-1$ + } catch (SAXException e) { + CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, + "Error initializing common source settings.", e)); //$NON-NLS-1$ + } catch (IOException e) { + CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, + "Error initializing common source settings.", e)); //$NON-NLS-1$ } } return result; } - public static ICSourceLocation[] initializeSourceLocations( Element root ) { - List sourceLocations = new LinkedList(); + public static ICSourceLocation[] initializeSourceLocations(Element root) { + List sourceLocations = new LinkedList(); NodeList list = root.getChildNodes(); int length = list.getLength(); - for( int i = 0; i < length; ++i ) { - Node node = list.item( i ); + for(int i = 0; i < length; ++i) { + Node node = list.item(i); short type = node.getNodeType(); - if ( type == Node.ELEMENT_NODE ) { + if (type == Node.ELEMENT_NODE) { Element entry = (Element)node; - if ( entry.getNodeName().equalsIgnoreCase( NAME_SOURCE_LOCATION ) ) { - String className = entry.getAttribute( ATTR_CLASS ); - String data = entry.getAttribute( ATTR_MEMENTO ); - if ( className == null || className.trim().length() == 0 ) { - CDebugCorePlugin.log( "Unable to restore common source locations - invalid format." ); //$NON-NLS-1$ + if (entry.getNodeName().equalsIgnoreCase(NAME_SOURCE_LOCATION)) { + String className = entry.getAttribute(ATTR_CLASS); + String data = entry.getAttribute(ATTR_MEMENTO); + if (className == null || className.trim().length() == 0) { + CDebugCorePlugin.log("Unable to restore common source locations - invalid format."); //$NON-NLS-1$ continue; } - Class clazz = null; + Class clazz = null; try { - clazz = CDebugCorePlugin.getDefault().getBundle().loadClass( className ); - } - catch( ClassNotFoundException e ) { - CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[]{ className } ) ); //$NON-NLS-1$ + clazz = CDebugCorePlugin.getDefault().getBundle().loadClass(className); + } catch (ClassNotFoundException e) { + CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", //$NON-NLS-1$ + new String[] { className })); continue; } ICSourceLocation location = null; try { location = (ICSourceLocation)clazz.newInstance(); - } - catch( IllegalAccessException e ) { - CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$ + } catch (IllegalAccessException e) { + CDebugCorePlugin.log("Unable to restore source location: " + e.getMessage()); //$NON-NLS-1$ continue; - } - catch( InstantiationException e ) { - CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$ + } catch (InstantiationException e) { + CDebugCorePlugin.log("Unable to restore source location: " + e.getMessage()); //$NON-NLS-1$ continue; } try { - location.initializeFrom( data ); - sourceLocations.add( location ); - } - catch( CoreException e ) { - CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$ + location.initializeFrom(data); + sourceLocations.add(location); + } catch (CoreException e) { + CDebugCorePlugin.log("Unable to restore source location: " + e.getMessage()); //$NON-NLS-1$ } } } } - return (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ); + return sourceLocations.toArray(new ICSourceLocation[sourceLocations.size()]); } - private static boolean isEmpty( String string ) { + private static boolean isEmpty(String string) { return (string == null || string.trim().length() == 0); } - static public ISourceContainer[] convertSourceLocations( ICSourceLocation[] locations ) { - ArrayList containers = new ArrayList( locations.length ); + static public ISourceContainer[] convertSourceLocations(ICSourceLocation[] locations) { + ArrayList containers = new ArrayList(locations.length); int mappingCount = 0; - for ( int i = 0; i < locations.length; ++i ) { - if ( locations[i] instanceof IProjectSourceLocation ) { - containers.add( new ProjectSourceContainer( ((IProjectSourceLocation)locations[i]).getProject(), false ) ); - } - else if ( locations[i] instanceof IDirectorySourceLocation ) { + for (int i = 0; i < locations.length; ++i) { + if (locations[i] instanceof IProjectSourceLocation) { + containers.add(new ProjectSourceContainer(((IProjectSourceLocation)locations[i]).getProject(), false)); + } else if (locations[i] instanceof IDirectorySourceLocation) { IDirectorySourceLocation d = (IDirectorySourceLocation)locations[i]; IPath a = d.getAssociation(); - if ( a != null ) { - MappingSourceContainer mapping = new MappingSourceContainer( InternalSourceLookupMessages.getString( "SourceUtils.0" ) + (++mappingCount) ); //$NON-NLS-1$ - mapping.addMapEntries( new MapEntrySourceContainer[] { new MapEntrySourceContainer( a, d.getDirectory() ) } ); - containers.add( mapping ); + if (a != null) { + MappingSourceContainer mapping = new MappingSourceContainer(InternalSourceLookupMessages.SourceUtils_0 + (++mappingCount)); + mapping.addMapEntries(new MapEntrySourceContainer[] { new MapEntrySourceContainer(a, d.getDirectory()) }); + containers.add(mapping); } - containers.add( new DirectorySourceContainer( d.getDirectory(), d.searchSubfolders() ) ); + containers.add(new DirectorySourceContainer(d.getDirectory(), d.searchSubfolders())); } } - return (ISourceContainer[])containers.toArray( new ISourceContainer[containers.size()] ); + return containers.toArray(new ISourceContainer[containers.size()]); } }