mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Cosmetics
Change-Id: I375dfe970de30bf660d7783c52fb809ecdfd84fe
This commit is contained in:
parent
2df93034f3
commit
6ba479a6f2
1 changed files with 69 additions and 74 deletions
|
@ -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,17 +29,13 @@ 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 = {};
|
||||||
/*
|
|
||||||
* Variables.
|
List<Adjustable> fOptions = new ArrayList<>();
|
||||||
*/
|
List<Adjustable> fParameters = new ArrayList<>();
|
||||||
final static String[] empty = new String[0];
|
String fOperation = new String();
|
||||||
|
|
||||||
List<Adjustable> fOptions = new ArrayList<Adjustable>();
|
|
||||||
List<Adjustable> fParameters = new ArrayList<Adjustable>();
|
|
||||||
String fOperation = new String();
|
|
||||||
IDMContext fCtx;
|
IDMContext fCtx;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructors.
|
* Constructors.
|
||||||
*/
|
*/
|
||||||
|
@ -48,11 +43,11 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
|
||||||
public MICommand(IDMContext ctx, String operation) {
|
public MICommand(IDMContext ctx, String operation) {
|
||||||
this(ctx, operation, empty, empty);
|
this(ctx, operation, empty, empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MICommand(IDMContext ctx, String operation, String[] params) {
|
public MICommand(IDMContext ctx, String operation, String[] params) {
|
||||||
this(ctx, operation, empty, params);
|
this(ctx, operation, empty, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MICommand(IDMContext ctx, String operation, String[] options, String[] params) {
|
public MICommand(IDMContext ctx, String operation, String[] options, String[] params) {
|
||||||
assert(ctx != null && DMContexts.getAncestorOfType(ctx, MIControlDMContext.class) != null);
|
assert(ctx != null && DMContexts.getAncestorOfType(ctx, MIControlDMContext.class) != null);
|
||||||
fCtx = ctx;
|
fCtx = ctx;
|
||||||
|
@ -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));
|
||||||
|
@ -70,9 +65,9 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
@ -80,25 +75,25 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCommandControlFilter() {
|
public String getCommandControlFilter() {
|
||||||
MIControlDMContext controlDmc = DMContexts.getAncestorOfType(getContext(), MIControlDMContext.class);
|
MIControlDMContext controlDmc = DMContexts.getAncestorOfType(getContext(), MIControlDMContext.class);
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
@ -128,17 +123,17 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
|
||||||
public void setParameters(Adjustable... params) {
|
public void setParameters(Adjustable... params) {
|
||||||
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$
|
||||||
}
|
}
|
||||||
|
@ -176,42 +172,38 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
|
||||||
command.append('\n');
|
command.append('\n');
|
||||||
return command.toString();
|
return command.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// /*
|
// /*
|
||||||
// * 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
|
|
||||||
public ICommand<? extends ICommandResult> coalesceWith( ICommand<? extends ICommandResult> command ) {
|
|
||||||
return null ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IDMContext getContext(){
|
public ICommand<? extends ICommandResult> coalesceWith(ICommand<? extends ICommandResult> command) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IDMContext getContext() {
|
||||||
return fCtx;
|
return fCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produces the corresponding ICommandResult result for this
|
* Produces the corresponding ICommandResult result for this
|
||||||
* command.
|
* command.
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
@ -250,36 +242,40 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return constructCommand().hashCode();
|
return constructCommand().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return constructCommand();
|
return constructCommand();
|
||||||
|
@ -342,11 +338,11 @@ public class MICommand<V extends MIInfo> implements ICommand<V> {
|
||||||
builder.insert(0, '"');
|
builder.insert(0, '"');
|
||||||
builder.append('"');
|
builder.append('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// if (builder.length() == 0) {
|
// if (builder.length() == 0) {
|
||||||
// builder.append("''"); //$NON-NLS-1$
|
// builder.append("''"); //$NON-NLS-1$
|
||||||
|
@ -357,12 +353,11 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*
|
*
|
||||||
* @param builder
|
* @param builder
|
||||||
* The string builder is an optimization option, if two
|
* The string builder is an optimization option, if two
|
||||||
* commands are not processed at the same time a shared
|
* commands are not processed at the same time a shared
|
||||||
|
|
Loading…
Add table
Reference in a new issue