import java.util.ArrayList;
import org.jetbrains.annotations.*;
class Test {
void nullableWithUnconditionalPatternLabel(@Nullable Integer i) {
switch (i) {
case 1:
break;
case Integer ii when true:
break;
}
}
void nullableSetNullWithUnconditionalPatternLabel(@Nullable Integer i) {
i = null;
switch (i) {
case 1:
break;
case Integer ii when true:
break;
}
}
void nullableSetNotNullWithUnconditionalPatternLabel(@Nullable Integer i) {
i = 1;
switch (i) {
case 1:
break;
case Integer ii when true:
break;
}
}
void unknownWithUnconditionalPatternLabel(Integer i) {
switch (i) {
case 1:
break;
case Integer ii when true:
break;
}
}
void unknownSetNullWithUnconditionalPatternLabel(Integer i) {
i = null;
switch (i) {
case 1:
break;
case Integer ii when true:
break;
}
}
void unknownSetNotNullWithUnconditionalPatternLabel(Integer i) {
i = 1;
switch (i) {
case 1:
break;
case Integer ii:
break;
}
}
void notNullWithUnconditionalPatternLabel(@NotNull Integer i) {
switch (i) {
case 1:
break;
case Integer ii when true:
break;
}
}
void notNullSetNullWithUnconditionalPatternLabel(@NotNull Integer i) {
i = null;
switch (i) {
case 1:
break;
case Integer ii when Math.random() > 0.5:
break;
case Integer ii when true:
break;
}
}
void notNullSetNotNullWithUnconditionalPatternLabel(@NotNull Integer i) {
i = 1;
switch (i) {
case 1:
break;
case Object o:
break;
}
}
void nullableCallWithGuardedNotUnconditionalPatternLabel() {
switch (createNullValue()) {
case 1:
break;
case Object o when !new ArrayList().isEmpty():
break;
default:
break;
}
}
void nullableCallWithUnconditionalPatternLabel() {
switch (createNullValue()) {
case 1:
break;
case Object o:
break;
}
}
void unknownCallWithUnconditionalPatternLabel() {
switch (createValue()) {
case 1:
break;
case Integer ii when true:
break;
}
}
void notNullCallWithUnconditionalPatternLabel() {
switch (createNotNullValue()) {
case 1, 2:
break;
case Object o when true:
break;
}
}
// expressions
int nullableWithUnconditionalPatternLabelExpr(@Nullable Integer i) {
return switch (i) {
case 1 -> 1;
case Integer ii when true -> 2;
};
}
int nullableSetNullWithUnconditionalPatternLabelExpr(@Nullable Integer i) {
i = null;
return switch (i) {
case 1 -> 1;
case Integer ii when true -> 2;
};
}
int nullableSetNotNullWithUnconditionalPatternLabelExpr(@Nullable Integer i) {
i = 1;
return switch (i) {
case 1 -> 1;
case Integer ii when true -> 2;
};
}
int unknownWithUnconditionalPatternLabelExpr(Integer i) {
return switch (i) {
case 1 -> 1;
case Integer ii when true -> 2;
};
}
int unknownSetNullWithUnconditionalPatternLabelExpr(Integer i) {
i = null;
return switch (i) {
case 1 -> 1;
case Integer ii when true -> 2;
};
}
int unknownSetNotNullWithUnconditionalPatternLabelExpr(Integer i) {
i = 1;
return switch (i) {
case 1 -> 1;
case Integer ii -> 2;
};
}
int notNullWithUnconditionalPatternLabelExpr(@NotNull Integer i) {
return switch (i) {
case 1 -> 1;
case Integer ii when true -> 2;
};
}
int notNullSetNullWithUnconditionalPatternLabelExpr(@NotNull Integer i) {
i = null;
return switch (i) {
case 1 -> 1;
case Integer ii when Math.random() > 0.5 -> 2;
case Integer ii when true -> 3;
};
}
int notNullSetNotNullWithUnconditionalPatternLabelExpr(@NotNull Integer i) {
i = 1;
return switch (i) {
case 1 -> 1;
case Object o -> 2;
};
}
int nullableCallWithGuardedNotUnconditionalPatternLabelExpr() {
return switch (createNullValue()) {
case 1 -> 1;
case Object o when Math.random() > 0.5 -> 2;
default -> 3;
};
}
int nullableCallWithUnconditionalPatternLabelExpr() {
return switch (createNullValue()) {
case 1 -> 1;
case Object o -> 2;
};
}
int unknownCallWithUnconditionalPatternLabelExpr() {
return switch (createValue()) {
case 1 -> 1;
case Integer ii when true -> 2;
};
}
int notNullCallWithUnconditionalPatternLabelExpr() {
return switch (createNotNullValue()) {
case 1, 2 -> 1;
case Object o when true -> 2;
};
}
@Nullable
Integer createNullValue() {
return null;
}
Integer createValue() {
return 1;
}
@NotNull
Integer createNotNullValue() {
return 1;
}
}