mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce variable: allow subtyping during non-physical expression creation (IDEA-216460)
GitOrigin-RevId: d26f7b045b8c88ebfcc64e854221db5c1b2ff6c1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
824db4c08b
commit
68eb38b104
+7
-3
@@ -26,7 +26,6 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -485,8 +484,13 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (containingExpression != null && !Comparing.equal(containingExpression.getType(), tempExpr.getType())){
|
||||
return null;
|
||||
else if (containingExpression != null) {
|
||||
PsiType containingExpressionType = containingExpression.getType();
|
||||
PsiType tempExprType = tempExpr.getType();
|
||||
if (containingExpressionType != null &&
|
||||
(tempExprType == null || !TypeConversionUtil.isAssignable(containingExpressionType, tempExprType))) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final PsiReferenceExpression refExpr = PsiTreeUtil.getParentOfType(toBeExpression.findElementAt(refIdx[0]), PsiReferenceExpression.class);
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.util.*;
|
||||
|
||||
class MyTest {
|
||||
|
||||
private void foo(List<Object> b) {
|
||||
int i = 6 - b.size();
|
||||
if (i - 2L < 1) {}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.util.*;
|
||||
|
||||
class MyTest {
|
||||
|
||||
private void foo(List<Object> b) {
|
||||
if (<selection>6 - b.size()</selection> - 2L < 1) {}
|
||||
}
|
||||
}
|
||||
@@ -368,6 +368,10 @@ public class IntroduceVariableTest extends LightJavaCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, CommonClassNames.JAVA_LANG_STRING));
|
||||
}
|
||||
|
||||
public void testSubExpressionFromPrimitiveWithConversion() {
|
||||
doTest(new MockIntroduceVariableHandler("i", false, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testSubPrimitiveLiteral() {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, CommonClassNames.JAVA_LANG_STRING));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user