diff options
author | Sarika Sinha | 2015-10-06 15:32:13 +0000 |
---|---|---|
committer | Sarika Sinha | 2015-10-06 15:32:13 +0000 |
commit | 5128ef1b51f8e0bf8decf026045f4844bf406532 (patch) | |
tree | c0e58e9f10e4b5679524ed888d07f1e76eb92454 | |
parent | 6c2773055bf371afa17b6cbf9cbb46f0228baad7 (diff) | |
download | eclipse.jdt.debug-5128ef1b51f8e0bf8decf026045f4844bf406532.tar.gz eclipse.jdt.debug-5128ef1b51f8e0bf8decf026045f4844bf406532.tar.xz eclipse.jdt.debug-5128ef1b51f8e0bf8decf026045f4844bf406532.zip |
Revert "Bug 389871 - [breakpoints] same condition accepted in one case but not another (be more tolerant)"I20151013-0800
This reverts commit 6c2773055bf371afa17b6cbf9cbb46f0228baad7.
-rw-r--r-- | org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java index 33872d586..d752a0f29 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java @@ -66,17 +66,24 @@ public class EvaluationSourceGenerator { this(new String[0], new String[0], codeSnippet); } + protected String getCompleteSnippet(String codeSnippet) { + + if (isExpression(codeSnippet)) { + codeSnippet = "return " + codeSnippet + ';'; //$NON-NLS-1$ + } + return codeSnippet; + } + /** - * Returns the completed codeSnippet by adding required semicolon and - * return + * Returns whether the given snippet represents an expression. This is + * determined by examining the snippet for non-quoted semicolons. + * + * Returns <code>true</code> if the snippet is an expression, or + * <code>false</code> if the expression contains a statement. */ - protected String getCompleteSnippet(String codeSnippet) { - codeSnippet = codeSnippet.trim(); // remove whitespaces at the end + protected boolean isExpression(String codeSnippet) { boolean inString = false; byte[] chars = codeSnippet.getBytes(); - - int semicolonIndex = -1; - int lastSemilcolonIndex = -1; for (int i = 0, numChars = chars.length; i < numChars; i++) { switch (chars[i]) { case '\\': @@ -89,44 +96,13 @@ public class EvaluationSourceGenerator { inString = !inString; break; case ';': - if (!inString) { // mark the last 2 semicolon - semicolonIndex = lastSemilcolonIndex; - lastSemilcolonIndex = i; + if (!inString) { + return false; } break; } } - StringBuffer wordBuffer = new StringBuffer(); - // if semicolon missing at the end - if (lastSemilcolonIndex != chars.length-1) - semicolonIndex = lastSemilcolonIndex; - int i ; - for (i=0; i < chars.length; i++) { - // copy everything before the last statement or if whitespace - if (i<= semicolonIndex || Character.isWhitespace(chars[i]) || chars[i] == '}'){ - wordBuffer.append(codeSnippet.charAt(i)); - } - else - break; - } - String returnString = "return ";//$NON-NLS-1$ - // don't add return if it there in some condition - int index = codeSnippet.lastIndexOf(returnString); - if (index > i){ - if (!Character.isWhitespace(chars[index-1]) || !(Character.isWhitespace(chars[index+6]) || chars[index+6] == '}')) - wordBuffer.append(returnString); - } else if (chars[chars.length -1] !='}' && ( i+7 > chars.length || (i + 7 <= chars.length && !codeSnippet.substring(i, i+6).equals("return")))){ //$NON-NLS-1$ - // add return if last statement does not have return - wordBuffer.append("return "); //$NON-NLS-1$ - } - for (; i < chars.length; i++) { - // copy the last statement - wordBuffer.append(codeSnippet.charAt(i)); - } - // add semicolon at the end if missing - if (chars[chars.length -1] !=';' && chars[chars.length -1] !='}') - wordBuffer.append(';'); - return wordBuffer.toString(); + return true; } public String getCompilationUnitName() { |