mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 23:31:05 +07:00
[java-refactoring] Inline variable on non-initialized declaration
Could be available if there's only one write visible for all the reads Fixes IDEA-354157 Inline variable not working when staying on uninitialized declaration GitOrigin-RevId: e257b2b493a3902e901699efa4eac90f62e3108b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bab02f85ff
commit
b01ac55564
@@ -485,7 +485,23 @@ public final class InlineLocalHandler extends JavaInlineActionHandler {
|
||||
if (rExpr != null) return rExpr;
|
||||
}
|
||||
}
|
||||
return local.getInitializer();
|
||||
PsiExpression initializer = local.getInitializer();
|
||||
if (initializer != null) {
|
||||
return initializer;
|
||||
}
|
||||
List<PsiReferenceExpression> refs = VariableAccessUtils.getVariableReferences(local, block);
|
||||
Set<PsiExpression> allDefs = new HashSet<>();
|
||||
for (PsiReferenceExpression ref : refs) {
|
||||
if (PsiUtil.isAccessedForWriting(ref)) {
|
||||
if (PsiUtil.isAccessedForReading(ref)) return null;
|
||||
continue;
|
||||
}
|
||||
PsiExpression def = getDefToInline(local, ref, block, rethrow);
|
||||
if (def == null) return null;
|
||||
allDefs.add(def);
|
||||
if (allDefs.size() != 1) return null;
|
||||
}
|
||||
return ContainerUtil.getOnlyItem(allDefs);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user