mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline variable: captured wildcard != wildcard so isAssignable should be used in order to avoid redundant class casts (IDEA-27243); though isAssignable can't replace equals as for primitive types cast can change expr semantics, e.g. (float)intVar1/intVar2
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.RedundantCastUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -54,7 +55,8 @@ public class InlineUtil {
|
||||
ChangeContextUtil.encodeContextInfo(initializer, false);
|
||||
PsiExpression expr = (PsiExpression)ref.replace(initializer);
|
||||
PsiType exprType = expr.getType();
|
||||
if (exprType != null && !varType.equals(exprType)) {
|
||||
if (exprType != null && (!varType.equals(exprType) && varType instanceof PsiPrimitiveType
|
||||
|| !TypeConversionUtil.isAssignable(varType, exprType))) {
|
||||
boolean matchedTypes = false;
|
||||
//try explicit type arguments
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.util.*;
|
||||
class Test {
|
||||
void foo() {
|
||||
final Collection<? extends Number> extensions = getExtensions();
|
||||
for (Number extension : exte<caret>nsions) {
|
||||
}
|
||||
}
|
||||
|
||||
Collection<? extends Number> getExtensions() {return null;}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.util.*;
|
||||
class Test {
|
||||
void foo() {
|
||||
for (Number extension : getExtensions()) {
|
||||
}
|
||||
}
|
||||
|
||||
Collection<? extends Number> getExtensions() {return null;}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testWildcard() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
private void doTest(final boolean inlineDef, String conflictMessage) throws Exception {
|
||||
try {
|
||||
doTest(inlineDef);
|
||||
|
||||
Reference in New Issue
Block a user