diff options
author | Manoj Palat | 2018-11-27 04:48:39 +0000 |
---|---|---|
committer | Manoj Palat | 2018-11-27 04:48:39 +0000 |
commit | 39d2fb46bd356e8adf1226a0e837d63099d5aad9 (patch) | |
tree | 5b97e5dc17ad4f2f10c4300f2ea3c48d5fb6e00b | |
parent | 1dc171831b809cfe7579cefd121518c46dd57b5d (diff) | |
download | eclipse.jdt.core-39d2fb46bd356e8adf1226a0e837d63099d5aad9.tar.gz eclipse.jdt.core-39d2fb46bd356e8adf1226a0e837d63099d5aad9.tar.xz eclipse.jdt.core-39d2fb46bd356e8adf1226a0e837d63099d5aad9.zip |
normal completion error message addition
5 files changed, 34 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java index 0ded539806..bfc4aec94b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java @@ -2082,5 +2082,7 @@ void setSourceStart(int sourceStart); int SwitchExpressionsEmptySwitchBlock = TypeRelated + 1601; /** @since 3.16 BETA_JAVA_12 */ int SwitchExpressionsNoResultExpression = TypeRelated + 1602; + /** @since 3.16 BETA_JAVA_12 */ + int SwitchExpressionBlockCompletesNormally = TypeRelated + 1603; -} + } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java index 5ad1dd5bf5..88b3352a14 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java @@ -56,6 +56,21 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression return this.expressionContext; } @Override + protected int getFallThroughState(Statement stmt, BlockScope blockScope) { + if (stmt instanceof Expression || stmt instanceof ThrowStatement) + return BREAKING; + if (stmt instanceof Block) { + Block block = (Block) stmt; + if (block.doesNotCompleteNormally()) { + return BREAKING; + } + //JLS 12 15.29.1 Given a switch expression, if the switch block consists of switch labeled rules, + //then it is a compile-time error if any switch labeled block can complete normally. + blockScope.problemReporter().switchExpressionBlockCompletesNormally(block); + } + return FALLTHROUGH; + } + @Override public Expression[] getPolyExpressions() { List<Expression> polys = new ArrayList<>(); for (Expression e : this.resultExpressions) { @@ -139,16 +154,15 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression } @Override public boolean visit(SwitchExpression switchExpression, BlockScope blockScope) { - return false; + return false; } - @SuppressWarnings("synthetic-access") @Override public boolean visit(BreakStatement breakStatement, BlockScope blockScope) { if (breakStatement.expression != null) { this.targetSwitchExpression.resultExpressions.add(breakStatement.expression); breakStatement.switchExpression = this.targetSwitchExpression; } - return false; + return false; } @Override public boolean visit(DoStatement stmt, BlockScope blockScope) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java index f822adc019..e8dbebed01 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java @@ -61,6 +61,7 @@ public class SwitchStatement extends Expression { public final static int CASE = 0; public final static int FALLTHROUGH = 1; public final static int ESCAPING = 2; + public final static int BREAKING = 3; // for switch on strings private static final char[] SecretStringVariableName = " switchDispatchString".toCharArray(); //$NON-NLS-1$ @@ -76,6 +77,9 @@ public class SwitchStatement extends Expression { int duplicateCaseStatementsCounter = 0; private LocalVariableBinding dispatchStringCopy = null; + protected int getFallThroughState(Statement stmt, BlockScope blockScope) { + return FALLTHROUGH; + } @Override public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { try { @@ -120,7 +124,7 @@ public class SwitchStatement extends Expression { complaintLevel = initialComplaintLevel; // reset complaint fallThroughState = CASE; } else { - fallThroughState = FALLTHROUGH; // reset below if needed + fallThroughState = getFallThroughState(statement, currentScope); // reset below if needed } if ((complaintLevel = statement.complainIfUnreachable(caseInits, this.scope, complaintLevel, true)) < Statement.COMPLAINED_UNREACHABLE) { caseInits = statement.analyseCode(this.scope, switchContext, caseInits); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index ca6c29b9b8..ce850386ee 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -11030,4 +11030,12 @@ public void switchExpressionNoResultExpressions(SwitchExpression expression) { expression.sourceStart, expression.sourceEnd); } +public void switchExpressionBlockCompletesNormally(Block block) { + this.handle( + IProblem.SwitchExpressionBlockCompletesNormally, + NoArgument, + NoArgument, + block.sourceStart, + block.sourceEnd); +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties index 33bc2745a6..9ab86a89e1 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties @@ -970,8 +970,7 @@ 1600 = Incompatible switch results expressions {0} 1601 = A switch expression should have a non-empty switch block 1602 = A switch expression {0} should have at least one result expression -1603 = The switch over the enum type {0} should have a default case -1604 = The switch expression should have a default case +1603 = The switch block in a switch expression should not complete normally ### ELABORATIONS |