Skip to content

Commit

Permalink
Issue checkstyle#13086: InnerAssignmentCheck failed for one line code…
Browse files Browse the repository at this point in the history
… in Java 14 switch expression
  • Loading branch information
shamithDI authored and sammy227799 committed May 28, 2023
1 parent b35c2e6 commit 7eb5a4e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Expand Up @@ -150,6 +150,7 @@ public class InnerAssignmentCheck
TokenTypes.RESOURCE_SPECIFICATION,
},
{TokenTypes.EXPR, TokenTypes.LAMBDA},
{TokenTypes.EXPR, TokenTypes.SWITCH_RULE},
};

/**
Expand Down
Expand Up @@ -61,6 +61,14 @@ public void testIt() throws Exception {
getPath("InputInnerAssignment.java"), expected);
}

@Test
public void testEnhancedSwitchExpression() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verifyWithInlineConfigParser(
getNonCompilablePath("InputInnerAssignmentWithEnhancedSwitch.java"),
expected);
}

@Test
public void testLambdaExpression() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
Expand Down
@@ -0,0 +1,23 @@
/*
InnerAssignment
*/

//non-compiled with javac: Compilable with Java14
package com.puppycrawl.tools.checkstyle.checks.coding.innerassignment;

public class InputInnerAssignmentWithEnhancedSwitch {

void method(final String operation) {
boolean flag = false;
if (flag = false) {} // violation
switch (operation) {
case "Y" -> flag = true; // no violation
case "N" -> {
flag = false;
}
default -> throw new UnsupportedOperationException();
}
}
}

0 comments on commit 7eb5a4e

Please sign in to comment.