mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
inline: do not insert casts when inline conditional expression in statements (IDEA-97902)
This commit is contained in:
@@ -56,10 +56,9 @@ public class InlineUtil {
|
||||
ChangeContextUtil.encodeContextInfo(initializer, false);
|
||||
PsiExpression expr = (PsiExpression)replaceDiamondWithInferredTypesIfNeeded(initializer, ref);
|
||||
PsiType exprType = expr.getType();
|
||||
if (exprType != null && (!varType.equals(exprType) && varType instanceof PsiPrimitiveType
|
||||
if (exprType != null && (!varType.equals(exprType) && (varType instanceof PsiPrimitiveType || exprType instanceof PsiPrimitiveType)
|
||||
|| !TypeConversionUtil.isAssignable(varType, exprType)
|
||||
|| insertCastWhenUnchecked && GenericsHighlightUtil.isRawToGeneric(varType, exprType)
|
||||
|| expr instanceof PsiConditionalExpression)) {
|
||||
|| insertCastWhenUnchecked && GenericsHighlightUtil.isRawToGeneric(varType, exprType))) {
|
||||
boolean matchedTypes = false;
|
||||
//try explicit type arguments
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class Test {
|
||||
static boolean isA() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean isB() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void foo(final boolean explicit) {
|
||||
final boolean has = explicit ? isA() : isB();
|
||||
if (ha<caret>s) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Test {
|
||||
static boolean isA() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean isB() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void foo(final boolean explicit) {
|
||||
if (explicit ? isA() : isB()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,10 +195,15 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
|
||||
public void testUncheckedCast() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testUncheckedCastNotNeeded() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testCastNotNeeded() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testLocalVarInsideLambdaBodyWriteUsage() throws Exception {
|
||||
doTest(true, "Cannot perform refactoring.\n" +
|
||||
"Variable 'hello' is accessed for writing.");
|
||||
|
||||
Reference in New Issue
Block a user