Bug 539416 - [12] Debugging with Switch Expressions

Change-Id: I091e63cb8435203dc9b1872e16b5ec63cce2df3a
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java
index 5a9d0d3..8dd0381 100644
--- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java
+++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java
@@ -11,7 +11,7 @@
  * This is an implementation of an early-draft specification developed under the Java
  * Community Process (JCP) and is made available for testing and evaluation purposes
  * only. The code is not compatible with any specification of the JCP.
- * 
+ *
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *     Jesper Steen Moller - Bug 427089
@@ -541,8 +541,9 @@
 	 */
 	@Override
 	public void endVisit(ArrayAccess node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		ITypeBinding typeBinding = node.getIndex().resolveTypeBinding();
 		if (typeBinding != null && unBoxing(typeBinding)) {
 			// un-box the index, if required
@@ -556,8 +557,9 @@
 	 */
 	@Override
 	public void endVisit(ArrayCreation node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -566,8 +568,9 @@
 	 */
 	@Override
 	public void endVisit(ArrayInitializer node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -576,8 +579,9 @@
 	 */
 	@Override
 	public void endVisit(ArrayType node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -594,8 +598,9 @@
 	 */
 	@Override
 	public void endVisit(Assignment node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -604,8 +609,9 @@
 	 */
 	@Override
 	public void endVisit(Block node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -614,8 +620,9 @@
 	 */
 	@Override
 	public void endVisit(BooleanLiteral node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -624,8 +631,9 @@
 	 */
 	@Override
 	public void endVisit(BreakStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -634,8 +642,9 @@
 	 */
 	@Override
 	public void endVisit(CastExpression node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -652,8 +661,9 @@
 	 */
 	@Override
 	public void endVisit(CharacterLiteral node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -662,8 +672,9 @@
 	 */
 	@Override
 	public void endVisit(ClassInstanceCreation node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -682,8 +693,9 @@
 	 */
 	@Override
 	public void endVisit(ConditionalExpression node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		// Get the instructions
 		int ifFalseAddress = fInstructions.getEnd();
@@ -723,8 +735,9 @@
 	 */
 	@Override
 	public void endVisit(ContinueStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -733,8 +746,9 @@
 	 */
 	@Override
 	public void endVisit(DoStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		/*
 		 * The structure of generated instructions is :
@@ -789,8 +803,9 @@
 	 */
 	@Override
 	public void endVisit(EmptyStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -803,8 +818,9 @@
 	 */
 	@Override
 	public void endVisit(EnhancedForStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		/*
 		 * The structure of generated instructions is :
@@ -870,8 +886,9 @@
 	 */
 	@Override
 	public void endVisit(ExpressionStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		addPopInstructionIfNeeded(node.getExpression());
 	}
@@ -881,8 +898,9 @@
 	 */
 	@Override
 	public void endVisit(FieldAccess node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -899,8 +917,9 @@
 	 */
 	@Override
 	public void endVisit(ForStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		/*
 		 * The structure of generated instructions is :
@@ -981,8 +1000,9 @@
 	 */
 	@Override
 	public void endVisit(IfStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		boolean hasElseStatement = node.getElseStatement() != null;
 
@@ -1055,8 +1075,9 @@
 	 */
 	@Override
 	public void endVisit(InstanceofExpression node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1073,8 +1094,9 @@
 	 */
 	@Override
 	public void endVisit(LabeledStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		String label = node.getLabel().getIdentifier();
 
@@ -1108,8 +1130,9 @@
 	 */
 	@Override
 	public void endVisit(MethodInvocation node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1118,8 +1141,9 @@
 	 */
 	@Override
 	public void endVisit(NullLiteral node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1128,8 +1152,9 @@
 	 */
 	@Override
 	public void endVisit(NumberLiteral node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1146,8 +1171,9 @@
 	 */
 	@Override
 	public void endVisit(ParameterizedType node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1164,8 +1190,9 @@
 	 */
 	@Override
 	public void endVisit(PostfixExpression node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1174,8 +1201,9 @@
 	 */
 	@Override
 	public void endVisit(PrefixExpression node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1184,8 +1212,9 @@
 	 */
 	@Override
 	public void endVisit(PrimitiveType node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1201,8 +1230,9 @@
 	 */
 	@Override
 	public void endVisit(QualifiedType node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1211,8 +1241,9 @@
 	 */
 	@Override
 	public void endVisit(ReturnStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1221,8 +1252,9 @@
 	 */
 	@Override
 	public void endVisit(SimpleName node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1231,8 +1263,9 @@
 	 */
 	@Override
 	public void endVisit(SimpleType node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1241,8 +1274,9 @@
 	 */
 	@Override
 	public void endVisit(SingleVariableDeclaration node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1251,8 +1285,9 @@
 	 */
 	@Override
 	public void endVisit(StringLiteral node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1269,8 +1304,9 @@
 	 */
 	@Override
 	public void endVisit(SuperFieldAccess node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1279,8 +1315,9 @@
 	 */
 	@Override
 	public void endVisit(SuperMethodInvocation node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1313,8 +1350,9 @@
 	 */
 	@Override
 	public void endVisit(ThisExpression node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1323,8 +1361,9 @@
 	 */
 	@Override
 	public void endVisit(ThrowStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1357,8 +1396,9 @@
 	 */
 	@Override
 	public void endVisit(TypeLiteral node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1375,8 +1415,9 @@
 	 */
 	@Override
 	public void endVisit(VariableDeclarationFragment node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 		storeInstruction();
 	}
 
@@ -1393,8 +1434,9 @@
 	 */
 	@Override
 	public void endVisit(WhileStatement node) {
-		if (!isActive() || hasErrors())
+		if (!isActive() || hasErrors()) {
 			return;
+		}
 
 		/*
 		 * The structure of generated instructions is :
@@ -3897,6 +3939,16 @@
 		return false;
 	}
 
+	@Override
+	public boolean visit(SwitchExpression node) {
+		if (!isActive()) {
+			return true;
+		}
+		setHasError(true);
+		addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Switch_expressions_cannot_be_used_in_an_evaluation_expression);
+		return false;
+	}
+
 	/**
 	 * @see ASTVisitor#visit(SwitchCase)
 	 */
@@ -3947,6 +3999,10 @@
 							} else {
 								push(new EqualEqualOperator(Instruction.T_int, Instruction.T_int, true, fCounter));
 							}
+							push(new Dup());
+							storeInstruction(); // dupe
+							((Expression) expression).accept(this);
+							storeInstruction(); // equal-equal
 						}
 					} else {
 						if (switchCase.getExpression() instanceof StringLiteral) {
@@ -3954,11 +4010,11 @@
 						} else {
 							push(new EqualEqualOperator(Instruction.T_int, Instruction.T_int, true, fCounter));
 						}
+						push(new Dup());
+						storeInstruction(); // dupe
+						switchCase.getExpression().accept(this);
+						storeInstruction(); // equal-equal
 					}
-					push(new Dup());
-					storeInstruction(); // dupe
-					switchCase.getExpression().accept(this);
-					storeInstruction(); // equal-equal
 					ConditionalJump condJump = new ConditionalJump(true);
 					push(condJump);
 					storeInstruction(); // conditional jump
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java
index f4ee002..f934212 100644
--- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java
+++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -8,6 +8,10 @@
  *
  * SPDX-License-Identifier: EPL-2.0
  *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
  * Contributors:
  * IBM - Initial API and implementation
  * Jesper Steen Moller - 427089: [1.8] Change value in Variables view with lambda or method reference
@@ -61,6 +65,7 @@
 
 	public static String ASTInstructionCompiler_Lambda_expressions_cannot_be_used_in_an_evaluation_expression;
 	public static String ASTInstructionCompiler_Reference_expressions_cannot_be_used_in_an_evaluation_expression;
+	public static String ASTInstructionCompiler_Switch_expressions_cannot_be_used_in_an_evaluation_expression;
 
 	static {
 		// load message values from bundle file
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.properties b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.properties
index 330af7a..fa85d7a 100644
--- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.properties
+++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2015 IBM Corporation and others.
+# Copyright (c) 2000, 2019 IBM Corporation and others.
 #
 # This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License 2.0
@@ -8,6 +8,10 @@
 #
 # SPDX-License-Identifier: EPL-2.0
 #
+# This is an implementation of an early-draft specification developed under the Java
+# Community Process (JCP) and is made available for testing and evaluation purposes
+# only. The code is not compatible with any specification of the JCP.
+ 
 # Contributors:
 #     IBM Corporation - initial API and implementation
 # Jesper Steen Moller - 427089: [1.8] Change value in Variables view with lambda or method reference
@@ -56,4 +60,5 @@
 ArrayRuntimeContext_0=Unable to retrieve type for java.lang.Object
 
 ASTInstructionCompiler_Lambda_expressions_cannot_be_used_in_an_evaluation_expression=Lambda expressions cannot be used in an evaluation expression
-ASTInstructionCompiler_Reference_expressions_cannot_be_used_in_an_evaluation_expression=Reference expressions cannot be used in an evaluation expression
\ No newline at end of file
+ASTInstructionCompiler_Reference_expressions_cannot_be_used_in_an_evaluation_expression=Reference expressions cannot be used in an evaluation expression
+ASTInstructionCompiler_Switch_expressions_cannot_be_used_in_an_evaluation_expression=Switch expressions cannot be used in an evaluation expression
\ No newline at end of file