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

Cosmetics

Change-Id: I375dfe970de30bf660d7783c52fb809ecdfd84fe
This commit is contained in:
Sergey Prigogin 2015-12-04 10:18:06 -08:00
parent 2df93034f3
commit 6ba479a6f2

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2011 QNX Software Systems and others. * Copyright (c) 2000, 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,7 +11,6 @@
* Ericsson - Modified for additional features in DSF Reference implementation and bug 219920 * Ericsson - Modified for additional features in DSF Reference implementation and bug 219920
* Onur Akdemir (TUBITAK BILGEM-ITI) - Multi-process debugging (Bug 237306) * Onur Akdemir (TUBITAK BILGEM-ITI) - Multi-process debugging (Bug 237306)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.commands; package org.eclipse.cdt.dsf.mi.service.command.commands;
import java.util.ArrayList; import java.util.ArrayList;
@ -30,15 +29,11 @@ import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput;
* Represents any MI command. * Represents any MI command.
*/ */
public class MICommand<V extends MIInfo> implements ICommand<V> { public class MICommand<V extends MIInfo> implements ICommand<V> {
private static final String[] empty = {};
/* List<Adjustable> fOptions = new ArrayList<>();
* Variables. List<Adjustable> fParameters = new ArrayList<>();
*/ String fOperation = new String();
final static String[] empty = new String[0];
List<Adjustable> fOptions = new ArrayList<Adjustable>();
List<Adjustable> fParameters = new ArrayList<Adjustable>();
String fOperation = new String();
IDMContext fCtx; IDMContext fCtx;
/* /*
@ -62,7 +57,7 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
} }
private final List<Adjustable> optionsToAdjustables(String[] options) { private final List<Adjustable> optionsToAdjustables(String[] options) {
List<Adjustable> result = new ArrayList<Adjustable>(); List<Adjustable> result = new ArrayList<>();
if (options != null) { if (options != null) {
for (String option : options) { for (String option : options) {
result.add(new MIStandardOptionAdjustable(option)); result.add(new MIStandardOptionAdjustable(option));
@ -72,7 +67,7 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
} }
private final List<Adjustable> parametersToAdjustables(String[] parameters) { private final List<Adjustable> parametersToAdjustables(String[] parameters) {
List<Adjustable> result = new ArrayList<Adjustable>(); List<Adjustable> result = new ArrayList<>();
if (parameters != null) { if (parameters != null) {
for (String parameter : parameters) { for (String parameter : parameters) {
result.add(new MIStandardParameterAdjustable(parameter)); result.add(new MIStandardParameterAdjustable(parameter));
@ -86,19 +81,19 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
return controlDmc.getCommandControlFilter(); return controlDmc.getCommandControlFilter();
} }
/* /**
* Returns the operation of this command. * Returns the operation of this command.
*/ */
public String getOperation() { public String getOperation() {
return fOperation; return fOperation;
} }
/* /**
* Returns an array of command's options. An empty collection is * Returns an array of command's options. An empty collection is
* returned if there are no options. * returned if there are no options.
*/ */
public String[] getOptions() { public String[] getOptions() {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Adjustable option : fOptions) { for (Adjustable option : fOptions) {
result.add(option.getValue()); result.add(option.getValue());
} }
@ -109,12 +104,12 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
fOptions = optionsToAdjustables(options); fOptions = optionsToAdjustables(options);
} }
/* /**
* Returns an array of command's parameters. An empty collection is * Returns an array of command's parameters. An empty collection is
* returned if there are no parameters. * returned if there are no parameters.
*/ */
public String[] getParameters() { public String[] getParameters() {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Adjustable parameter : fParameters) { for (Adjustable parameter : fParameters) {
result.add(parameter.getValue()); result.add(parameter.getValue());
} }
@ -129,16 +124,16 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
fParameters = Arrays.asList(params); fParameters = Arrays.asList(params);
} }
/* /**
* Returns the constructed command without using the --thread/--frame options. * Returns the constructed command without using the --thread/--frame options.
*/ */
public String constructCommand() { public String constructCommand() {
return constructCommand(null, -1); return constructCommand(null, -1);
} }
/*
* Returns the constructed command potentially using the --thread/--frame options.
*/
/** /**
* Returns the constructed command potentially using the --thread/--frame options.
*
* @since 1.1 * @since 1.1
*/ */
public String constructCommand(String threadId, int frameId) { public String constructCommand(String threadId, int frameId) {
@ -147,20 +142,21 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
/** /**
* With GDB 7.1 the --thread-group option is used to support multiple processes. * With GDB 7.1 the --thread-group option is used to support multiple processes.
*
* @since 4.0 * @since 4.0
*/ */
public String constructCommand(String groupId, String threadId, int frameId) { public String constructCommand(String groupId, String threadId, int frameId) {
StringBuffer command = new StringBuffer(getOperation()); StringBuilder command = new StringBuilder(getOperation());
// Add the --thread option // Add the --thread option
if (supportsThreadAndFrameOptions() && threadId != null && threadId.trim().length() > 0) { if (supportsThreadAndFrameOptions() && threadId != null && !threadId.trim().isEmpty()) {
command.append(" --thread " + threadId); //$NON-NLS-1$ command.append(" --thread " + threadId); //$NON-NLS-1$
// Add the --frame option, but only if we are using the --thread option // Add the --frame option, but only if we are using the --thread option
if (frameId >= 0) { if (frameId >= 0) {
command.append(" --frame " + frameId); //$NON-NLS-1$ command.append(" --frame " + frameId); //$NON-NLS-1$
} }
} else if (supportsThreadGroupOption() && groupId != null && groupId.trim().length() > 0) { } else if (supportsThreadGroupOption() && groupId != null && !groupId.trim().isEmpty()) {
// The --thread-group option is only allowed if we are not using the --thread option // The --thread-group option is only allowed if we are not using the --thread option
command.append(" --thread-group " + groupId); //$NON-NLS-1$ command.append(" --thread-group " + groupId); //$NON-NLS-1$
} }
@ -181,25 +177,21 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
// * Checks to see if the current command can be coalesced with the // * Checks to see if the current command can be coalesced with the
// * supplied command. // * supplied command.
// */ // */
// public boolean canCoalesce( ICommand<? extends ICommandResult> command ) { // public boolean canCoalesce(ICommand<? extends ICommandResult> command) {
// return false ; // return false;
// } // }
/*
* Takes the supplied command and coalesces it with this one.
* The result is a new third command which represent the two
* original command.
*/
@Override @Override
public ICommand<? extends ICommandResult> coalesceWith( ICommand<? extends ICommandResult> command ) { public ICommand<? extends ICommandResult> coalesceWith(ICommand<? extends ICommandResult> command) {
return null ; return null;
} }
@Override @Override
public IDMContext getContext(){ public IDMContext getContext() {
return fCtx; return fCtx;
} }
/** /**
* Produces the corresponding ICommandResult result for this * Produces the corresponding ICommandResult result for this
* command. * command.
@ -207,11 +199,11 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
* @return result for this command * @return result for this command
*/ */
public MIInfo getResult(MIOutput MIresult) { public MIInfo getResult(MIOutput MIresult) {
return ( new MIInfo(MIresult) ); return new MIInfo(MIresult);
} }
protected String optionsToString() { protected String optionsToString() {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
if (fOptions != null && !fOptions.isEmpty()) { if (fOptions != null && !fOptions.isEmpty()) {
for (Adjustable option : fOptions) { for (Adjustable option : fOptions) {
sb.append(option.getAdjustedValue()); sb.append(option.getAdjustedValue());
@ -222,13 +214,13 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
protected String parametersToString() { protected String parametersToString() {
String[] options = getOptions(); String[] options = getOptions();
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
if (fParameters != null && !fParameters.isEmpty()) { if (fParameters != null && !fParameters.isEmpty()) {
// According to GDB/MI spec // According to GDB/MI spec
// Add a "--" separator if any parameters start with "-" // Add a "--" separator if any parameters start with "-"
if (options != null && options.length > 0) { if (options != null && options.length > 0) {
for (Adjustable parameter : fParameters) { for (Adjustable parameter : fParameters) {
if (parameter.getValue().startsWith("-")) {//$NON-NLS-1$ if (parameter.getValue().startsWith("-")) { //$NON-NLS-1$
buffer.append('-').append('-'); buffer.append('-').append('-');
break; break;
} }
@ -254,21 +246,25 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
/** /**
* @since 1.1 * @since 1.1
*/ */
public boolean supportsThreadAndFrameOptions() { return true; } public boolean supportsThreadAndFrameOptions() {
return true;
}
/** /**
* @since 4.0 * @since 4.0
*/ */
public boolean supportsThreadGroupOption() { return true; } public boolean supportsThreadGroupOption() {
return true;
}
/** /**
* Compare commands based on the MI command string that they generate, * Compares commands based on the MI command string that they generate,
* without the token. * without the token.
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj instanceof MICommand<?>){ if (obj instanceof MICommand<?>) {
MICommand<?> otherCmd = (MICommand<?>)obj; MICommand<?> otherCmd = (MICommand<?>) obj;
return ((fCtx == null && otherCmd.fCtx == null) || (fCtx != null && fCtx.equals(otherCmd.fCtx))) && return ((fCtx == null && otherCmd.fCtx == null) || (fCtx != null && fCtx.equals(otherCmd.fCtx))) &&
constructCommand().equals(otherCmd.constructCommand()); constructCommand().equals(otherCmd.constructCommand());
} }
@ -344,7 +340,7 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
} }
// Although this change makes sense, it could have impacts on many // Although this change makes sense, it could have impacts on many
// different commands we send to GDB. The risk outways the benefits, // different commands we send to GDB. The risk outweighs the benefits,
// so we comment it out. See bugs 412471 and 414959 for details. // so we comment it out. See bugs 412471 and 414959 for details.
// //
// // an empty parameter can be passed with two single quotes // // an empty parameter can be passed with two single quotes
@ -357,7 +353,6 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
} }
public static abstract class MICommandAdjustable implements Adjustable { public static abstract class MICommandAdjustable implements Adjustable {
protected final String value; protected final String value;
/** /**