mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
IDEA-198546 "Replace cast with variable" inserts unresolved reference
This commit is contained in:
@@ -94,6 +94,7 @@ public class ReplaceCastWithVariableAction extends PsiElementBaseIntentionAction
|
||||
.filter(PsiTypeCastExpression.class)
|
||||
.filter(cast -> EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(cast.getOperand(), operand))
|
||||
.toList();
|
||||
PsiResolveHelper resolveHelper = PsiResolveHelper.SERVICE.getInstance(method.getProject());
|
||||
for (PsiTypeCastExpression occurrence : found) {
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
final TextRange occurrenceTextRange = occurrence.getTextRange();
|
||||
@@ -105,7 +106,9 @@ public class ReplaceCastWithVariableAction extends PsiElementBaseIntentionAction
|
||||
|
||||
final PsiCodeBlock methodBody = method.getBody();
|
||||
if (variable != null && methodBody != null &&
|
||||
!isChangedBetween(castedVar, methodBody, occurrence, expression) && !isChangedBetween(variable, methodBody, occurrence, expression)) {
|
||||
variable.getName() != null && resolveHelper.resolveReferencedVariable(variable.getName(), expression) == variable &&
|
||||
!isChangedBetween(castedVar, methodBody, occurrence, expression) &&
|
||||
!isChangedBetween(variable, methodBody, occurrence, expression)) {
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace '(String)o' with 's'" "false"
|
||||
|
||||
class C {
|
||||
void foo(Object o) {
|
||||
if (o instanceof String) {
|
||||
String s = (String)o;
|
||||
}
|
||||
if (o instanceof String) {
|
||||
String t = (Stri<caret>ng)o;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user