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,12 +205,10 @@ 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) {
}
}
if (type != null) {
if (!priv && type.supportsMode(ILaunchManager.RUN_MODE) && equalCategories(type.getCategory(), "org.eclipse.ui.externaltools") //$NON-NLS-1$
&& !WorkbenchActivityHelper.filterItem(new LaunchConfigurationTypeContribution(type)))

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

@ -111,7 +111,7 @@ public class SoundActionPage extends PlatformObject implements IBreakpointAction
public String getSummary() {
if (soundAction.getSoundFile() == null)
return new String(""); //$NON-NLS-1$
return ""; //$NON-NLS-1$
return soundAction.getSoundFile().getAbsolutePath();
}
@ -190,7 +190,7 @@ public class SoundActionPage extends PlatformObject implements IBreakpointAction
}
public void saveRecentSounds() {
String recentSoundData = new String(""); //$NON-NLS-1$
String recentSoundData = ""; //$NON-NLS-1$
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;

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;
}