handle one other type of PSI change (part of KTIJ-27988 K2 IDE: used/unused declaration highlighting is not updated in Kotlin source on editing Java source)

GitOrigin-RevId: d2e7d4c9801d50df41cffa33eedb22a1db1ac7cf
This commit is contained in:
Alexey Kudravtsev
2024-05-17 16:57:14 +02:00
committed by intellij-monorepo-bot
parent e31cbdfc41
commit 12fe9dde02
4 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
package p2;
public class A2222 {
void foo(p1.A1111 a) {
a.hashCode();
// a.foo();
a.hashCode();
}
}

View File

@@ -2214,4 +2214,22 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
// now A2222 is no longer unused
assertEmpty(doHighlighting(HighlightSeverity.WARNING));
}
// test the other type of PSI change: child remove/child add
public void testTypingInsideCodeBlockCanAffectUnusedDeclarationInTheOtherClass2() {
enableInspectionTool(new UnusedSymbolLocalInspection());
enableDeadCodeInspection();
configureByFiles(null, BASE_PATH+getTestName(true)+"/p1/A1111.java", BASE_PATH+getTestName(true)+"/p2/A2222.java");
assertEquals("A1111.java", getFile().getName());
makeEditorWindowVisible(new Point(0, 1000), myEditor);
HighlightInfo info = assertOneElement(doHighlighting(HighlightSeverity.WARNING));
assertEquals("Method 'foo()' is never used", info.getDescription());
Document document2222 = getFile().getParent().findFile("A2222.java").getFileDocument();
// uncomment (inside codeblock) the reference to A1111
WriteCommandAction.writeCommandAction(myProject).run(()->document2222.deleteString(document2222.getText().indexOf("//"), document2222.getText().indexOf("//")+2));
// now foo() is no longer unused
assertEmpty(doHighlighting(HighlightSeverity.WARNING));
}
}

View File

@@ -215,7 +215,11 @@ final class PsiChangeHandler extends PsiTreeChangeAdapter {
return true;
}
PsiElement newChild = event.getNewChild();
return newChild != null && newChild != oldChild && hasReferenceInside(newChild);
if (newChild != null && newChild != oldChild && hasReferenceInside(newChild)) {
return true;
}
PsiElement child = event.getChild();
return child != null && child != oldChild && child != newChild && hasReferenceInside(child);
}
private void queueElement(@NotNull PsiElement child, boolean whitespaceOptimizationAllowed, @NotNull PsiTreeChangeEvent event) {