1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

Bug 341175 - Address FindBugs issues in debug.core and debug.ui

This commit is contained in:
John Cortell 2011-03-28 23:11:24 +00:00
parent ea04df9522
commit eeb3c6825a
26 changed files with 293 additions and 301 deletions

View file

@ -237,7 +237,7 @@ public class BreakpointActionManager {
}
public void saveActionData() {
String actionData = new String(""); //$NON-NLS-1$
String actionData = ""; //$NON-NLS-1$
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;

View file

@ -455,11 +455,11 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
}
public IBreakpoint getBreakpoint( ICDIBreakpoint cdiBreakpoint ) {
Object b = null;
ICBreakpoint b;
synchronized ( getBreakpointMap() ) {
b = getBreakpointMap().getCBreakpoint( cdiBreakpoint );
}
return ( b instanceof IBreakpoint ) ? (IBreakpoint)b : null;
return b;
}
/**
@ -781,7 +781,7 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
ArrayList installedCDIBplist = new ArrayList();
ArrayList installedCBplist = new ArrayList();
ICBreakpoint[] breakpoints = new ICBreakpoint[0];
ICBreakpoint[] breakpoints;
synchronized( getBreakpointMap() ) {
breakpoints = getBreakpointMap().getAllCBreakpoints();
for ( int i = 0; i < breakpoints.length; ++i ) {

View file

@ -143,7 +143,7 @@ public class CGlobalVariableManager implements ICGlobalVariableManager {
return;
}
ICGlobalVariable[] globals = new ICGlobalVariable[0];
ICGlobalVariable[] globals;
synchronized( fGlobals ) {
globals = fGlobals.toArray( new ICGlobalVariable[fGlobals.size()] );
fGlobals.clear();

View file

@ -331,7 +331,7 @@ abstract public class CDebugElement extends PlatformObject implements ICDebugEle
fSeverity = severity;
fMessage = message;
if ( fMessage != null )
fMessage.trim();
fMessage = fMessage.trim();
}
protected void resetStatus() {

View file

@ -1438,7 +1438,6 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
*/
public IGlobalVariableDescriptor[] getGlobals() throws DebugException {
ICDITarget cdiTarget = getCDITarget();
IGlobalVariableDescriptor[] globals = new IGlobalVariableDescriptor[0];
// If the backend can give us the globals...
boolean hasCDIGlobals = false;
ArrayList<IGlobalVariableDescriptor> list = new ArrayList<IGlobalVariableDescriptor>();
@ -1458,8 +1457,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
list.addAll(getCFileGlobals(file));
}
}
globals = list.toArray(new IGlobalVariableDescriptor[list.size()]);
return globals;
return list.toArray(new IGlobalVariableDescriptor[list.size()]);
}
private List<IGlobalVariableDescriptor> getCFileGlobals(IBinaryObject file) {
@ -1952,7 +1950,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
protected void stopInMain() throws DebugException {
String mainSymbol = new String(ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT);
String mainSymbol = ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT;
try {
final ICDITarget cdiTarget = getCDITarget();
if (cdiTarget != null) {

View file

@ -47,7 +47,7 @@ public class CModule extends CDebugElement implements ICModule {
private int fType = 0;
private ICElement fCElement;
private Binary fBinary;
private ICDIObject fCDIObject;
@ -70,7 +70,7 @@ public class CModule extends CDebugElement implements ICModule {
private CModule( int type, CDebugTarget target, IPath path ) {
super( target );
fType = type;
fCElement = createBinary(path);
fBinary = createBinary(path);
fCDIObject = null;
fImageName = path;
fSymbolsFileName = path;
@ -84,7 +84,7 @@ public class CModule extends CDebugElement implements ICModule {
fType = type;
if ( cdiObject instanceof ICDISharedLibrary ) {
ICDISharedLibrary cdiSharedLib = (ICDISharedLibrary)cdiObject;
fCElement = createBinary(new Path(cdiSharedLib.getFileName()));
fBinary = createBinary(new Path(cdiSharedLib.getFileName()));
}
fCDIObject = cdiObject;
fImageName = ( ( cdiObject instanceof ICDISharedLibrary ) ) ? new Path( ((ICDISharedLibrary)cdiObject).getFileName() ) : new Path( CoreModelMessages.getString( "CModule.0" ) ); //$NON-NLS-1$
@ -203,8 +203,8 @@ public class CModule extends CDebugElement implements ICModule {
if (fCDIObject instanceof ICDISharedLibrary)
return ((ICDISharedLibrary)fCDIObject).areSymbolsLoaded();
if (fCElement instanceof IBinary)
return ((IBinary)fCElement).hasDebug();
if (fBinary != null)
return fBinary.hasDebug();
return false;
}
@ -227,14 +227,14 @@ public class CModule extends CDebugElement implements ICModule {
* @see org.eclipse.cdt.debug.core.model.ICModule#getPlatform()
*/
public String getPlatform() {
return ( fCElement instanceof IBinary ) ? ((IBinary)fCElement).getCPU() : CoreModelMessages.getString( "CModule.1" ); //$NON-NLS-1$
return ( fBinary != null ) ? fBinary.getCPU() : CoreModelMessages.getString( "CModule.1" ); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICModule#isLittleEndian()
*/
public boolean isLittleEndian() {
return ( fCElement instanceof IBinary ) ? ((IBinary)fCElement).isLittleEndian() : ((CDebugTarget)getDebugTarget()).isLittleEndian();
return ( fBinary != null ) ? fBinary.isLittleEndian() : ((CDebugTarget)getDebugTarget()).isLittleEndian();
}
/* (non-Javadoc)
@ -248,7 +248,7 @@ public class CModule extends CDebugElement implements ICModule {
* @see org.eclipse.cdt.debug.core.model.ICModule#getCPU()
*/
public String getCPU() {
return ( fCElement instanceof IBinary ) ? ((IBinary)fCElement).getCPU() : null;
return ( fBinary != null ) ? fBinary.getCPU() : null;
}
/* (non-Javadoc)
@ -273,7 +273,7 @@ public class CModule extends CDebugElement implements ICModule {
}
protected ICElement getCElement() {
return fCElement;
return fBinary;
}
private void loadSymbolsFromFile(IPath path) throws DebugException {

View file

@ -57,7 +57,7 @@ public class CType implements ICType {
ICDIType type = getCDIType();
while( type instanceof ICDIArrayType ) {
++length;
type = ( type instanceof ICDIDerivedType ) ? ((ICDIDerivedType)type).getComponentType() : null;
type = ((ICDIDerivedType)type).getComponentType();
}
int[] dims = new int[length];
type = getCDIType();

View file

@ -179,16 +179,17 @@ public class CValue extends AbstractCValue {
ICDIValue value = getUnderlyingValue();
if ( value != null ) {
vars = value.getVariables();
// Quick fix.
// getVariables should return an empty array instead of null.
if ( vars == null ) {
vars = new ICDIVariable[0];
}
}
}
catch( CDIException e ) {
requestFailed( e.getMessage(), e );
}
// getVariables should return an empty array instead of null.
if ( vars == null ) {
vars = new ICDIVariable[0];
}
return Arrays.asList( vars );
}

View file

@ -19,13 +19,11 @@ import org.eclipse.cdt.debug.core.model.IDisassemblyInstruction;
public class DisassemblyInstruction extends CDebugElement implements IDisassemblyInstruction {
private BigInteger fBaseElement;
private ICDIInstruction fCDIInstruction;
private IAddress fAddress;
public DisassemblyInstruction( CDebugTarget target, BigInteger baseElement, ICDIInstruction instruction ) {
super( target );
fBaseElement = baseElement;
fCDIInstruction = instruction;
fAddress = target.getAddressFactory().createAddress( fCDIInstruction.getAdress() );
}

View file

@ -103,7 +103,7 @@ public class CSourceLookupDirector extends AbstractSourceLookupDirector {
if (container instanceof CProjectSourceContainer && project.equals(((CProjectSourceContainer) container).getProject())) {
return true;
}
if (container instanceof ProjectSourceContainer && project.equals(((CProjectSourceContainer) container).getProject())) {
if (container instanceof ProjectSourceContainer && project.equals(((ProjectSourceContainer) container).getProject())) {
return true;
}
try {

View file

@ -685,7 +685,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.5" ), new String[]{ sigInfo.getName(), sigInfo.getDescription() } ); //$NON-NLS-1$
}
else if ( info != null && info instanceof ICDIExitInfo ) {
reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.6" ), new Integer[] { new Integer( ((ICDIExitInfo)info).getCode() ) } ); //$NON-NLS-1$
reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.6" ), new Integer[] { Integer.valueOf( ((ICDIExitInfo)info).getCode() ) } ); //$NON-NLS-1$
}
return MessageFormat.format( label, new String[] { target.getName(), reason } );
}

View file

@ -59,7 +59,7 @@ public class AddWatchpointDialog extends Dialog implements ModifyListener, Selec
private boolean fRangeInitialEnable;
private Button fRangeEnableButton;
private Text fRangeField;
private String fRange = new String();
private String fRange = ""; //$NON-NLS-1$
private Button fChkBtnWrite;
private Button fChkBtnRead;

View file

@ -64,7 +64,7 @@ public class SelectionButtonDialogFieldGroup extends DialogField {
fButtonsSelected[i]= false;
fButtonsEnabled[i]= true;
}
if (fButtonsStyle == SWT.RADIO) {
if (buttonsStyle == SWT.RADIO) {
fButtonsSelected[0]= true;
}

View file

@ -89,9 +89,9 @@ public class DisassemblyDisplayModeHandler extends AbstractHandler implements IE
if ( s instanceof IStructuredSelection ) {
Object o = ((IStructuredSelection)s).getFirstElement();
if ( o instanceof DisassemblyEditorInput ) {
IDocumentProvider dp = CDebugUIPlugin.getDefault().getDisassemblyEditorManager().getDocumentProvider();
if ( dp instanceof DisassemblyDocumentProvider ) {
return (DisassemblyEditorPresentation)((DisassemblyDocumentProvider)dp).getDocumentPresentation( o );
DisassemblyDocumentProvider dp = CDebugUIPlugin.getDefault().getDisassemblyEditorManager().getDocumentProvider();
if ( dp != null ) {
return (DisassemblyEditorPresentation)dp.getDocumentPresentation( o );
}
}
}

View file

@ -194,6 +194,6 @@ public final class ViewIDCounterManager {
}
}
return new Integer(0);
return Integer.valueOf(0);
}
}

View file

@ -146,7 +146,6 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
* Set the values of the component widgets based on the values in the preference store
*/
private void setValues() {
IPreferenceStore store = getPreferenceStore();
fVariableFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ) ) );
fExpressionFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) );
fRegisterFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) );
@ -299,7 +298,6 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
* Store the preference values based on the state of the component widgets
*/
private void storeValues() {
IPreferenceStore store = getPreferenceStore();
CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT, getFormatId( fVariableFormatCombo.getSelectionIndex() ) );
CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT, getFormatId( fExpressionFormatCombo.getSelectionIndex() ) );
CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT, getFormatId( fRegisterFormatCombo.getSelectionIndex() ) );
@ -318,7 +316,6 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
}
private void setDefaultValues() {
IPreferenceStore store = getPreferenceStore();
fVariableFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ) ) );
fExpressionFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) );
fRegisterFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) );

View file

@ -72,10 +72,10 @@ public class ModuleProperties {
*/
private ModuleProperties( ICModule module ) {
fProperties = new ArrayList( 10 );
fProperties.add( new Property( TYPE, new Integer( module.getType() ) ) );
fProperties.add( new Property( TYPE, Integer.valueOf(module.getType()) ) );
fProperties.add( new Property( CPU, module.getCPU() ) );
fProperties.add( new Property( BASE_ADDRESS, module.getBaseAddress() ) );
fProperties.add( new Property( SIZE, new Long( module.getSize() ) ) );
fProperties.add( new Property( SIZE, Long.valueOf( module.getSize() ) ) );
fProperties.add( new Property( SYMBOLS_LOADED, Boolean.valueOf( module.areSymbolsLoaded() ) ) );
fProperties.add( new Property( SYMBOLS_FILE, module.getSymbolsFileName() ) );
}

View file

@ -83,14 +83,14 @@ abstract class BaseViewer extends TreeViewer {
Tree tree = getTree();
// save the column order
String columnOrder = ""; //$NON-NLS-1$
StringBuilder columnOrder = new StringBuilder(); //$NON-NLS-1$
for (int index : tree.getColumnOrder()) {
columnOrder += ","; //$NON-NLS-1$
columnOrder += Integer.toString(index);
columnOrder.append(","); //$NON-NLS-1$
columnOrder.append(Integer.toString(index));
}
// trim the leading comma
columnOrder = columnOrder.substring(1);
preferences.setValue(getColumnOrderKey(), columnOrder);
columnOrder.deleteCharAt(0);
preferences.setValue(getColumnOrderKey(), columnOrder.toString());
// save which column was sorted and in which direction
TreeColumn sortedColumn = tree.getSortColumn();

View file

@ -159,7 +159,7 @@ public class AddMemoryBlockDialog extends TrayDialog implements ModifyListener,
GC gc = new GC(fAddressInput);
FontMetrics fm = gc.getFontMetrics();
// Give enough room for a 64 bit hex address (25 is a guess at the combobox selector)
gridData.minimumWidth = gridData.minimumWidth = 18 * fm.getAverageCharWidth() + 25;
gridData.minimumWidth = 18 * fm.getAverageCharWidth() + 25;
gc.dispose();
fAddressInput.setLayoutData(gridData);
fAddressInput.addModifyListener(this);

View file

@ -43,7 +43,7 @@ import org.xml.sax.helpers.DefaultHandler;
public class ExternalToolAction extends AbstractBreakpointAction {
private String externalToolName = new String(""); //$NON-NLS-1$
private String externalToolName = ""; //$NON-NLS-1$
public IStatus execute(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor) {
IStatus errorStatus = null;
@ -96,7 +96,7 @@ public class ExternalToolAction extends AbstractBreakpointAction {
}
public String getMemento() {
String executeData = new String(""); //$NON-NLS-1$
String executeData = ""; //$NON-NLS-1$
if (externalToolName != null) {
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;

View file

@ -197,7 +197,7 @@ public class ExternalToolActionComposite extends Composite {
public ILaunchConfiguration[] getLaunchConfigurations() {
ArrayList onlyExternalTools = new ArrayList();
ILaunchManager lcm = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration[] launchConfigurations = new ILaunchConfiguration[0];
ILaunchConfiguration[] launchConfigurations;
try {
launchConfigurations = lcm.getLaunchConfigurations();
for (int i = 0; i < launchConfigurations.length; i++) {
@ -205,11 +205,9 @@ public class ExternalToolActionComposite extends Composite {
ILaunchConfiguration config = launchConfigurations[i];
ILaunchConfigurationType type = config.getType();
boolean priv = false;
if (config != null) {
try {
priv = config.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false);
} catch (CoreException e) {
}
try {
priv = config.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false);
} catch (CoreException e) {
}
if (type != null) {
if (!priv && type.supportsMode(ILaunchManager.RUN_MODE) && equalCategories(type.getCategory(), "org.eclipse.ui.externaltools") //$NON-NLS-1$

View file

@ -110,7 +110,7 @@ public class LogAction extends AbstractBreakpointAction {
}
public String getMemento() {
String logData = new String(""); //$NON-NLS-1$
String logData = ""; //$NON-NLS-1$
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;

View file

@ -41,7 +41,7 @@ import org.xml.sax.helpers.DefaultHandler;
public class ResumeAction extends AbstractBreakpointAction {
final int INCRIMENT_MSEC = 100;
final static int INCRIMENT_MSEC = 100;
int pauseTime = 0;
@ -60,7 +60,7 @@ public class ResumeAction extends AbstractBreakpointAction {
long currentTime = System.currentTimeMillis();
while (!monitor.isCanceled() && currentTime < endTime ){
monitor.setTaskName(MessageFormat.format(Messages.getString("ResumeAction.SummaryResumeTime"), new Object[] { new Long((endTime - currentTime)/1000) })); //$NON-NLS-1$)
monitor.setTaskName(MessageFormat.format(Messages.getString("ResumeAction.SummaryResumeTime"), new Object[] { Long.valueOf((endTime - currentTime)/1000) })); //$NON-NLS-1$)
monitor.worked(1);
Thread.sleep(INCRIMENT_MSEC);
currentTime = System.currentTimeMillis();
@ -104,7 +104,7 @@ public class ResumeAction extends AbstractBreakpointAction {
}
public String getMemento() {
String resumeData = new String(""); //$NON-NLS-1$
String resumeData = ""; //$NON-NLS-1$
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;
@ -139,7 +139,7 @@ public class ResumeAction extends AbstractBreakpointAction {
public String getSummary() {
if (pauseTime == 0)
return Messages.getString("ResumeAction.SummaryImmediately"); //$NON-NLS-1$
return MessageFormat.format(Messages.getString("ResumeAction.SummaryResumeTime"), new Object[] { new Integer(pauseTime) }); //$NON-NLS-1$
return MessageFormat.format(Messages.getString("ResumeAction.SummaryResumeTime"), new Object[] { Integer.valueOf(pauseTime) }); //$NON-NLS-1$
}
public String getTypeName() {

View file

@ -115,7 +115,7 @@ public class SoundAction extends AbstractBreakpointAction {
public String getSummary() {
if (soundFile == null)
return new String(""); //$NON-NLS-1$
return ""; //$NON-NLS-1$
return soundFile.getAbsolutePath();
}
@ -124,7 +124,7 @@ public class SoundAction extends AbstractBreakpointAction {
}
public String getMemento() {
String soundData = new String(""); //$NON-NLS-1$
String soundData = ""; //$NON-NLS-1$
if (soundFile != null) {
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;

View file

@ -1,237 +1,237 @@
/*******************************************************************************
* Copyright (c) 2007 Nokia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nokia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.ui.breakpointactions;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.debug.core.breakpointactions.IBreakpointAction;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.swt.widgets.Composite;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
public class SoundActionPage extends PlatformObject implements IBreakpointActionPage {
private static final String SOUND_ACTION_RECENT = "SoundBehaviorDialog.recentSounds"; //$NON-NLS-1$
private static boolean isWindows() {
String os = System.getProperty("os.name"); //$NON-NLS-1$
return (os != null && os.toLowerCase().startsWith("win")); //$NON-NLS-1$
}
private static boolean isMacOS() {
String os = System.getProperty("os.name"); //$NON-NLS-1$
return (os != null && os.toLowerCase().startsWith("mac")); //$NON-NLS-1$
}
private SoundActionComposite editor = null;
private String mediaPath = ""; //$NON-NLS-1$
private ArrayList recentSounds = new ArrayList();
private SoundAction soundAction;
public SoundActionPage() {
if (isWindows())
mediaPath = "C:\\WINNT\\Media\\"; //$NON-NLS-1$
if (isMacOS())
mediaPath = "/System/Library/Sounds"; //$NON-NLS-1$
loadRecentSounds();
}
public void actionDialogCanceled() {
}
public void actionDialogOK() {
saveRecentSounds();
soundAction.setSoundFile(editor.getSoundFile());
}
public void addRecentSound(File soundFile) {
String soundFilePath = soundFile.getAbsolutePath();
int removeIndex = -1;
int fileCount = 0;
for (Iterator iter = recentSounds.iterator(); iter.hasNext() && removeIndex < 0;) {
File element = (File) iter.next();
if (element.getAbsolutePath().equals(soundFilePath))
removeIndex = fileCount;
fileCount++;
}
if (removeIndex >= 0)
recentSounds.remove(removeIndex);
recentSounds.add(soundFile);
if (recentSounds.size() > 10)
recentSounds.remove(0);
}
public Composite createComposite(IBreakpointAction action, Composite composite, int style) {
this.soundAction = (SoundAction) action;
loadRecentSounds();
if (soundAction.getSoundFile() == null && recentSounds.size() > 0)
soundAction.setSoundFile((File) recentSounds.get(0));
editor = new SoundActionComposite(composite, style, this);
return editor;
}
public String getMediaPath() {
return mediaPath;
}
public ArrayList getRecentSounds() {
return recentSounds;
}
public String getSummary() {
if (soundAction.getSoundFile() == null)
return new String(""); //$NON-NLS-1$
return soundAction.getSoundFile().getAbsolutePath();
}
private void initializeRecentSounds() {
if (isWindows()) {
String defaultSounds[] = { "chimes.wav", "chord.wav", "ding.wav", "notify.wav", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tada.wav" }; //$NON-NLS-1$
for (int i = 0; i < defaultSounds.length; i++) {
File soundFile = new File(mediaPath + defaultSounds[i]);
if (soundFile.exists())
recentSounds.add(soundFile);
}
}
if (isMacOS()) {
File macSounds = new File(mediaPath);
File[] soundFiles = macSounds.listFiles();
for (int i = 0; i < soundFiles.length; i++) {
String fileExtension = new Path(soundFiles[i].getAbsolutePath()).getFileExtension();
if (fileExtension.equalsIgnoreCase("aiff") || fileExtension.equalsIgnoreCase("wav")) //$NON-NLS-1$ //$NON-NLS-2$
recentSounds.add(soundFiles[i]);
}
}
saveRecentSounds();
}
private void loadRecentSounds() {
String recentSoundData = CDebugUIPlugin.getDefault().getPreferenceStore().getString(SOUND_ACTION_RECENT);
if (recentSoundData == null || recentSoundData.length() == 0) {
initializeRecentSounds();
return;
}
recentSounds = new ArrayList();
Element root = null;
DocumentBuilder parser;
try {
parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
root = parser.parse(new InputSource(new StringReader(recentSoundData))).getDocumentElement();
NodeList nodeList = root.getChildNodes();
int entryCount = nodeList.getLength();
for (int i = 0; i < entryCount; i++) {
Node node = nodeList.item(i);
short type = node.getNodeType();
if (type == Node.ELEMENT_NODE) {
Element subElement = (Element) node;
String nodeName = subElement.getNodeName();
if (nodeName.equalsIgnoreCase("soundFileName")) { //$NON-NLS-1$
String value = subElement.getAttribute("name"); //$NON-NLS-1$
if (value == null)
throw new Exception();
File soundFile = new File(value);
if (soundFile.exists()) {
recentSounds.add(soundFile);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (recentSounds.size() == 0)
initializeRecentSounds();
}
public void saveRecentSounds() {
String recentSoundData = new String(""); //$NON-NLS-1$
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = dfactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("recentSounds"); //$NON-NLS-1$
doc.appendChild(rootElement);
for (Iterator iter = recentSounds.iterator(); iter.hasNext();) {
File soundFile = (File) iter.next();
Element element = doc.createElement("soundFileName"); //$NON-NLS-1$
element.setAttribute("name", soundFile.getAbsolutePath()); //$NON-NLS-1$
rootElement.appendChild(element);
}
ByteArrayOutputStream s = new ByteArrayOutputStream();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
DOMSource source = new DOMSource(doc);
StreamResult outputTarget = new StreamResult(s);
transformer.transform(source, outputTarget);
recentSoundData = s.toString("UTF8"); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
CDebugUIPlugin.getDefault().getPreferenceStore().setValue(SOUND_ACTION_RECENT, recentSoundData);
}
public SoundAction getSoundAction() {
return soundAction;
}
}
/*******************************************************************************
* Copyright (c) 2007 Nokia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nokia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.ui.breakpointactions;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.debug.core.breakpointactions.IBreakpointAction;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.swt.widgets.Composite;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
public class SoundActionPage extends PlatformObject implements IBreakpointActionPage {
private static final String SOUND_ACTION_RECENT = "SoundBehaviorDialog.recentSounds"; //$NON-NLS-1$
private static boolean isWindows() {
String os = System.getProperty("os.name"); //$NON-NLS-1$
return (os != null && os.toLowerCase().startsWith("win")); //$NON-NLS-1$
}
private static boolean isMacOS() {
String os = System.getProperty("os.name"); //$NON-NLS-1$
return (os != null && os.toLowerCase().startsWith("mac")); //$NON-NLS-1$
}
private SoundActionComposite editor = null;
private String mediaPath = ""; //$NON-NLS-1$
private ArrayList recentSounds = new ArrayList();
private SoundAction soundAction;
public SoundActionPage() {
if (isWindows())
mediaPath = "C:\\WINNT\\Media\\"; //$NON-NLS-1$
if (isMacOS())
mediaPath = "/System/Library/Sounds"; //$NON-NLS-1$
loadRecentSounds();
}
public void actionDialogCanceled() {
}
public void actionDialogOK() {
saveRecentSounds();
soundAction.setSoundFile(editor.getSoundFile());
}
public void addRecentSound(File soundFile) {
String soundFilePath = soundFile.getAbsolutePath();
int removeIndex = -1;
int fileCount = 0;
for (Iterator iter = recentSounds.iterator(); iter.hasNext() && removeIndex < 0;) {
File element = (File) iter.next();
if (element.getAbsolutePath().equals(soundFilePath))
removeIndex = fileCount;
fileCount++;
}
if (removeIndex >= 0)
recentSounds.remove(removeIndex);
recentSounds.add(soundFile);
if (recentSounds.size() > 10)
recentSounds.remove(0);
}
public Composite createComposite(IBreakpointAction action, Composite composite, int style) {
this.soundAction = (SoundAction) action;
loadRecentSounds();
if (soundAction.getSoundFile() == null && recentSounds.size() > 0)
soundAction.setSoundFile((File) recentSounds.get(0));
editor = new SoundActionComposite(composite, style, this);
return editor;
}
public String getMediaPath() {
return mediaPath;
}
public ArrayList getRecentSounds() {
return recentSounds;
}
public String getSummary() {
if (soundAction.getSoundFile() == null)
return ""; //$NON-NLS-1$
return soundAction.getSoundFile().getAbsolutePath();
}
private void initializeRecentSounds() {
if (isWindows()) {
String defaultSounds[] = { "chimes.wav", "chord.wav", "ding.wav", "notify.wav", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tada.wav" }; //$NON-NLS-1$
for (int i = 0; i < defaultSounds.length; i++) {
File soundFile = new File(mediaPath + defaultSounds[i]);
if (soundFile.exists())
recentSounds.add(soundFile);
}
}
if (isMacOS()) {
File macSounds = new File(mediaPath);
File[] soundFiles = macSounds.listFiles();
for (int i = 0; i < soundFiles.length; i++) {
String fileExtension = new Path(soundFiles[i].getAbsolutePath()).getFileExtension();
if (fileExtension.equalsIgnoreCase("aiff") || fileExtension.equalsIgnoreCase("wav")) //$NON-NLS-1$ //$NON-NLS-2$
recentSounds.add(soundFiles[i]);
}
}
saveRecentSounds();
}
private void loadRecentSounds() {
String recentSoundData = CDebugUIPlugin.getDefault().getPreferenceStore().getString(SOUND_ACTION_RECENT);
if (recentSoundData == null || recentSoundData.length() == 0) {
initializeRecentSounds();
return;
}
recentSounds = new ArrayList();
Element root = null;
DocumentBuilder parser;
try {
parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
root = parser.parse(new InputSource(new StringReader(recentSoundData))).getDocumentElement();
NodeList nodeList = root.getChildNodes();
int entryCount = nodeList.getLength();
for (int i = 0; i < entryCount; i++) {
Node node = nodeList.item(i);
short type = node.getNodeType();
if (type == Node.ELEMENT_NODE) {
Element subElement = (Element) node;
String nodeName = subElement.getNodeName();
if (nodeName.equalsIgnoreCase("soundFileName")) { //$NON-NLS-1$
String value = subElement.getAttribute("name"); //$NON-NLS-1$
if (value == null)
throw new Exception();
File soundFile = new File(value);
if (soundFile.exists()) {
recentSounds.add(soundFile);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (recentSounds.size() == 0)
initializeRecentSounds();
}
public void saveRecentSounds() {
String recentSoundData = ""; //$NON-NLS-1$
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = dfactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("recentSounds"); //$NON-NLS-1$
doc.appendChild(rootElement);
for (Iterator iter = recentSounds.iterator(); iter.hasNext();) {
File soundFile = (File) iter.next();
Element element = doc.createElement("soundFileName"); //$NON-NLS-1$
element.setAttribute("name", soundFile.getAbsolutePath()); //$NON-NLS-1$
rootElement.appendChild(element);
}
ByteArrayOutputStream s = new ByteArrayOutputStream();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
DOMSource source = new DOMSource(doc);
StreamResult outputTarget = new StreamResult(s);
transformer.transform(source, outputTarget);
recentSoundData = s.toString("UTF8"); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
CDebugUIPlugin.getDefault().getPreferenceStore().setValue(SOUND_ACTION_RECENT, recentSoundData);
}
public SoundAction getSoundAction() {
return soundAction;
}
}

View file

@ -124,7 +124,7 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
setConfigurationDefaults(wc, targetProject);
final IStructuredSelection selection = new StructuredSelection(wc.doSave());
final String identifier = new String("org.eclipse.debug.ui.launchGroup.debug"); //$NON-NLS-1$
final String identifier = "org.eclipse.debug.ui.launchGroup.debug"; //$NON-NLS-1$
UIJob openLaunchConfigJob = new UIJob(Messages.AbstractImportExecutableWizard_CreateLaunchConfiguration) {
@ -251,12 +251,12 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
}
public String getDefaultProjectName() {
String defaultName = new String();
String defaultName = ""; //$NON-NLS-1$
String[] executables = getImportExecutablePage()
.getSelectedExecutables();
if (executables.length > 0) {
String fileName = new File(executables[0]).getName();
defaultName = new String(Messages.ImportExecutablePageTwo_DefaultProjectPrefix + fileName);
defaultName = Messages.ImportExecutablePageTwo_DefaultProjectPrefix + fileName;
}
return defaultName;
}