|
59 | 59 | import static org.sonar.plugins.java.api.tree.Tree.Kind.DEFAULT_PATTERN; |
60 | 60 | import static org.sonar.plugins.java.api.tree.Tree.Kind.DO_STATEMENT; |
61 | 61 | import static org.sonar.plugins.java.api.tree.Tree.Kind.EQUAL_TO; |
| 62 | +import static org.sonar.plugins.java.api.tree.Tree.Kind.EXTENDS_WILDCARD; |
62 | 63 | import static org.sonar.plugins.java.api.tree.Tree.Kind.FOR_EACH_STATEMENT; |
63 | 64 | import static org.sonar.plugins.java.api.tree.Tree.Kind.FOR_STATEMENT; |
64 | 65 | import static org.sonar.plugins.java.api.tree.Tree.Kind.GREATER_THAN; |
|
87 | 88 | import static org.sonar.plugins.java.api.tree.Tree.Kind.RECORD_PATTERN; |
88 | 89 | import static org.sonar.plugins.java.api.tree.Tree.Kind.RETURN_STATEMENT; |
89 | 90 | import static org.sonar.plugins.java.api.tree.Tree.Kind.STRING_LITERAL; |
| 91 | +import static org.sonar.plugins.java.api.tree.Tree.Kind.SUPER_WILDCARD; |
90 | 92 | import static org.sonar.plugins.java.api.tree.Tree.Kind.SWITCH_EXPRESSION; |
91 | 93 | import static org.sonar.plugins.java.api.tree.Tree.Kind.SWITCH_STATEMENT; |
92 | 94 | import static org.sonar.plugins.java.api.tree.Tree.Kind.SYNCHRONIZED_STATEMENT; |
|
95 | 97 | import static org.sonar.plugins.java.api.tree.Tree.Kind.TYPE_CAST; |
96 | 98 | import static org.sonar.plugins.java.api.tree.Tree.Kind.TYPE_PATTERN; |
97 | 99 | import static org.sonar.plugins.java.api.tree.Tree.Kind.UNARY_MINUS; |
| 100 | +import static org.sonar.plugins.java.api.tree.Tree.Kind.UNBOUNDED_WILDCARD; |
98 | 101 | import static org.sonar.plugins.java.api.tree.Tree.Kind.VARIABLE; |
99 | 102 | import static org.sonar.plugins.java.api.tree.Tree.Kind.WHILE_STATEMENT; |
100 | 103 | import static org.sonar.plugins.java.api.tree.Tree.Kind.YIELD_STATEMENT; |
@@ -403,7 +406,10 @@ public ElementChecker(final Tree.Kind kind) { |
403 | 406 | TYPE_PATTERN, |
404 | 407 | GUARDED_PATTERN, |
405 | 408 | DEFAULT_PATTERN, |
406 | | - RECORD_PATTERN: |
| 409 | + RECORD_PATTERN, |
| 410 | + UNBOUNDED_WILDCARD, |
| 411 | + SUPER_WILDCARD, |
| 412 | + EXTENDS_WILDCARD: |
407 | 413 | break; |
408 | 414 | default: |
409 | 415 | throw new IllegalArgumentException("Unsupported element kind: " + kind); |
@@ -3149,6 +3155,42 @@ void throw_statement_within_try_catch() { |
3149 | 3155 |
|
3150 | 3156 | } |
3151 | 3157 |
|
| 3158 | + @Test |
| 3159 | + void generic_record_pattern() { |
| 3160 | + CFG cfg = buildCFG(""" |
| 3161 | + private static boolean testGen3(GenBase<Integer, String> o) { |
| 3162 | + return o instanceof GenRecord1<?, ? super Integer, ? extends CharSequence>(String a, Integer i, CharSequence s) && i == 3 && s.isEmpty(); |
| 3163 | + } |
| 3164 | + """); |
| 3165 | + |
| 3166 | + CFGChecker cfgChecker = checker( |
| 3167 | + block( |
| 3168 | + element(IDENTIFIER, "o"), |
| 3169 | + element(RECORD_PATTERN), |
| 3170 | + element(UNBOUNDED_WILDCARD), |
| 3171 | + element(SUPER_WILDCARD), |
| 3172 | + element(IDENTIFIER, "Integer"), |
| 3173 | + element(EXTENDS_WILDCARD), |
| 3174 | + element(IDENTIFIER, "CharSequence"), |
| 3175 | + element(IDENTIFIER, "GenRecord1"), |
| 3176 | + element(TYPE_PATTERN), |
| 3177 | + element(VARIABLE, "a"), |
| 3178 | + element(TYPE_PATTERN), |
| 3179 | + element(VARIABLE, "i"), |
| 3180 | + element(TYPE_PATTERN), |
| 3181 | + element(VARIABLE, "s"), |
| 3182 | + element(PATTERN_INSTANCE_OF) |
| 3183 | + ).terminator(CONDITIONAL_AND).ifTrue(4).ifFalse(3), |
| 3184 | + block(element(IDENTIFIER, "i"), element(INT_LITERAL, "3"), element(EQUAL_TO)) |
| 3185 | + .successors(3), |
| 3186 | + terminator(CONDITIONAL_AND).ifTrue(2).ifFalse(1), |
| 3187 | + block(element(IDENTIFIER, "s"), element(METHOD_INVOCATION)) |
| 3188 | + .successors(1), |
| 3189 | + terminator(RETURN_STATEMENT).successors(0)); |
| 3190 | + |
| 3191 | + cfgChecker.check(cfg); |
| 3192 | + } |
| 3193 | + |
3152 | 3194 | @Test |
3153 | 3195 | void build_partial_cfg_with_break() { |
3154 | 3196 | build_partial_cfg("break"); |
|
0 commit comments