diff options
2 files changed, 78 insertions, 71 deletions
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFContextQueryExpressionDialog.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFContextQueryExpressionDialog.java index 270c8535d..1a2e65016 100644 --- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFContextQueryExpressionDialog.java +++ b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFContextQueryExpressionDialog.java @@ -29,7 +29,8 @@ import org.eclipse.ui.dialogs.SelectionDialog; public class TCFContextQueryExpressionDialog extends SelectionDialog { private String expression; - private String[] attributeList; + final private String originalExpression; + final private String[] attributeList; private ParameterDataModel[] parameterData; final String[] columnNames = new String[] {"Parameter","Value"}; @@ -37,6 +38,7 @@ public class TCFContextQueryExpressionDialog extends SelectionDialog { super(parentShell); setShellStyle(getShellStyle() | SWT.RESIZE); expression = initialExpression; + originalExpression = initialExpression; attributeList = attributes; } @@ -51,15 +53,18 @@ public class TCFContextQueryExpressionDialog extends SelectionDialog { return getParameterInitialValue(comparator,indexExpr+1); } } - int startOfVal = expression.indexOf ('=', indexExpr) + 1; - int endOfVal = -1; - if (startOfVal != 0) { - endOfVal = expression.indexOf (',', startOfVal); - if (endOfVal == -1) { - endOfVal = expression.length(); + int startOfVal = expression.indexOf ('=', indexExpr); + if (startOfVal != -1) { + startOfVal += 1; + int endOfVal = -1; + if (startOfVal != 0) { + endOfVal = expression.indexOf (',', startOfVal); + if (endOfVal == -1) { + endOfVal = expression.length(); + } } + return expression.substring(startOfVal, endOfVal); } - return expression.substring(startOfVal, endOfVal); } } return null; @@ -167,6 +172,33 @@ public class TCFContextQueryExpressionDialog extends SelectionDialog { return indexExpr; } + private boolean replaceParameter(String parameter, String replaceString, int index) { + if (index != 0) { + String testChar = expression.substring(index+parameter.length(), index+1+parameter.length()); + if (!testChar.equals("=")) { + return false; + } + testChar = expression.substring(index-1, index); + if (!testChar.equals(",")) { + return false; + } + else { + index-=1; + } + } + int endLocation = expression.indexOf(',', index+1); + if (endLocation == -1) { + endLocation = expression.length(); + } + else if (index == 0 && replaceString.length() == 0) { + endLocation++; + } + String removeStr = expression.substring(index, endLocation); + expression = expression.replace(removeStr, replaceString); + + return true; + } + public final class CellEditorListener implements ICellEditorListener { private ValueCellEditor fcellEditor; public CellEditorListener(ValueCellEditor cellEditor) { @@ -189,47 +221,33 @@ public class TCFContextQueryExpressionDialog extends SelectionDialog { expression = new String(paramName + "=" + cellString); } else { - String nameValuePair = paramName + "=" + cellString ; - if (expression.lastIndexOf(nameValuePair) == -1) { - expression +=","; - expression += nameValuePair; + String nameValuePair = paramName + "=" + cellString; + int strIndex = findParameter(paramName, 0); + if (strIndex == -1) { + expression += "," + nameValuePair; + } + else { + if (strIndex != 0) { + nameValuePair = "," + nameValuePair; + } + if (!replaceParameter(paramName,nameValuePair,strIndex)) { + getButton(IDialogConstants.OK_ID).setEnabled(false); + } } } param.setData(cellString); - getButton(IDialogConstants.OK_ID).setEnabled(true); } else if (expression != null && expression.length() != 0){ fcellEditor.setValue(cellString); - // Check to remove expression value. int strIndex = findParameter(paramName, 0); if (strIndex != -1) { - if (strIndex != 0) { - String testChar = expression.substring(strIndex+paramName.length(), strIndex+1+paramName.length()); - if (!testChar.equals("=")) { - // malformed expression - getButton(IDialogConstants.OK_ID).setEnabled(false); - return; - } - testChar = expression.substring(strIndex-1, strIndex); - if (!testChar.equals(",")) { - // malformed expression - getButton(IDialogConstants.OK_ID).setEnabled(false); - return; - } - else { - strIndex-=1; - } - } - int endLocation = expression.indexOf(',', strIndex+1); - if (endLocation == -1) { - endLocation = expression.length(); + if (!replaceParameter(paramName,"",strIndex)) { + getButton(IDialogConstants.OK_ID).setEnabled(false); } - String removeStr = expression.substring(strIndex, endLocation); - expression = expression.replace(removeStr, ""); param.setData(""); } } - if (expression != null && expression.length() == 0) { + if (expression == null || expression.length() == 0 || originalExpression.contentEquals(expression)) { getButton(IDialogConstants.OK_ID).setEnabled(false); } else { diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFThreadFilterEditor.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFThreadFilterEditor.java index 1cf99242c..1baf57b69 100644 --- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFThreadFilterEditor.java +++ b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/breakpoints/TCFThreadFilterEditor.java @@ -388,42 +388,31 @@ public class TCFThreadFilterEditor { return result; } - boolean missingParameterValue(String expression) { + boolean missingParameterValue(String expression, int fromIndex) { boolean result = false; int lastIndex = expression.length(); - int fromIndex = 0; - if (lastIndex != 0) { - fromIndex = expression.indexOf('=', fromIndex); - if (fromIndex == -1) { - result = true; - } - else { - fromIndex = 0; - } - while (fromIndex != -1) { - fromIndex = expression.indexOf('=', fromIndex); - if (fromIndex != -1) { - if (fromIndex == 0 || fromIndex == lastIndex-1) { - result = true; - break; - } - else { - String testChar = expression.substring(fromIndex-1, fromIndex); - String testNextChar = expression.substring(fromIndex+1,fromIndex+2); - int foundComma = expression.indexOf(',', fromIndex); - if (testChar.matches("[,\\s]") || testNextChar.matches("[,\\s]")) { - result = true; - break; - } - else if (foundComma != -1 && expression.indexOf('=', fromIndex) != -1) { - result = true; - } - else { - result = false; - } - fromIndex++; - } + if (lastIndex != 0 && fromIndex <= lastIndex) { + String failPattern = new String("[=,\\s]"); + int equalsIndex = expression.indexOf('=', fromIndex); + int commaIndex = expression.indexOf(',', fromIndex); + int nextEqualsIndex = expression.indexOf('=',equalsIndex+1); + if (commaIndex == lastIndex-1 || equalsIndex == -1 || equalsIndex == lastIndex-1) { + return true; + } + String testChar = expression.substring(equalsIndex-1, equalsIndex); + String testNextChar = expression.substring(equalsIndex+1,equalsIndex+2); + if (testChar.matches(failPattern) || testNextChar.matches(failPattern) || + (commaIndex != -1 && commaIndex < equalsIndex) || + (nextEqualsIndex != -1 && (commaIndex == -1 || nextEqualsIndex < commaIndex))) { + return true; + } + if (commaIndex!=-1) { + testChar = expression.substring(commaIndex-1, commaIndex); + testNextChar = expression.substring(commaIndex+1,commaIndex+2); + if (testChar.matches(failPattern) || testNextChar.matches(failPattern)) { + return true; } + result = missingParameterValue(expression, commaIndex+1); } } return result; @@ -432,7 +421,7 @@ public class TCFThreadFilterEditor { private class ExpressionModifier implements ModifyListener { public void modifyText(ModifyEvent e) { String expression = scopeExprCombo.getText(); - if (missingParameterValue(expression)) { + if (missingParameterValue(expression, 0)) { scopeExpressionDecoration.show(); fPage.setErrorMessage(Messages.TCFThreadFilterEditorFormatError); fPage.setValid(false); |