1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 01:05:38 +02:00

NLS-style string resources.

This commit is contained in:
Sergey Prigogin 2010-12-02 20:45:54 +00:00
parent f3b4634427
commit bd51ec8825
11 changed files with 684 additions and 860 deletions

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
@ -27,39 +27,39 @@ public class CDirectorySourceContainerType extends AbstractSourceContainerTypeDe
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#createSourceContainer(java.lang.String) * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#createSourceContainer(java.lang.String)
*/ */
public ISourceContainer createSourceContainer( String memento ) throws CoreException { public ISourceContainer createSourceContainer(String memento) throws CoreException {
Node node = parseDocument( memento ); Node node = parseDocument(memento);
if ( node.getNodeType() == Node.ELEMENT_NODE ) { if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element)node; Element element = (Element) node;
if ( "directory".equals( element.getNodeName() ) ) { //$NON-NLS-1$ if ("directory".equals(element.getNodeName())) { //$NON-NLS-1$
String string = element.getAttribute( "path" ); //$NON-NLS-1$ String string = element.getAttribute("path"); //$NON-NLS-1$
if ( string == null || string.length() == 0 ) { if (string == null || string.length() == 0) {
abort( InternalSourceLookupMessages.getString( "CDirectorySourceContainerType.0" ), null ); //$NON-NLS-1$ abort(InternalSourceLookupMessages.CDirectorySourceContainerType_0, null);
} }
String nest = element.getAttribute( "nest" ); //$NON-NLS-1$ String nest = element.getAttribute("nest"); //$NON-NLS-1$
boolean nested = "true".equals( nest ); //$NON-NLS-1$ boolean nested = "true".equals(nest); //$NON-NLS-1$
return new DirectorySourceContainer( new Path( string ), nested ); 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; return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#getMemento(org.eclipse.debug.internal.core.sourcelookup.ISourceContainer) * @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; DirectorySourceContainer folder = (DirectorySourceContainer)container;
Document document = newDocument(); Document document = newDocument();
Element element = document.createElement( "directory" ); //$NON-NLS-1$ Element element = document.createElement("directory"); //$NON-NLS-1$
element.setAttribute( "path", folder.getDirectory().getAbsolutePath() ); //$NON-NLS-1$ element.setAttribute("path", folder.getDirectory().getAbsolutePath()); //$NON-NLS-1$
String nest = "false"; //$NON-NLS-1$ String nest = "false"; //$NON-NLS-1$
if ( folder.isComposite() ) { if (folder.isComposite()) {
nest = "true"; //$NON-NLS-1$ nest = "true"; //$NON-NLS-1$
} }
element.setAttribute( "nest", nest ); //$NON-NLS-1$ element.setAttribute("nest", nest); //$NON-NLS-1$
document.appendChild( element ); document.appendChild(element);
return serializeDocument( document ); return serializeDocument(document);
} }
} }

View file

@ -14,7 +14,6 @@ import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import com.ibm.icu.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; 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.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
@ -50,8 +50,7 @@ import org.xml.sax.SAXException;
* *
* @since Sep 23, 2002 * @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 ELEMENT_NAME = "cDirectorySourceLocation"; //$NON-NLS-1$
private static final String ATTR_DIRECTORY = "directory"; //$NON-NLS-1$ private static final String ATTR_DIRECTORY = "directory"; //$NON-NLS-1$
private static final String ATTR_ASSOCIATION = "association"; //$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 * The root directory of this source location
*/ */
private IPath fDirectory; private IPath fDirectory;
/** /**
* The associted path of this source location. * The associated path of this source location.
*/ */
private IPath fAssociation = null; private IPath fAssociation;
private boolean fSearchForDuplicateFiles;
private boolean fSearchForDuplicateFiles = false; private boolean fSearchSubfolders;
private File[] fFolders;
private boolean fSearchSubfolders = false;
private File[] fFolders = null;
/** /**
* Constructor for CDirectorySourceLocation. * Constructor for CDirectorySourceLocation.
*/ */
public CDirectorySourceLocation() public CDirectorySourceLocation() {
{
} }
/** /**
* Constructor for CDirectorySourceLocation. * Constructor for CDirectorySourceLocation.
*/ */
public CDirectorySourceLocation( IPath directory, IPath association, boolean searchSubfolders ) public CDirectorySourceLocation(IPath directory, IPath association, boolean searchSubfolders) {
{ setDirectory(directory);
setDirectory( directory ); setAssociation(association);
setAssociation( association ); setSearchSubfolders(searchSubfolders);
setSearchSubfolders( searchSubfolders );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#findSourceElement(String) * @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; Object result = null;
if ( !isEmpty( name ) && getDirectory() != null ) if (!isEmpty(name) && getDirectory() != null) {
{ File file = new File(name);
File file = new File( name ); if (file.isAbsolute()) {
if ( file.isAbsolute() ) result = findFileByAbsolutePath(name);
result = findFileByAbsolutePath( name ); } else {
else result = findFileByRelativePath(name);
result = findFileByRelativePath( name ); }
if ( result == null && getAssociation() != null ) if (result == null && getAssociation() != null) {
{ IPath path = new Path(name);
IPath path = new Path( name ); if (path.segmentCount() > 1 && getAssociation().isPrefixOf(path)) {
if ( path.segmentCount() > 1 && getAssociation().isPrefixOf( path ) ) path = getDirectory().append(path.removeFirstSegments(getAssociation().segmentCount()));
{ result = findFileByAbsolutePath(path.toOSString());
path = getDirectory().append( path.removeFirstSegments( getAssociation().segmentCount() ) );
result = findFileByAbsolutePath( path.toOSString() );
} }
} }
} }
@ -119,13 +109,12 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
*/ */
public Object getAdapter( Class adapter ) public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
{ if (adapter.equals(ICSourceLocation.class))
if ( adapter.equals( ICSourceLocation.class ) )
return this; return this;
if ( adapter.equals( CDirectorySourceLocation.class ) ) if (adapter.equals(CDirectorySourceLocation.class))
return this; return this;
if ( adapter.equals( IPath.class ) ) if (adapter.equals(IPath.class))
return getDirectory(); return getDirectory();
return null; return null;
} }
@ -135,8 +124,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
* *
* @param directory a directory * @param directory a directory
*/ */
private void setDirectory( IPath directory ) private void setDirectory(IPath directory) {
{
fDirectory = directory; fDirectory = directory;
} }
@ -145,186 +133,162 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
* *
* @return directory * @return directory
*/ */
public IPath getDirectory() public IPath getDirectory() {
{
return fDirectory; return fDirectory;
} }
public void getDirectory( IPath path ) public void getDirectory(IPath path) {
{
fDirectory = path; fDirectory = path;
} }
public void setAssociation( IPath association ) public void setAssociation(IPath association) {
{
fAssociation = association; fAssociation = association;
} }
public IPath getAssociation() public IPath getAssociation() {
{
return fAssociation; return fAssociation;
} }
private Object findFileByAbsolutePath( String name ) @SuppressWarnings("unchecked")
{ private Object findFileByAbsolutePath(String name) {
File file = new File( name ); File file = new File(name);
if ( !file.isAbsolute() ) if (!file.isAbsolute())
return null; return null;
File[] folders = getFolders(); File[] folders = getFolders();
if ( folders != null ) if (folders != null) {
{ LinkedList<Object> list = new LinkedList<Object>();
LinkedList list = new LinkedList(); for (int i = 0; i < folders.length; ++i) {
for ( int i = 0; i < folders.length; ++i ) Object result = findFileByAbsolutePath(folders[i], name);
{ if (result instanceof List) {
Object result = findFileByAbsolutePath( folders[i], name ); if (searchForDuplicateFiles()) {
if ( result instanceof List ) list.addAll((List<Object>) result);
{ } else {
if ( searchForDuplicateFiles() )
list.addAll( (List)result );
else
return list.getFirst(); return list.getFirst();
} }
else if ( result != null ) } else if (result != null) {
{ if (searchForDuplicateFiles()) {
if ( searchForDuplicateFiles() ) list.add(result);
list.add( result ); } else {
else
return result; return result;
}
} }
} }
if ( list.size() > 0 ) if (list.size() > 0)
return ( list.size() == 1 ) ? list.getFirst() : list; return (list.size() == 1) ? list.getFirst() : list;
} }
return null; return null;
} }
private Object findFileByAbsolutePath( File folder, String name ) private Object findFileByAbsolutePath(File folder, String name) {
{ File file = new File(name);
File file = new File( name ); if (!file.isAbsolute())
if ( !file.isAbsolute() )
return null; return null;
IPath filePath = new Path( name ); IPath filePath = new Path(name);
IPath path = new Path( folder.getAbsolutePath() ); IPath path = new Path(folder.getAbsolutePath());
IPath association = getAssociation(); IPath association = getAssociation();
if ( !isPrefix( path, filePath ) || path.segmentCount() + 1 != filePath.segmentCount() ) if (!isPrefix(path, filePath) || path.segmentCount() + 1 != filePath.segmentCount()) {
{ if (association != null &&
if ( association != null && isPrefix( association, filePath ) && association.segmentCount() + 1 == filePath.segmentCount() ) isPrefix(association, filePath) && association.segmentCount() + 1 == filePath.segmentCount()) {
filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) ); filePath = path.append(filePath.removeFirstSegments(association.segmentCount()));
else } else {
return null; return null;
}
} }
// Try for a file in another workspace project // Try for a file in another workspace project
IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( filePath ); IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath);
LinkedList list = new LinkedList(); LinkedList<IFile> list = new LinkedList<IFile>();
for ( int j = 0; j < wsFiles.length; ++j ) for (int j = 0; j < wsFiles.length; ++j)
if ( wsFiles[j].exists() ) if (wsFiles[j].exists()) {
{ if (!searchForDuplicateFiles())
if ( !searchForDuplicateFiles() )
return wsFiles[j]; return wsFiles[j];
list.add( wsFiles[j] ); list.add(wsFiles[j]);
} }
if ( list.size() > 0 ) if (list.size() > 0)
return ( list.size() == 1 ) ? list.getFirst() : list; return (list.size() == 1) ? list.getFirst() : list;
file = filePath.toFile(); file = filePath.toFile();
if ( file.exists() && file.isFile() ) if (file.exists() && file.isFile()) {
{ return createExternalFileStorage(filePath);
return createExternalFileStorage( filePath );
} }
return null; return null;
} }
private Object findFileByRelativePath( String fileName ) @SuppressWarnings("unchecked")
{ private Object findFileByRelativePath(String fileName) {
File[] folders = getFolders(); File[] folders = getFolders();
if ( folders != null ) if (folders != null) {
{ LinkedList<Object> list = new LinkedList<Object>();
LinkedList list = new LinkedList(); for (int i = 0; i < folders.length; ++i) {
for ( int i = 0; i < folders.length; ++i ) Object result = findFileByRelativePath(folders[i], fileName);
{ if (result instanceof List) {
Object result = findFileByRelativePath( folders[i], fileName ); if (searchForDuplicateFiles()) {
if ( result instanceof List ) list.addAll((List<Object>) result);
{ } else {
if ( searchForDuplicateFiles() )
list.addAll( (List)result );
else
return list.getFirst(); return list.getFirst();
} }
else if ( result != null ) } else if (result != null) {
{ if (searchForDuplicateFiles()) {
if ( searchForDuplicateFiles() ) list.add(result);
list.add( result ); } else {
else
return result; return result;
}
} }
} }
if ( list.size() > 0 ) if (list.size() > 0)
return ( list.size() == 1 ) ? list.getFirst() : list; return (list.size() == 1) ? list.getFirst() : list;
} }
return null; return null;
} }
private Object findFileByRelativePath( File folder, String fileName ) private Object findFileByRelativePath(File folder, String fileName) {
{ IPath path = new Path(folder.getAbsolutePath());
IPath path = new Path( folder.getAbsolutePath() ); path = path.append(fileName);
path = path.append( fileName );
File file = path.toFile(); File file = path.toFile();
if ( file.exists() && file.isFile() ) if (file.exists() && file.isFile()) {
{ path = new Path(file.getAbsolutePath());
path = new Path( file.getAbsolutePath() ); IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path ); LinkedList<IFile> list = new LinkedList<IFile>();
LinkedList list = new LinkedList(); for (int j = 0; j < wsFiles.length; ++j)
for ( int j = 0; j < wsFiles.length; ++j ) if (wsFiles[j].exists()) {
if ( wsFiles[j].exists() ) if (!searchForDuplicateFiles())
{
if ( !searchForDuplicateFiles() )
return wsFiles[j]; return wsFiles[j];
list.add( wsFiles[j] ); list.add(wsFiles[j]);
} }
if ( list.size() > 0 ) if (list.size() > 0)
return ( list.size() == 1 ) ? list.getFirst() : list; return (list.size() == 1) ? list.getFirst() : list;
return createExternalFileStorage( path ); return createExternalFileStorage(path);
} }
return null; return null;
} }
private IStorage createExternalFileStorage( IPath path ) private IStorage createExternalFileStorage(IPath path) {
{ return new FileStorage(path);
return new FileStorage( path );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getMemento() * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getMemento()
*/ */
public String getMemento() throws CoreException public String getMemento() throws CoreException {
{
Document document = null; Document document = null;
Throwable ex = null; Throwable ex = null;
try try {
{
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element node = document.createElement( ELEMENT_NAME ); Element node = document.createElement(ELEMENT_NAME);
document.appendChild( node ); document.appendChild(node);
node.setAttribute( ATTR_DIRECTORY, getDirectory().toOSString() ); node.setAttribute(ATTR_DIRECTORY, getDirectory().toOSString());
if ( getAssociation() != null ) if (getAssociation() != null)
node.setAttribute( ATTR_ASSOCIATION, getAssociation().toOSString() ); node.setAttribute(ATTR_ASSOCIATION, getAssociation().toOSString());
node.setAttribute( ATTR_SEARCH_SUBFOLDERS, Boolean.valueOf( searchSubfolders() ).toString() ); node.setAttribute(ATTR_SEARCH_SUBFOLDERS, Boolean.valueOf(searchSubfolders()).toString());
return CDebugUtils.serializeDocument( document ); return CDebugUtils.serializeDocument(document);
} } catch (ParserConfigurationException e) {
catch( ParserConfigurationException e )
{
ex = e; ex = e;
} } catch (IOException e) {
catch( IOException e ) ex = e;
{ } catch (TransformerException e) {
ex = e; ex = e;
} }
catch( TransformerException e ) abort(NLS.bind(InternalSourceLookupMessages.CDirectorySourceLocation_0, getDirectory().toOSString()), ex);
{
ex = e;
}
abort( MessageFormat.format( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.0" ), new String[] { getDirectory().toOSString() } ), ex ); //$NON-NLS-1$
// execution will not reach here // execution will not reach here
return null; return null;
} }
@ -332,204 +296,165 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#initializeFrom(java.lang.String) * @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; Exception ex = null;
try try {
{
Element root = null; Element root = null;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento ); StringReader reader = new StringReader(memento);
InputSource source = new InputSource( reader ); InputSource source = new InputSource(reader);
root = parser.parse( source ).getDocumentElement(); root = parser.parse(source).getDocumentElement();
String dir = root.getAttribute( ATTR_DIRECTORY ); String dir = root.getAttribute(ATTR_DIRECTORY);
if ( isEmpty( dir ) ) if (isEmpty(dir)) {
{ abort(InternalSourceLookupMessages.CDirectorySourceLocation_1, null);
abort( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.1" ), null ); //$NON-NLS-1$ } else {
} IPath path = new Path(dir);
else if (path.isValidPath(dir) && path.toFile().isDirectory() && path.toFile().exists()) {
{ setDirectory(path);
IPath path = new Path( dir ); } else {
if ( path.isValidPath( dir ) && path.toFile().isDirectory() && path.toFile().exists() ) abort(NLS.bind(InternalSourceLookupMessages.CDirectorySourceLocation_2, dir), null);
{
setDirectory( path );
}
else
{
abort( MessageFormat.format( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.2" ), new String[] { dir } ), null ); //$NON-NLS-1$
} }
} }
dir = root.getAttribute( ATTR_ASSOCIATION ); dir = root.getAttribute(ATTR_ASSOCIATION);
if ( isEmpty( dir ) ) if (isEmpty(dir)) {
{ setAssociation(null);
setAssociation( null ); } else {
} IPath path = new Path(dir);
else if (path.isValidPath(dir)) {
{ setAssociation(path);
IPath path = new Path( dir ); } else {
if ( path.isValidPath( dir ) ) setAssociation(null);
{
setAssociation( path );
}
else
{
setAssociation( null );
} }
} }
setSearchSubfolders( Boolean.valueOf( root.getAttribute( ATTR_SEARCH_SUBFOLDERS ) ).booleanValue() ); setSearchSubfolders(Boolean.valueOf(root.getAttribute(ATTR_SEARCH_SUBFOLDERS)).booleanValue());
return; return;
} } catch (ParserConfigurationException e) {
catch( ParserConfigurationException e ) ex = e;
{ } catch (SAXException e) {
ex = e;
} catch (IOException e) {
ex = e; ex = e;
} }
catch( SAXException e ) abort(InternalSourceLookupMessages.CDirectorySourceLocation_3, ex);
{
ex = e;
}
catch( IOException e )
{
ex = e;
}
abort( InternalSourceLookupMessages.getString( "CDirectorySourceLocation.3" ), ex ); //$NON-NLS-1$
} }
/** /**
* Throws an internal error exception * Throws an internal error exception
*/ */
private void abort( String message, Throwable e ) throws CoreException private void abort(String message, Throwable e) throws CoreException {
{ IStatus s = new Status(IStatus.ERROR,
IStatus s = new Status( IStatus.ERROR,
CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.getUniqueIdentifier(),
CDebugCorePlugin.INTERNAL_ERROR, CDebugCorePlugin.INTERNAL_ERROR,
message, message,
e ); e);
throw new CoreException( s ); throw new CoreException(s);
} }
private boolean isEmpty( String string ) private boolean isEmpty(String string) {
{
return string == null || string.length() == 0; return string == null || string.length() == 0;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
public boolean equals( Object obj ) public boolean equals(Object obj) {
{ if (obj instanceof IDirectorySourceLocation) {
if ( obj instanceof IDirectorySourceLocation )
{
IPath dir = ((IDirectorySourceLocation)obj).getDirectory(); IPath dir = ((IDirectorySourceLocation)obj).getDirectory();
IPath association = ((IDirectorySourceLocation)obj).getAssociation(); IPath association = ((IDirectorySourceLocation)obj).getAssociation();
if ( dir == null ) if (dir == null)
return false; return false;
boolean result = dir.equals( getDirectory() ); boolean result = dir.equals(getDirectory());
if ( result ) if (result) {
{ if (association == null && getAssociation() == null)
if ( association == null && getAssociation() == null )
return true; return true;
if ( association != null ) if (association != null)
return association.equals( getAssociation() ); return association.equals(getAssociation());
} }
} }
return false; return false;
} }
private boolean isPrefix( IPath prefix, IPath path ) private boolean isPrefix(IPath prefix, IPath path) {
{
int segCount = prefix.segmentCount(); int segCount = prefix.segmentCount();
if ( segCount >= path.segmentCount() ) if (segCount >= path.segmentCount())
return false; return false;
String prefixString = prefix.toOSString(); String prefixString = prefix.toOSString();
String pathString = path.removeLastSegments( path.segmentCount() - segCount ).toOSString(); String pathString = path.removeLastSegments(path.segmentCount() - segCount).toOSString();
return prefixString.equalsIgnoreCase( pathString ); return prefixString.equalsIgnoreCase(pathString);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean)
*/ */
public void setSearchForDuplicateFiles( boolean search ) public void setSearchForDuplicateFiles(boolean search) {
{
fSearchForDuplicateFiles = search; fSearchForDuplicateFiles = search;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles() * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles()
*/ */
public boolean searchForDuplicateFiles() public boolean searchForDuplicateFiles() {
{
return fSearchForDuplicateFiles; return fSearchForDuplicateFiles;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation#searchSubfolders() * @see org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation#searchSubfolders()
*/ */
public boolean searchSubfolders() public boolean searchSubfolders() {
{
return fSearchSubfolders; return fSearchSubfolders;
} }
public void setSearchSubfolders( boolean search ) public void setSearchSubfolders(boolean search) {
{
resetFolders(); resetFolders();
fSearchSubfolders = search; fSearchSubfolders = search;
} }
protected File[] getFolders() protected File[] getFolders() {
{ if (fFolders == null)
if ( fFolders == null )
initializeFolders(); initializeFolders();
return fFolders; return fFolders;
} }
protected void resetFolders() protected void resetFolders() {
{
fFolders = null; fFolders = null;
} }
private void initializeFolders() private void initializeFolders() {
{ if (getDirectory() != null) {
if ( getDirectory() != null ) ArrayList<File> list = new ArrayList<File>();
{
ArrayList list = new ArrayList();
File root = getDirectory().toFile(); File root = getDirectory().toFile();
list.add( root ); list.add(root);
if ( searchSubfolders() ) if (searchSubfolders())
list.addAll( getFileFolders( root ) ); list.addAll(getFileFolders(root));
fFolders = (File[])list.toArray( new File[list.size()] ); fFolders = list.toArray(new File[list.size()]);
} }
} }
private List getFileFolders( File file ) private List<File> getFileFolders(File file) {
{ ArrayList<File> list = new ArrayList<File>();
ArrayList list = new ArrayList();
File[] folders = file.listFiles( File[] folders = file.listFiles(
new FileFilter() new FileFilter() {
{ public boolean accept(File pathname) {
public boolean accept( File pathname )
{
return pathname.isDirectory(); return pathname.isDirectory();
} }
} ); });
list.addAll( Arrays.asList( folders ) ); list.addAll(Arrays.asList(folders));
for ( int i = 0; i < folders.length; ++i ) for (int i = 0; i < folders.length; ++i)
list.addAll( getFileFolders( folders[i] ) ); list.addAll(getFileFolders(folders[i]));
return list; return list;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
public String toString() public String toString() {
{ return (getDirectory() != null) ? getDirectory().toOSString() : ""; //$NON-NLS-1$
return ( getDirectory() != null ) ? getDirectory().toOSString() : ""; //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#dispose() * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#dispose()
*/ */
public void dispose() public void dispose() {
{
} }
} }

View file

@ -49,8 +49,7 @@ import org.xml.sax.SAXException;
* *
* @since Sep 23, 2002 * @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 ELEMENT_NAME = "cProjectSourceLocation"; //$NON-NLS-1$
private static final String ATTR_PROJECT = "project"; //$NON-NLS-1$ private static final String ATTR_PROJECT = "project"; //$NON-NLS-1$
private static final String ATTR_GENERIC = "generic"; //$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 * The project associated with this source location
*/ */
private IProject fProject; private IProject fProject;
private IResource[] fFolders; private IResource[] fFolders;
private HashMap fCache = new HashMap( 20 ); private HashMap fCache = new HashMap( 20 );
private HashSet fNotFoundCache = new HashSet( 20 ); private HashSet fNotFoundCache = new HashSet( 20 );
private boolean fGenerated = true; private boolean fGenerated = true;
private boolean fSearchForDuplicateFiles = false; private boolean fSearchForDuplicateFiles = false;
/** public CProjectSourceLocation() {
* Constructor for CProjectSourceLocation.
*/
public CProjectSourceLocation()
{
} }
/** public CProjectSourceLocation( IProject project ) {
* Constructor for CProjectSourceLocation.
*/
public CProjectSourceLocation( IProject project )
{
setProject( project ); setProject( project );
fGenerated = true; fGenerated = true;
} }
/** public CProjectSourceLocation( IProject project, boolean generated ) {
* Constructor for CProjectSourceLocation.
*/
public CProjectSourceLocation( IProject project, boolean generated )
{
setProject( project ); setProject( project );
fGenerated = generated; fGenerated = generated;
} }
@ -101,19 +83,15 @@ public class CProjectSourceLocation implements IProjectSourceLocation
public Object findSourceElement( String name ) throws CoreException public Object findSourceElement( String name ) throws CoreException
{ {
Object result = null; Object result = null;
if ( !isEmpty( name ) && getProject() != null && !notFoundCacheLookup( name ) ) if ( !isEmpty( name ) && getProject() != null && !notFoundCacheLookup( name ) ) {
{
result = cacheLookup( name ); result = cacheLookup( name );
if ( result == null ) if ( result == null ) {
{
result = doFindSourceElement( name ); result = doFindSourceElement( name );
if ( result != null ) if ( result != null ) {
{
cacheSourceElement( name, result ); cacheSourceElement( name, result );
} }
} }
if ( result == null ) if ( result == null ) {
{
cacheNotFound( name ); cacheNotFound( name );
} }
} }
@ -123,8 +101,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
*/ */
public Object getAdapter( Class adapter ) public Object getAdapter( Class adapter ) {
{
if ( adapter.equals( ICSourceLocation.class ) ) if ( adapter.equals( ICSourceLocation.class ) )
return this; return this;
if ( adapter.equals( CProjectSourceLocation.class ) ) if ( adapter.equals( CProjectSourceLocation.class ) )
@ -139,8 +116,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
* *
* @param project the project * @param project the project
*/ */
private void setProject( IProject project ) private void setProject( IProject project ) {
{
fProject = project; fProject = project;
} }
@ -149,27 +125,22 @@ public class CProjectSourceLocation implements IProjectSourceLocation
* *
* @return project * @return project
*/ */
public IProject getProject() public IProject getProject() {
{
return fProject; return fProject;
} }
private Object doFindSourceElement( String name ) private Object doFindSourceElement( String name ) {
{
File file = new File( name ); File file = new File( name );
return ( file.isAbsolute() ) ? findFileByAbsolutePath( file ) : findFileByRelativePath( name ); return ( file.isAbsolute() ) ? findFileByAbsolutePath( file ) : findFileByRelativePath( name );
} }
private Object findFileByAbsolutePath( File file ) private Object findFileByAbsolutePath( File file ) {
{
LinkedList list = new LinkedList(); LinkedList list = new LinkedList();
if ( file.exists() ) if ( file.exists() ) {
{
IPath path = new Path( file.getAbsolutePath() ); IPath path = new Path( file.getAbsolutePath() );
IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path ); IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path );
for ( int i = 0; i < wsFiles.length; ++i ) 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() ) if ( !searchForDuplicateFiles() )
return wsFiles[i]; return wsFiles[i];
list.add( 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; return ( list.size() > 0 ) ? ( ( list.size() == 1 ) ? list.getFirst() : list ) : null;
} }
private Object findFileByRelativePath( String fileName ) private Object findFileByRelativePath( String fileName ) {
{
IResource[] folders = getFolders(); IResource[] folders = getFolders();
LinkedList list = new LinkedList(); 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() ) if ( list.size() > 0 && !searchForDuplicateFiles() )
break; break;
IPath path = folders[i].getLocation(); IPath path = folders[i].getLocation();
if ( path != null ) { if ( path != null ) {
path = path.append( fileName ); path = path.append( fileName );
File file = new File( path.toOSString() ); File file = new File( path.toOSString() );
if ( file.exists() ) if ( file.exists() ) {
{
IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path ); IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path );
for ( int j = 0; j < wsFiles.length; ++j ) for ( int j = 0; j < wsFiles.length; ++j )
if ( wsFiles[j].exists() ) if ( wsFiles[j].exists() ) {
{
if ( !searchForDuplicateFiles() ) if ( !searchForDuplicateFiles() )
return wsFiles[j]; return wsFiles[j];
list.add( 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; 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 ); return fCache.get( name );
} }
private boolean notFoundCacheLookup( String name ) private boolean notFoundCacheLookup( String name ) {
{
return fNotFoundCache.contains( name ); return fNotFoundCache.contains( name );
} }
private void cacheSourceElement( String name, Object element ) private void cacheSourceElement( String name, Object element ) {
{
fCache.put( name, element ); fCache.put( name, element );
} }
private void cacheNotFound( String name ) private void cacheNotFound( String name ) {
{
fNotFoundCache.add( name ); fNotFoundCache.add( name );
} }
public void dispose() public void dispose() {
{
fCache.clear(); fCache.clear();
fNotFoundCache.clear(); fNotFoundCache.clear();
} }
@ -247,20 +209,15 @@ public class CProjectSourceLocation implements IProjectSourceLocation
node.setAttribute( ATTR_PROJECT, getProject().getName() ); node.setAttribute( ATTR_PROJECT, getProject().getName() );
node.setAttribute( ATTR_GENERIC, Boolean.valueOf( isGeneric() ).toString() ); node.setAttribute( ATTR_GENERIC, Boolean.valueOf( isGeneric() ).toString() );
return CDebugUtils.serializeDocument( document ); return CDebugUtils.serializeDocument( document );
} } catch( ParserConfigurationException e )
catch( ParserConfigurationException e )
{ {
ex = e; ex = e;
} } catch( IOException e ) {
catch( IOException e ) ex = e;
{ } catch( TransformerException e ) {
ex = e; ex = e;
} }
catch( TransformerException e ) abort( MessageFormat.format( InternalSourceLookupMessages.CProjectSourceLocation_0, new String[] { getProject().getName() } ), ex ); //$NON-NLS-1$
{
ex = e;
}
abort( MessageFormat.format( InternalSourceLookupMessages.getString( "CProjectSourceLocation.0" ), new String[] { getProject().getName() } ), ex ); //$NON-NLS-1$
// execution will not reach here // execution will not reach here
return null; return null;
} }
@ -280,9 +237,8 @@ public class CProjectSourceLocation implements IProjectSourceLocation
root = parser.parse( source ).getDocumentElement(); root = parser.parse( source ).getDocumentElement();
String name = root.getAttribute( ATTR_PROJECT ); String name = root.getAttribute( ATTR_PROJECT );
if ( isEmpty( name ) ) if ( isEmpty( name ) ) {
{ abort( InternalSourceLookupMessages.CProjectSourceLocation_1, null ); //$NON-NLS-1$
abort( InternalSourceLookupMessages.getString( "CProjectSourceLocation.1" ), null ); //$NON-NLS-1$
} }
else else
{ {
@ -294,20 +250,14 @@ public class CProjectSourceLocation implements IProjectSourceLocation
isGeneric = Boolean.FALSE.toString(); isGeneric = Boolean.FALSE.toString();
setGenerated( isGeneric.equals( Boolean.TRUE.toString() ) ); setGenerated( isGeneric.equals( Boolean.TRUE.toString() ) );
return; return;
} } catch( ParserConfigurationException e ) {
catch( ParserConfigurationException e ) ex = e;
{ } catch( SAXException e ) {
ex = e;
} catch( IOException e ) {
ex = e; ex = e;
} }
catch( SAXException e ) abort( InternalSourceLookupMessages.CProjectSourceLocation_2, ex ); //$NON-NLS-1$
{
ex = e;
}
catch( IOException e )
{
ex = e;
}
abort( InternalSourceLookupMessages.getString( "CProjectSourceLocation.2" ), ex ); //$NON-NLS-1$
} }
/** /**
@ -323,49 +273,40 @@ public class CProjectSourceLocation implements IProjectSourceLocation
throw new CoreException( s ); throw new CoreException( s );
} }
private boolean isEmpty( String string ) private boolean isEmpty( String string ) {
{
return string == null || string.length() == 0; return string == null || string.length() == 0;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation#isGenerated() * @see org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation#isGenerated()
*/ */
public boolean isGeneric() public boolean isGeneric() {
{
return fGenerated; return fGenerated;
} }
public void setGenerated( boolean b ) public void setGenerated( boolean b ) {
{
fGenerated = b; fGenerated = b;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
public boolean equals( Object obj ) public boolean equals( Object obj ) {
{
if ( obj instanceof IProjectSourceLocation && getProject() != null ) if ( obj instanceof IProjectSourceLocation && getProject() != null )
return getProject().equals( ((IProjectSourceLocation)obj).getProject() ); return getProject().equals( ((IProjectSourceLocation)obj).getProject() );
return false; return false;
} }
private void initializeFolders() private void initializeFolders() {
{
final LinkedList list = new LinkedList(); final LinkedList list = new LinkedList();
if ( getProject() != null && getProject().exists() ) if ( getProject() != null && getProject().exists() ) {
{
list.add( getProject() ); list.add( getProject() );
try try {
{
getProject().accept( getProject().accept(
new IResourceProxyVisitor() new IResourceProxyVisitor() {
{
public boolean visit( IResourceProxy proxy ) throws CoreException public boolean visit( IResourceProxy proxy ) throws CoreException
{ {
switch( proxy.getType() ) switch( proxy.getType() ) {
{
case IResource.FILE: case IResource.FILE:
return false; return false;
case IResource.FOLDER: case IResource.FOLDER:
@ -377,13 +318,10 @@ public class CProjectSourceLocation implements IProjectSourceLocation
}, },
IResource.NONE ); IResource.NONE );
} } catch( CoreException e ) {
catch( CoreException e )
{
} }
} }
synchronized( this ) synchronized( this ) {
{
if ( fFolders == null ) if ( fFolders == null )
{ {
fFolders = (IResource[])list.toArray( new IResource[list.size()] ); 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 ) if ( fFolders == null )
initializeFolders(); initializeFolders();
return fFolders; return fFolders;
@ -401,23 +338,20 @@ public class CProjectSourceLocation implements IProjectSourceLocation
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles() * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles()
*/ */
public boolean searchForDuplicateFiles() public boolean searchForDuplicateFiles() {
{
return fSearchForDuplicateFiles; return fSearchForDuplicateFiles;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean)
*/ */
public void setSearchForDuplicateFiles( boolean search ) public void setSearchForDuplicateFiles( boolean search ) {
{
fCache.clear(); fCache.clear();
fNotFoundCache.clear(); fNotFoundCache.clear();
fSearchForDuplicateFiles = search; fSearchForDuplicateFiles = search;
} }
public String toString() public String toString() {
{
return ( getProject() != null ) ? fProject.toString() : ""; //$NON-NLS-1$ return ( getProject() != null ) ? fProject.toString() : ""; //$NON-NLS-1$
} }
} }

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
@ -56,27 +56,19 @@ import org.xml.sax.SAXException;
* Default source locator. * Default source locator.
*/ */
public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator, IResourceChangeListener { public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator, IResourceChangeListener {
private static final String SOURCE_LOCATOR_NAME = "cSourceLocator"; //$NON-NLS-1$ 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 DISABLED_GENERIC_PROJECT_NAME = "disabledGenericProject"; //$NON-NLS-1$
private static final String ADDITIONAL_SOURCE_LOCATION_NAME = "additionalSourceLocation"; //$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 SOURCE_LOCATION_NAME = "cSourceLocation"; //$NON-NLS-1$
private static final String ATTR_CLASS = "class"; //$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_MEMENTO = "memento"; //$NON-NLS-1$
private static final String ATTR_PROJECT_NAME = "projectName"; //$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$ private static final String ATTR_DUPLICATE_FILES = "duplicateFiles"; //$NON-NLS-1$
/** /**
* The project associated with this locator. * The project associated with this locator.
*/ */
private IProject fProject = null; private IProject fProject;
/** /**
* The array of source locations associated with this locator. * 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. * The array of projects referenced by main project.
*/ */
private List fReferencedProjects = new ArrayList( 10 ); private List<IProject> fReferencedProjects = new ArrayList<IProject>(10);
/** /**
* The flag specifies whether to search for all source elements, or just the first match. * 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. * Constructor for CSourceLocator.
*/ */
public CSourceLocator( IProject project ) { public CSourceLocator(IProject project) {
setProject( project ); setProject(project);
setReferencedProjects(); setReferencedProjects();
setSourceLocations( getDefaultSourceLocations() ); setSourceLocations(getDefaultSourceLocations());
} }
/* /*
@ -107,8 +99,8 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
* *
* @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame) * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
*/ */
public Object getSourceElement( IStackFrame stackFrame ) { public Object getSourceElement(IStackFrame stackFrame) {
return getInput( stackFrame ); return getInput(stackFrame);
} }
/* /*
@ -116,31 +108,30 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
* *
* @see org.eclipse.cdt.debug.core.ICSourceLocator#getLineNumber(IStackFrameInfo) * @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; return (frame instanceof ICStackFrame) ? ((ICStackFrame)frame).getFrameLineNumber() : 0;
} }
protected Object getInput( IStackFrame f ) { protected Object getInput(IStackFrame f) {
if ( f instanceof ICStackFrame ) { if (f instanceof ICStackFrame) {
ICStackFrame frame = (ICStackFrame)f; ICStackFrame frame = (ICStackFrame)f;
LinkedList list = new LinkedList(); LinkedList<Object> list = new LinkedList<Object>();
Object result = null; Object result = null;
String fileName = frame.getFile(); String fileName = frame.getFile();
if ( fileName != null && fileName.length() > 0 ) { if (fileName != null && fileName.length() > 0) {
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
for( int i = 0; i < locations.length; ++i ) { for (int i = 0; i < locations.length; ++i) {
try { try {
result = locations[i].findSourceElement( fileName ); result = locations[i].findSourceElement(fileName);
} } catch (CoreException e) {
catch( CoreException e ) {
// do nothing // do nothing
} }
if ( result != null ) { if (result != null) {
if ( result instanceof List ) if (result instanceof List)
list.addAll( (List)result ); list.addAll((List<?>) result);
else else
list.add( result ); list.add(result);
if ( !searchForDuplicateFiles() ) if (!searchForDuplicateFiles())
break; break;
} }
} }
@ -155,23 +146,22 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
* *
* @see org.eclipse.cdt.debug.core.ICSourceLocator#contains(IResource) * @see org.eclipse.cdt.debug.core.ICSourceLocator#contains(IResource)
*/ */
public boolean contains( IResource resource ) { public boolean contains(IResource resource) {
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
for( int i = 0; i < locations.length; ++i ) { for (int i = 0; i < locations.length; ++i) {
if ( resource instanceof IProject ) { if (resource instanceof IProject) {
if ( locations[i] instanceof CProjectSourceLocation && ((CProjectSourceLocation)locations[i]).getProject().equals( resource ) ) { if (locations[i] instanceof CProjectSourceLocation && ((CProjectSourceLocation)locations[i]).getProject().equals(resource)) {
return true; return true;
} }
} }
if ( resource instanceof IFile ) { if (resource instanceof IFile) {
try { try {
Object result = locations[i].findSourceElement( resource.getLocation().toOSString() ); Object result = locations[i].findSourceElement(resource.getLocation().toOSString());
if ( result instanceof IFile && ((IFile)result).equals( resource ) ) if (result instanceof IFile && ((IFile) result).equals(resource))
return true; return true;
if ( result instanceof List && ((List)result).contains( resource ) ) if (result instanceof List && ((List<?>) result).contains(resource))
return true; return true;
} } catch (CoreException e) {
catch( CoreException e ) {
} }
} }
} }
@ -189,10 +179,9 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#setSourceLocations(ICSourceLocation[]) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#setSourceLocations(ICSourceLocation[])
*/ */
public void setSourceLocations( ICSourceLocation[] locations ) { public void setSourceLocations(ICSourceLocation[] locations) {
fSourceLocations = locations; fSourceLocations = locations;
} }
@ -205,37 +194,36 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
* @return a collection of source locations for all required projects * @return a collection of source locations for all required projects
* @exception CoreException * @exception CoreException
*/ */
public static ICSourceLocation[] getDefaultSourceLocations( IProject project ) { public static ICSourceLocation[] getDefaultSourceLocations(IProject project) {
ArrayList list = new ArrayList(); ArrayList<IProjectSourceLocation> list = new ArrayList<IProjectSourceLocation>();
if ( project != null && project.exists() ) { if (project != null && project.exists()) {
list.add( SourceLookupFactory.createProjectSourceLocation( project ) ); list.add(SourceLookupFactory.createProjectSourceLocation(project));
addReferencedSourceLocations( list, 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 ) { private static void addReferencedSourceLocations(List<IProjectSourceLocation> list, IProject project) {
if ( project != null ) { if (project != null) {
try { try {
IProject[] projects = project.getReferencedProjects(); IProject[] projects = project.getReferencedProjects();
for( int i = 0; i < projects.length; i++ ) { for (int i = 0; i < projects.length; i++) {
if ( projects[i].exists() && !containsProject( list, projects[i] ) ) { if (projects[i].exists() && !containsProject(list, projects[i])) {
list.add( SourceLookupFactory.createProjectSourceLocation( projects[i] ) ); list.add(SourceLookupFactory.createProjectSourceLocation(projects[i]));
addReferencedSourceLocations( list, projects[i] ); addReferencedSourceLocations(list, projects[i]);
} }
} }
} } catch (CoreException e) {
catch( CoreException e ) {
// do nothing // do nothing
} }
} }
} }
private static boolean containsProject( List list, IProject project ) { private static boolean containsProject(List<IProjectSourceLocation> list, IProject project) {
Iterator it = list.iterator(); Iterator<IProjectSourceLocation> it = list.iterator();
while( it.hasNext() ) { while (it.hasNext()) {
CProjectSourceLocation location = (CProjectSourceLocation)it.next(); CProjectSourceLocation location = (CProjectSourceLocation)it.next();
if ( project.equals( location.getProject() ) ) if (project.equals(location.getProject()))
return true; return true;
} }
return false; return false;
@ -246,18 +234,17 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
* *
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#findSourceElement(String) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#findSourceElement(String)
*/ */
public Object findSourceElement( String fileName ) { public Object findSourceElement(String fileName) {
Object result = null; Object result = null;
if ( fileName != null && fileName.length() > 0 ) { if (fileName != null && fileName.length() > 0) {
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
for( int i = 0; i < locations.length; ++i ) { for (int i = 0; i < locations.length; ++i) {
try { try {
result = locations[i].findSourceElement( fileName ); result = locations[i].findSourceElement(fileName);
} } catch (CoreException e) {
catch( CoreException e ) {
// do nothing // do nothing
} }
if ( result != null ) if (result != null)
break; break;
} }
} }
@ -274,24 +261,21 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
Throwable ex = null; Throwable ex = null;
try { try {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element node = document.createElement( SOURCE_LOCATOR_NAME ); Element node = document.createElement(SOURCE_LOCATOR_NAME);
document.appendChild( node ); document.appendChild(node);
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
saveDisabledGenericSourceLocations( locations, document, node ); saveDisabledGenericSourceLocations(locations, document, node);
saveAdditionalSourceLocations( locations, document, node ); saveAdditionalSourceLocations(locations, document, node);
node.setAttribute( ATTR_DUPLICATE_FILES, Boolean.valueOf( searchForDuplicateFiles() ).toString() ); node.setAttribute(ATTR_DUPLICATE_FILES, Boolean.valueOf(searchForDuplicateFiles()).toString());
return CDebugUtils.serializeDocument( document ); return CDebugUtils.serializeDocument(document);
} } catch (ParserConfigurationException e) {
catch( ParserConfigurationException e ) { ex = e;
} catch (IOException e) {
ex = e;
} catch (TransformerException e) {
ex = e; ex = e;
} }
catch( IOException e ) { abort(InternalSourceLookupMessages.CSourceLocator_0, ex);
ex = e;
}
catch( TransformerException e ) {
ex = e;
}
abort( InternalSourceLookupMessages.getString( "CSourceLocator.0" ), ex ); //$NON-NLS-1$
// execution will not reach here // execution will not reach here
return null; 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) * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration)
*/ */
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException { public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
setSourceLocations( getDefaultSourceLocations() ); setSourceLocations(getDefaultSourceLocations());
} }
/* /*
@ -310,160 +294,151 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
* *
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String) * @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; Exception ex = null;
try { try {
Element root = null; Element root = null;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento ); StringReader reader = new StringReader(memento);
InputSource source = new InputSource( reader ); InputSource source = new InputSource(reader);
root = parser.parse( source ).getDocumentElement(); root = parser.parse(source).getDocumentElement();
if ( !root.getNodeName().equalsIgnoreCase( SOURCE_LOCATOR_NAME ) ) { if (!root.getNodeName().equalsIgnoreCase(SOURCE_LOCATOR_NAME)) {
abort( InternalSourceLookupMessages.getString( "CSourceLocator.1" ) , null ); //$NON-NLS-1$ abort(InternalSourceLookupMessages.CSourceLocator_1 , null);
} }
List sourceLocations = new ArrayList(); List<ICSourceLocation> sourceLocations = new ArrayList<ICSourceLocation>();
// Add locations based on referenced projects // Add locations based on referenced projects
IProject project = getProject(); IProject project = getProject();
if ( project != null && project.exists() && project.isOpen() ) if (project != null && project.exists() && project.isOpen())
sourceLocations.addAll( Arrays.asList( getDefaultSourceLocations() ) ); sourceLocations.addAll(Arrays.asList(getDefaultSourceLocations()));
removeDisabledLocations( root, sourceLocations ); removeDisabledLocations(root, sourceLocations);
addAdditionalLocations( root, sourceLocations ); addAdditionalLocations(root, sourceLocations);
// To support old launch configuration // To support old launch configuration
addOldLocations( root, sourceLocations ); addOldLocations(root, sourceLocations);
setSourceLocations( (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ) ); setSourceLocations(sourceLocations.toArray(new ICSourceLocation[sourceLocations.size()]));
setSearchForDuplicateFiles( Boolean.valueOf( root.getAttribute( ATTR_DUPLICATE_FILES ) ).booleanValue() ); setSearchForDuplicateFiles(Boolean.valueOf(root.getAttribute(ATTR_DUPLICATE_FILES)).booleanValue());
return; return;
} } catch (ParserConfigurationException e) {
catch( ParserConfigurationException e ) { ex = e;
} catch (SAXException e) {
ex = e;
} catch (IOException e) {
ex = e; ex = e;
} }
catch( SAXException e ) { abort(InternalSourceLookupMessages.CSourceLocator_2, ex);
ex = e;
}
catch( IOException e ) {
ex = e;
}
abort( InternalSourceLookupMessages.getString( "CSourceLocator.2" ), ex ); //$NON-NLS-1$
} }
private void removeDisabledLocations( Element root, List sourceLocations ) { private void removeDisabledLocations(Element root, List<ICSourceLocation> sourceLocations) {
NodeList list = root.getChildNodes(); NodeList list = root.getChildNodes();
int length = list.getLength(); int length = list.getLength();
HashSet disabledProjects = new HashSet( length ); HashSet<String> disabledProjects = new HashSet<String>(length);
for( int i = 0; i < length; ++i ) { for (int i = 0; i < length; ++i) {
Node node = list.item( i ); Node node = list.item(i);
short type = node.getNodeType(); short type = node.getNodeType();
if ( type == Node.ELEMENT_NODE ) { if (type == Node.ELEMENT_NODE) {
Element entry = (Element)node; Element entry = (Element)node;
if ( entry.getNodeName().equalsIgnoreCase( DISABLED_GENERIC_PROJECT_NAME ) ) { if (entry.getNodeName().equalsIgnoreCase(DISABLED_GENERIC_PROJECT_NAME)) {
String projectName = entry.getAttribute( ATTR_PROJECT_NAME ); String projectName = entry.getAttribute(ATTR_PROJECT_NAME);
if ( isEmpty( projectName ) ) { if (isEmpty(projectName)) {
CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." ); //$NON-NLS-1$ 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(); Iterator<ICSourceLocation> it = sourceLocations.iterator();
while( it.hasNext() ) { while (it.hasNext()) {
ICSourceLocation location = (ICSourceLocation)it.next(); ICSourceLocation location = it.next();
if ( location instanceof IProjectSourceLocation && disabledProjects.contains( ((IProjectSourceLocation)location).getProject().getName() ) ) if (location instanceof IProjectSourceLocation && disabledProjects.contains(((IProjectSourceLocation)location).getProject().getName()))
it.remove(); it.remove();
} }
} }
private void addAdditionalLocations( Element root, List sourceLocations ) throws CoreException { private void addAdditionalLocations(Element root, List<ICSourceLocation> sourceLocations) throws CoreException {
Bundle bundle = CDebugCorePlugin.getDefault().getBundle(); 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(); NodeList list = root.getChildNodes();
int length = list.getLength(); int length = list.getLength();
for( int i = 0; i < length; ++i ) { for (int i = 0; i < length; ++i) {
Node node = list.item( i ); Node node = list.item(i);
short type = node.getNodeType(); short type = node.getNodeType();
if ( type == Node.ELEMENT_NODE ) { if (type == Node.ELEMENT_NODE) {
Element entry = (Element)node; Element entry = (Element)node;
if ( entry.getNodeName().equalsIgnoreCase( ADDITIONAL_SOURCE_LOCATION_NAME ) ) { if (entry.getNodeName().equalsIgnoreCase(ADDITIONAL_SOURCE_LOCATION_NAME)) {
String className = entry.getAttribute( ATTR_CLASS ); String className = entry.getAttribute(ATTR_CLASS);
String data = entry.getAttribute( ATTR_MEMENTO ); String data = entry.getAttribute(ATTR_MEMENTO);
if ( isEmpty( className ) ) { if (isEmpty(className)) {
CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." ); //$NON-NLS-1$ CDebugCorePlugin.log("Unable to restore C/C++ source locator - invalid format."); //$NON-NLS-1$
continue; continue;
} }
Class clazz = null; Class<?> clazz = null;
try { try {
clazz = bundle.loadClass( className ); clazz = bundle.loadClass(className);
} } catch (ClassNotFoundException e) {
catch( ClassNotFoundException e ) { CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", new String[]{ className })); //$NON-NLS-1$
CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[]{ className } ) ); //$NON-NLS-1$
continue; continue;
} }
ICSourceLocation location = null; ICSourceLocation location = null;
try { try {
location = (ICSourceLocation)clazz.newInstance(); location = (ICSourceLocation)clazz.newInstance();
} } catch (IllegalAccessException e) {
catch( IllegalAccessException e ) { CDebugCorePlugin.log("Unable to restore source location."); //$NON-NLS-1$
CDebugCorePlugin.log( "Unable to restore source location." ); //$NON-NLS-1$
continue; continue;
} } catch (InstantiationException e) {
catch( InstantiationException e ) { CDebugCorePlugin.log("Unable to restore source location."); //$NON-NLS-1$
CDebugCorePlugin.log( "Unable to restore source location." ); //$NON-NLS-1$
continue; continue;
} }
try { try {
location.initializeFrom( data ); location.initializeFrom(data);
sourceLocations.add( location ); sourceLocations.add(location);
} } catch (CoreException e) {
catch( CoreException e ) { status.addAll(e.getStatus());
status.addAll( e.getStatus() );
} }
} }
} }
} }
if ( status.getSeverity() > IStatus.OK ) if (status.getSeverity() > IStatus.OK)
throw new CoreException( status ); throw new CoreException(status);
} }
private void addOldLocations( Element root, List sourceLocations ) throws CoreException { private void addOldLocations(Element root, List<ICSourceLocation> sourceLocations) throws CoreException {
Bundle bundle = CDebugCorePlugin.getDefault().getBundle(); Bundle bundle = CDebugCorePlugin.getDefault().getBundle();
NodeList list = root.getChildNodes(); NodeList list = root.getChildNodes();
int length = list.getLength(); int length = list.getLength();
for( int i = 0; i < length; ++i ) { for (int i = 0; i < length; ++i) {
Node node = list.item( i ); Node node = list.item(i);
short type = node.getNodeType(); short type = node.getNodeType();
if ( type == Node.ELEMENT_NODE ) { if (type == Node.ELEMENT_NODE) {
Element entry = (Element)node; Element entry = (Element)node;
if ( entry.getNodeName().equalsIgnoreCase( SOURCE_LOCATION_NAME ) ) { if (entry.getNodeName().equalsIgnoreCase(SOURCE_LOCATION_NAME)) {
String className = entry.getAttribute( ATTR_CLASS ); String className = entry.getAttribute(ATTR_CLASS);
String data = entry.getAttribute( ATTR_MEMENTO ); String data = entry.getAttribute(ATTR_MEMENTO);
if ( isEmpty( className ) ) { if (isEmpty(className)) {
CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." ); //$NON-NLS-1$ CDebugCorePlugin.log("Unable to restore C/C++ source locator - invalid format."); //$NON-NLS-1$
continue; continue;
} }
Class clazz = null; Class<?> clazz = null;
try { try {
clazz = bundle.loadClass( className ); clazz = bundle.loadClass(className);
} } catch (ClassNotFoundException e) {
catch( ClassNotFoundException e ) { CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", new String[]{ className })); //$NON-NLS-1$
CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[]{ className } ) ); //$NON-NLS-1$
continue; continue;
} }
ICSourceLocation location = null; ICSourceLocation location = null;
try { try {
location = (ICSourceLocation)clazz.newInstance(); location = (ICSourceLocation)clazz.newInstance();
} } catch (IllegalAccessException e) {
catch( IllegalAccessException e ) { CDebugCorePlugin.log("Unable to restore source location."); //$NON-NLS-1$
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; continue;
} }
catch( InstantiationException e ) { location.initializeFrom(data);
CDebugCorePlugin.log( "Unable to restore source location." ); //$NON-NLS-1$ if (!sourceLocations.contains(location)) {
continue; if (location instanceof CProjectSourceLocation)
} ((CProjectSourceLocation)location).setGenerated(isReferencedProject(((CProjectSourceLocation)location).getProject()));
location.initializeFrom( data ); sourceLocations.add(location);
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 * Throws an internal error exception
*/ */
private void abort( String message, Throwable e ) throws CoreException { private void abort(String message, Throwable e) throws CoreException {
IStatus s = new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, e ); IStatus s = new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, e);
throw new CoreException( s ); throw new CoreException(s);
} }
private boolean isEmpty( String string ) { private boolean isEmpty(String string) {
return string == null || string.trim().length() == 0; return string == null || string.trim().length() == 0;
} }
public void resourceChanged( IResourceChangeEvent event ) { public void resourceChanged(IResourceChangeEvent event) {
if ( event.getSource() instanceof IWorkspace && event.getDelta() != null ) { if (event.getSource() instanceof IWorkspace && event.getDelta() != null) {
IResourceDelta[] deltas = event.getDelta().getAffectedChildren(); IResourceDelta[] deltas = event.getDelta().getAffectedChildren();
if ( deltas != null ) { if (deltas != null) {
ArrayList list = new ArrayList( deltas.length ); ArrayList<IResource> list = new ArrayList<IResource>(deltas.length);
for( int i = 0; i < deltas.length; ++i ) for (int i = 0; i < deltas.length; ++i)
if ( deltas[i].getResource() instanceof IProject ) if (deltas[i].getResource() instanceof IProject)
list.add( deltas[i].getResource() ); list.add(deltas[i].getResource());
resetSourceLocations( list ); resetSourceLocations(list);
} }
} }
} }
private void saveDisabledGenericSourceLocations( ICSourceLocation[] locations, Document doc, Element node ) { private void saveDisabledGenericSourceLocations(ICSourceLocation[] locations, Document doc, Element node) {
IProject project = getProject(); IProject project = getProject();
if ( project != null && project.exists() && project.isOpen() ) { if (project != null && project.exists() && project.isOpen()) {
List list = CDebugUtils.getReferencedProjects( project ); List<IProject> list = CDebugUtils.getReferencedProjects(project);
HashSet names = new HashSet( list.size() + 1 ); HashSet<String> names = new HashSet<String>(list.size() + 1);
names.add( project.getName() ); names.add(project.getName());
Iterator it = list.iterator(); for (IProject proj : list) {
while( it.hasNext() ) { names.add(proj.getName());
names.add( ((IProject)it.next()).getName() );
} }
for( int i = 0; i < locations.length; ++i ) for (int i = 0; i < locations.length; ++i) {
if ( locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation)locations[i]).isGeneric() ) if (locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation) locations[i]).isGeneric())
names.remove( ((IProjectSourceLocation)locations[i]).getProject().getName() ); names.remove(((IProjectSourceLocation) locations[i]).getProject().getName());
it = names.iterator(); }
while( it.hasNext() ) { for (String name : names) {
Element child = doc.createElement( DISABLED_GENERIC_PROJECT_NAME ); Element child = doc.createElement(DISABLED_GENERIC_PROJECT_NAME);
child.setAttribute( ATTR_PROJECT_NAME, (String)it.next() ); child.setAttribute(ATTR_PROJECT_NAME, name);
node.appendChild( child ); node.appendChild(child);
} }
} }
} }
private void saveAdditionalSourceLocations( ICSourceLocation[] locations, Document doc, Element node ) { private void saveAdditionalSourceLocations(ICSourceLocation[] locations, Document doc, Element node) {
for( int i = 0; i < locations.length; i++ ) { for (int i = 0; i < locations.length; i++) {
if ( locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation)locations[i]).isGeneric() ) if (locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation)locations[i]).isGeneric())
continue; continue;
Element child = doc.createElement( ADDITIONAL_SOURCE_LOCATION_NAME ); Element child = doc.createElement(ADDITIONAL_SOURCE_LOCATION_NAME);
child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() ); child.setAttribute(ATTR_CLASS, locations[i].getClass().getName());
try { try {
child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() ); child.setAttribute(ATTR_MEMENTO, locations[i].getMemento());
} } catch (CoreException e) {
catch( CoreException e ) { CDebugCorePlugin.log(e);
CDebugCorePlugin.log( e );
continue; continue;
} }
node.appendChild( child ); node.appendChild(child);
} }
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getProject() * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getProject()
*/ */
public IProject getProject() { public IProject getProject() {
return fProject; return fProject;
} }
protected void setProject( IProject project ) { protected void setProject(IProject project) {
fProject = project; fProject = project;
} }
private boolean isReferencedProject( IProject ref ) { private boolean isReferencedProject(IProject ref) {
if ( getProject() != null ) { if (getProject() != null) {
try { try {
return Arrays.asList( getProject().getReferencedProjects() ).contains( ref ); return Arrays.asList(getProject().getReferencedProjects()).contains(ref);
} } catch (CoreException e) {
catch( CoreException e ) { CDebugCorePlugin.log(e);
CDebugCorePlugin.log( e );
} }
} }
return false; return false;
@ -561,29 +532,26 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
private void setReferencedProjects() { private void setReferencedProjects() {
fReferencedProjects.clear(); fReferencedProjects.clear();
fReferencedProjects = CDebugUtils.getReferencedProjects( getProject() ); fReferencedProjects = CDebugUtils.getReferencedProjects(getProject());
} }
protected ICSourceLocation[] getDefaultSourceLocations() { protected ICSourceLocation[] getDefaultSourceLocations() {
Iterator it = fReferencedProjects.iterator(); ArrayList<IProjectSourceLocation> list = new ArrayList<IProjectSourceLocation>(fReferencedProjects.size());
ArrayList list = new ArrayList( fReferencedProjects.size() ); if (getProject() != null && getProject().exists() && getProject().isOpen())
if ( getProject() != null && getProject().exists() && getProject().isOpen() ) list.add(SourceLookupFactory.createProjectSourceLocation(getProject()));
list.add( SourceLookupFactory.createProjectSourceLocation( getProject() ) ); for (IProject project : fReferencedProjects) {
while( it.hasNext() ) { if (project != null && project.exists() && project.isOpen())
IProject project = (IProject)it.next(); list.add(SourceLookupFactory.createProjectSourceLocation(project));
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 ) { private void resetSourceLocations(List<IResource> affectedProjects) {
if ( affectedProjects.size() != 0 && getProject() != null ) { if (affectedProjects.size() != 0 && getProject() != null) {
if ( !getProject().exists() || !getProject().isOpen() ) { if (!getProject().exists() || !getProject().isOpen()) {
removeGenericSourceLocations(); removeGenericSourceLocations();
} } else {
else { updateGenericSourceLocations(affectedProjects);
updateGenericSourceLocations( affectedProjects );
} }
} }
} }
@ -591,39 +559,37 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
private void removeGenericSourceLocations() { private void removeGenericSourceLocations() {
fReferencedProjects.clear(); fReferencedProjects.clear();
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
ArrayList newLocations = new ArrayList( locations.length ); ArrayList<ICSourceLocation> newLocations = new ArrayList<ICSourceLocation>(locations.length);
for( int i = 0; i < locations.length; ++i ) for (int i = 0; i < locations.length; ++i) {
if ( !(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric() ) if (!(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric())
newLocations.add( locations[i] ); newLocations.add(locations[i]);
setSourceLocations( (ICSourceLocation[])newLocations.toArray( new ICSourceLocation[newLocations.size()] ) ); }
setSourceLocations(newLocations.toArray(new ICSourceLocation[newLocations.size()]));
} }
private void updateGenericSourceLocations( List affectedProjects ) { private void updateGenericSourceLocations(List<IResource> affectedProjects) {
List newRefs = CDebugUtils.getReferencedProjects( getProject() ); List<IProject> newRefs = CDebugUtils.getReferencedProjects(getProject());
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
ArrayList newLocations = new ArrayList( locations.length ); ArrayList<ICSourceLocation> newLocations = new ArrayList<ICSourceLocation>(locations.length);
for( int i = 0; i < locations.length; ++i ) { for (int i = 0; i < locations.length; ++i) {
if ( !(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric() ) { if (!(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric()) {
newLocations.add( locations[i] ); newLocations.add(locations[i]);
} } else {
else {
IProject project = ((IProjectSourceLocation)locations[i]).getProject(); IProject project = ((IProjectSourceLocation)locations[i]).getProject();
if ( project.exists() && project.isOpen() ) { if (project.exists() && project.isOpen()) {
if ( newRefs.contains( project ) || project.equals( getProject() ) ) { if (newRefs.contains(project) || project.equals(getProject())) {
newLocations.add( locations[i] ); newLocations.add(locations[i]);
newRefs.remove( project ); newRefs.remove(project);
} }
} }
} }
} }
Iterator it = newRefs.iterator(); for (IProject project : newRefs) {
while( it.hasNext() ) { if (!fReferencedProjects.contains(project))
IProject project = (IProject)it.next(); newLocations.add(SourceLookupFactory.createProjectSourceLocation(project));
if ( !fReferencedProjects.contains( project ) )
newLocations.add( SourceLookupFactory.createProjectSourceLocation( project ) );
} }
fReferencedProjects = newRefs; 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; return fDuplicateFiles;
} }
public void setSearchForDuplicateFiles( boolean search ) { public void setSearchForDuplicateFiles(boolean search) {
fDuplicateFiles = search; fDuplicateFiles = search;
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
for( int i = 0; i < locations.length; ++i ) for (int i = 0; i < locations.length; ++i)
locations[i].setSearchForDuplicateFiles( search ); locations[i].setSearchForDuplicateFiles(search);
} }
} }

View file

@ -19,6 +19,7 @@ import java.util.Set;
import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer; 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.ProgramRelativePathSourceContainer;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
@ -182,22 +183,21 @@ public class CSourceLookupDirector extends AbstractSourceLookupDirector {
} }
private IPath getCompilationPath(ISourceContainer container, String sourceName) { private IPath getCompilationPath(ISourceContainer container, String sourceName) {
IPath path = null; if (container instanceof IMappingSourceContainer) {
if (container instanceof MappingSourceContainer) { return ((IMappingSourceContainer) container).getCompilationPath(sourceName);
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) {
}
} }
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 // >> Bugzilla 279473

View file

@ -6,28 +6,43 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.util.MissingResourceException; import org.eclipse.osgi.util.NLS;
import java.util.ResourceBundle;
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$ static {
NLS.initializeMessages(InternalSourceLookupMessages.class.getName(), InternalSourceLookupMessages.class);
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); }
private InternalSourceLookupMessages() { private InternalSourceLookupMessages() {
} // Do not instantiate
public static String getString( String key ) {
try {
return RESOURCE_BUNDLE.getString( key );
}
catch( MissingResourceException e ) {
return '!' + key + '!';
}
} }
} }

View file

@ -7,28 +7,29 @@
# #
# Contributors: # Contributors:
# QNX Software Systems - initial API and implementation # QNX Software Systems - initial API and implementation
# Sergey Prigogin (Google)
############################################################################### ###############################################################################
CDirectorySourceLocation.0=Unable to create memento for C/C++ directory source location {0}. CDirectorySourceLocation_0=Unable to create memento for C/C++ directory source location {0}.
CDirectorySourceLocation.1=Unable to initialize source location - missing directory path. CDirectorySourceLocation_1=Unable to initialize source location - missing directory path.
CDirectorySourceLocation.2=Unable to initialize source location - invalid directory path {0}. CDirectorySourceLocation_2=Unable to initialize source location - invalid directory path {0}.
CDirectorySourceLocation.3=Exception occurred initializing source location. CDirectorySourceLocation_3=Exception occurred initializing source location.
CDirectorySourceContainerType.0=Unable to restore directory source lookup entry - missing path attribute. 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_1=Unable to restore directory source lookup entry - expecting directory element.
CDirectorySourceContainerType.2=Unable to restore directory source lookup entry - invalid memento. 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_0=Unable to create memento for C/C++ project source location {0}.
CProjectSourceLocation.1=Unable to initialize source location - missing project name CProjectSourceLocation_1=Unable to initialize source location - missing project name
CProjectSourceLocation.2=Exception occurred initializing source location. CProjectSourceLocation_2=Exception occurred initializing source location.
CSourceLocator.0=Unable to create memento for C/C++ source locator. CSourceLocator_0=Unable to create memento for C/C++ source locator.
CSourceLocator.1=Unable to restore C/C++ source locator - invalid format. CSourceLocator_1=Unable to restore C/C++ source locator - invalid format.
CSourceLocator.2=Exception occurred initializing source locator. CSourceLocator_2=Exception occurred initializing source locator.
CSourceLocator.3=Error initializing directory source location. CSourceLocator_3=Error initializing directory source location.
MapEntrySourceContainerType.0=Source lookup: unable to restore map entry - missing backend path attribute. 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_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_2=Source lookup: unable to restore map entry - expecting map entry element.
MapEntrySourceContainerType.3=Source lookup: unable to restore map entry - invalid memento. MapEntrySourceContainerType_3=Source lookup: unable to restore map entry - invalid memento.
MappingSourceContainerType.0=Source lookup: unable to restore map entry - expecting memento attribute. MappingSourceContainerType_0=Source lookup: unable to restore map entry - expecting memento attribute.
MappingSourceContainerType.1=Source lookup: unable to restore mapping - expecting mapping element. MappingSourceContainerType_1=Source lookup: unable to restore mapping - expecting mapping element.
MappingSourceContainerType.2=Source lookup: unable to restore mapping - invalid memento. MappingSourceContainerType_2=Source lookup: unable to restore mapping - invalid memento.
SourceUtils.0=Mapping SourceUtils_0=Mapping
ProgramRelativePathSourceContainerType.1=Source lookup: unable to restore program relative source container - invalid memento. ProgramRelativePathSourceContainerType_1=Source lookup: unable to restore program relative source container - invalid memento.

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
@ -38,18 +38,18 @@ public class MapEntrySourceContainerType extends AbstractSourceContainerTypeDele
String path = element.getAttribute(BACKEND_PATH); String path = element.getAttribute(BACKEND_PATH);
IPath backend = new Path(path); IPath backend = new Path(path);
if (!backend.isValidPath(path)) { if (!backend.isValidPath(path)) {
abort(InternalSourceLookupMessages.getString("MapEntrySourceContainerType.0"), null); //$NON-NLS-1$ abort(InternalSourceLookupMessages.MapEntrySourceContainerType_0, null);
} }
path = element.getAttribute(LOCAL_PATH); path = element.getAttribute(LOCAL_PATH);
IPath local = new Path(path); IPath local = new Path(path);
if (!local.isValidPath(path)) { if (!local.isValidPath(path)) {
abort(InternalSourceLookupMessages.getString("MapEntrySourceContainerType.1"), null); //$NON-NLS-1$ abort(InternalSourceLookupMessages.MapEntrySourceContainerType_1, null);
} }
return new MapEntrySourceContainer(backend, local); 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; return null;
} }

View file

@ -6,12 +6,11 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -27,7 +26,6 @@ import org.w3c.dom.Node;
* The mapping container type. * The mapping container type.
*/ */
public class MappingSourceContainerType extends AbstractSourceContainerTypeDelegate { public class MappingSourceContainerType extends AbstractSourceContainerTypeDelegate {
private final static String ELEMENT_MAPPING = "mapping"; //$NON-NLS-1$ 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 ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$
private final static String ATTR_NAME = "name"; //$NON-NLS-1$ private final static String ATTR_NAME = "name"; //$NON-NLS-1$
@ -36,58 +34,57 @@ public class MappingSourceContainerType extends AbstractSourceContainerTypeDeleg
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String) * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String)
*/ */
public ISourceContainer createSourceContainer( String memento ) throws CoreException { public ISourceContainer createSourceContainer(String memento) throws CoreException {
Node node = parseDocument( memento ); Node node = parseDocument(memento);
if ( node.getNodeType() == Node.ELEMENT_NODE ) { if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element)node; Element element = (Element) node;
if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) { if (ELEMENT_MAPPING.equals(element.getNodeName())) {
String name = element.getAttribute( ATTR_NAME ); String name = element.getAttribute(ATTR_NAME);
if ( name == null ) if (name == null)
name = ""; //$NON-NLS-1$ name = ""; //$NON-NLS-1$
List entries = new ArrayList(); List<MapEntrySourceContainer> entries = new ArrayList<MapEntrySourceContainer>();
Node childNode = element.getFirstChild(); Node childNode = element.getFirstChild();
while( childNode != null ) { while (childNode != null) {
if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { if (childNode.getNodeType() == Node.ELEMENT_NODE) {
Element child = (Element)childNode; Element child = (Element)childNode;
if ( ELEMENT_MAP_ENTRY.equals( child.getNodeName() ) ) { if (ELEMENT_MAP_ENTRY.equals(child.getNodeName())) {
String childMemento = child.getAttribute( ATTR_MEMENTO ); String childMemento = child.getAttribute(ATTR_MEMENTO);
if ( childMemento == null || childMemento.length() == 0 ) { if (childMemento == null || childMemento.length() == 0) {
abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.0" ), null ); //$NON-NLS-1$ abort(InternalSourceLookupMessages.MappingSourceContainerType_0, null);
} }
ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID ); ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType(MapEntrySourceContainer.TYPE_ID);
MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento ); MapEntrySourceContainer entry = (MapEntrySourceContainer) type.createSourceContainer(childMemento);
entries.add( entry ); entries.add(entry);
} }
} }
childNode = childNode.getNextSibling(); childNode = childNode.getNextSibling();
} }
MappingSourceContainer container = new MappingSourceContainer( name ); MappingSourceContainer container = new MappingSourceContainer(name);
Iterator it = entries.iterator(); for (MapEntrySourceContainer entry : entries) {
while( it.hasNext() ) { container.addMapEntry(entry);
container.addMapEntry( (MapEntrySourceContainer)it.next() );
} }
return container; 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; return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer) * @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(); Document document = newDocument();
Element element = document.createElement( ELEMENT_MAPPING ); Element element = document.createElement(ELEMENT_MAPPING);
element.setAttribute( ATTR_NAME, container.getName() ); element.setAttribute(ATTR_NAME, container.getName());
ISourceContainer[] entries = ((MappingSourceContainer)container).getSourceContainers(); ISourceContainer[] entries = ((MappingSourceContainer)container).getSourceContainers();
for ( int i = 0; i < entries.length; ++i ) { for (int i = 0; i < entries.length; ++i) {
Element child = document.createElement( ELEMENT_MAP_ENTRY ); Element child = document.createElement(ELEMENT_MAP_ENTRY);
child.setAttribute( ATTR_MEMENTO, entries[i].getType().getMemento( entries[i] ) ); child.setAttribute(ATTR_MEMENTO, entries[i].getType().getMemento(entries[i]));
element.appendChild( child ); element.appendChild(child);
} }
document.appendChild( element ); document.appendChild(element);
return serializeDocument( document ); return serializeDocument(document);
} }
} }

View file

@ -6,9 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Freescale - Initial implementation * Freescale - Initial implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
import org.eclipse.cdt.debug.core.sourcelookup.ProgramRelativePathSourceContainer; 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; import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
public class ProgramRelativePathSourceContainerType extends AbstractSourceContainerTypeDelegate { public class ProgramRelativePathSourceContainerType extends AbstractSourceContainerTypeDelegate {
private final static String ELEMENT_NAME = "programRelativePath"; //$NON-NLS-1$ private final static String ELEMENT_NAME = "programRelativePath"; //$NON-NLS-1$
public ISourceContainer createSourceContainer(String memento) throws CoreException { public ISourceContainer createSourceContainer(String memento) throws CoreException {
if ( ELEMENT_NAME.equals( memento ) ) { if (ELEMENT_NAME.equals(memento)) {
return new ProgramRelativePathSourceContainer(); return new ProgramRelativePathSourceContainer();
} }
abort( InternalSourceLookupMessages.getString("ProgramRelativePathSourceContainerType.1"), null ); //$NON-NLS-1$ abort(InternalSourceLookupMessages.ProgramRelativePathSourceContainerType_1, null);
return null; return null;
} }
public String getMemento(ISourceContainer container) throws CoreException { public String getMemento(ISourceContainer container) throws CoreException {
if (container instanceof ProgramRelativePathSourceContainer){ if (container instanceof ProgramRelativePathSourceContainer) {
return ELEMENT_NAME; return ELEMENT_NAME;
} } else {
else{
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
} }

View file

@ -41,149 +41,138 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
public class SourceUtils { public class SourceUtils {
private static final String NAME_COMMON_SOURCE_LOCATIONS = "commonSourceLocations"; //$NON-NLS-1$ 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 NAME_SOURCE_LOCATION = "sourceLocation"; //$NON-NLS-1$
private static final String ATTR_CLASS = "class"; //$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_MEMENTO = "memento"; //$NON-NLS-1$
public static String getCommonSourceLocationsMemento( ICSourceLocation[] locations ) { public static String getCommonSourceLocationsMemento(ICSourceLocation[] locations) {
Document document = null; Document document = null;
Throwable ex = null; Throwable ex = null;
try { try {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element element = document.createElement( NAME_COMMON_SOURCE_LOCATIONS ); Element element = document.createElement(NAME_COMMON_SOURCE_LOCATIONS);
document.appendChild( element ); document.appendChild(element);
saveSourceLocations( document, element, locations ); saveSourceLocations(document, element, locations);
return CDebugUtils.serializeDocument( document ); return CDebugUtils.serializeDocument(document);
} } catch (ParserConfigurationException e) {
catch( ParserConfigurationException e ) { ex = e;
} catch (IOException e) {
ex = e;
} catch (TransformerException e) {
ex = e; ex = e;
} }
catch( IOException e ) { CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0,
ex = e; "Error saving common source settings.", ex)); //$NON-NLS-1$
}
catch( TransformerException e ) {
ex = e;
}
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error saving common source settings.", ex ) ); //$NON-NLS-1$
return null; return null;
} }
private static void saveSourceLocations( Document doc, Element node, ICSourceLocation[] locations ) { private static void saveSourceLocations(Document doc, Element node, ICSourceLocation[] locations) {
for( int i = 0; i < locations.length; i++ ) { for(int i = 0; i < locations.length; i++) {
Element child = doc.createElement( NAME_SOURCE_LOCATION ); Element child = doc.createElement(NAME_SOURCE_LOCATION);
child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() ); child.setAttribute(ATTR_CLASS, locations[i].getClass().getName());
try { try {
child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() ); child.setAttribute(ATTR_MEMENTO, locations[i].getMemento());
} } catch (CoreException e) {
catch( CoreException e ) { CDebugCorePlugin.log(e);
CDebugCorePlugin.log( e );
continue; continue;
} }
node.appendChild( child ); node.appendChild(child);
} }
} }
public static ICSourceLocation[] getCommonSourceLocationsFromMemento( String memento ) { public static ICSourceLocation[] getCommonSourceLocationsFromMemento(String memento) {
ICSourceLocation[] result = new ICSourceLocation[0]; ICSourceLocation[] result = new ICSourceLocation[0];
if ( !isEmpty( memento ) ) { if (!isEmpty(memento)) {
try { try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento ); StringReader reader = new StringReader(memento);
InputSource source = new InputSource( reader ); InputSource source = new InputSource(reader);
Element root = parser.parse( source ).getDocumentElement(); Element root = parser.parse(source).getDocumentElement();
if ( root.getNodeName().equalsIgnoreCase( NAME_COMMON_SOURCE_LOCATIONS ) ) if (root.getNodeName().equalsIgnoreCase(NAME_COMMON_SOURCE_LOCATIONS))
result = initializeSourceLocations( root ); result = initializeSourceLocations(root);
} } catch (ParserConfigurationException e) {
catch( ParserConfigurationException e ) { CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0,
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$ "Error initializing common source settings.", e)); //$NON-NLS-1$
} } catch (SAXException e) {
catch( SAXException e ) { CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0,
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$ "Error initializing common source settings.", e)); //$NON-NLS-1$
} } catch (IOException e) {
catch( IOException e ) { CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0,
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$ "Error initializing common source settings.", e)); //$NON-NLS-1$
} }
} }
return result; return result;
} }
public static ICSourceLocation[] initializeSourceLocations( Element root ) { public static ICSourceLocation[] initializeSourceLocations(Element root) {
List sourceLocations = new LinkedList(); List<ICSourceLocation> sourceLocations = new LinkedList<ICSourceLocation>();
NodeList list = root.getChildNodes(); NodeList list = root.getChildNodes();
int length = list.getLength(); int length = list.getLength();
for( int i = 0; i < length; ++i ) { for(int i = 0; i < length; ++i) {
Node node = list.item( i ); Node node = list.item(i);
short type = node.getNodeType(); short type = node.getNodeType();
if ( type == Node.ELEMENT_NODE ) { if (type == Node.ELEMENT_NODE) {
Element entry = (Element)node; Element entry = (Element)node;
if ( entry.getNodeName().equalsIgnoreCase( NAME_SOURCE_LOCATION ) ) { if (entry.getNodeName().equalsIgnoreCase(NAME_SOURCE_LOCATION)) {
String className = entry.getAttribute( ATTR_CLASS ); String className = entry.getAttribute(ATTR_CLASS);
String data = entry.getAttribute( ATTR_MEMENTO ); String data = entry.getAttribute(ATTR_MEMENTO);
if ( className == null || className.trim().length() == 0 ) { if (className == null || className.trim().length() == 0) {
CDebugCorePlugin.log( "Unable to restore common source locations - invalid format." ); //$NON-NLS-1$ CDebugCorePlugin.log("Unable to restore common source locations - invalid format."); //$NON-NLS-1$
continue; continue;
} }
Class clazz = null; Class<?> clazz = null;
try { try {
clazz = CDebugCorePlugin.getDefault().getBundle().loadClass( className ); clazz = CDebugCorePlugin.getDefault().getBundle().loadClass(className);
} } catch (ClassNotFoundException e) {
catch( ClassNotFoundException e ) { CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", //$NON-NLS-1$
CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[]{ className } ) ); //$NON-NLS-1$ new String[] { className }));
continue; continue;
} }
ICSourceLocation location = null; ICSourceLocation location = null;
try { try {
location = (ICSourceLocation)clazz.newInstance(); location = (ICSourceLocation)clazz.newInstance();
} } catch (IllegalAccessException e) {
catch( IllegalAccessException e ) { CDebugCorePlugin.log("Unable to restore source location: " + e.getMessage()); //$NON-NLS-1$
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$
continue; continue;
} } catch (InstantiationException e) {
catch( InstantiationException e ) { CDebugCorePlugin.log("Unable to restore source location: " + e.getMessage()); //$NON-NLS-1$
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$
continue; continue;
} }
try { try {
location.initializeFrom( data ); location.initializeFrom(data);
sourceLocations.add( location ); sourceLocations.add(location);
} } catch (CoreException e) {
catch( CoreException e ) { CDebugCorePlugin.log("Unable to restore source location: " + e.getMessage()); //$NON-NLS-1$
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); return (string == null || string.trim().length() == 0);
} }
static public ISourceContainer[] convertSourceLocations( ICSourceLocation[] locations ) { static public ISourceContainer[] convertSourceLocations(ICSourceLocation[] locations) {
ArrayList containers = new ArrayList( locations.length ); ArrayList<ISourceContainer> containers = new ArrayList<ISourceContainer>(locations.length);
int mappingCount = 0; int mappingCount = 0;
for ( int i = 0; i < locations.length; ++i ) { for (int i = 0; i < locations.length; ++i) {
if ( locations[i] instanceof IProjectSourceLocation ) { if (locations[i] instanceof IProjectSourceLocation) {
containers.add( new ProjectSourceContainer( ((IProjectSourceLocation)locations[i]).getProject(), false ) ); containers.add(new ProjectSourceContainer(((IProjectSourceLocation)locations[i]).getProject(), false));
} } else if (locations[i] instanceof IDirectorySourceLocation) {
else if ( locations[i] instanceof IDirectorySourceLocation ) {
IDirectorySourceLocation d = (IDirectorySourceLocation)locations[i]; IDirectorySourceLocation d = (IDirectorySourceLocation)locations[i];
IPath a = d.getAssociation(); IPath a = d.getAssociation();
if ( a != null ) { if (a != null) {
MappingSourceContainer mapping = new MappingSourceContainer( InternalSourceLookupMessages.getString( "SourceUtils.0" ) + (++mappingCount) ); //$NON-NLS-1$ MappingSourceContainer mapping = new MappingSourceContainer(InternalSourceLookupMessages.SourceUtils_0 + (++mappingCount));
mapping.addMapEntries( new MapEntrySourceContainer[] { new MapEntrySourceContainer( a, d.getDirectory() ) } ); mapping.addMapEntries(new MapEntrySourceContainer[] { new MapEntrySourceContainer(a, d.getDirectory()) });
containers.add( mapping ); 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()]);
} }
} }