[java] IJ-CR-167924 IDEA-371865 Inspection to convert 'System.out'<->'IO'

- extract "java.lang.IO"
- tests for allowUnresolved
- more reliable works with varargs

GitOrigin-RevId: 8376baaa86afa3806cb096cffd42e9ed0db0d451
This commit is contained in:
Mikhail Pyltsin
2025-07-08 22:10:37 +00:00
committed by intellij-monorepo-bot
parent de315fe676
commit 7369bd9f90
11 changed files with 279 additions and 11 deletions
@@ -11,14 +11,16 @@ import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.psiutils.CommentTracker;
import org.jetbrains.annotations.NotNull;
import static com.intellij.psi.CommonClassNames.JAVA_LANG_IO;
public final class MigrateFromJavaLangIoInspection extends AbstractBaseJavaLocalInspectionTool {
private static final CallMatcher IO_PRINT =
CallMatcher.anyOf(
CallMatcher.staticCall("java.lang.IO", "println")
CallMatcher.staticCall(JAVA_LANG_IO, "println")
.parameterCount(0)
.allowUnresolved(),
CallMatcher.staticCall("java.lang.IO", "println", "print")
CallMatcher.staticCall(JAVA_LANG_IO, "println", "print")
.parameterCount(1)
.allowUnresolved()
);
@@ -119,7 +119,7 @@ public final class MigrateToJavaLangIoInspection extends AbstractBaseJavaLocalIn
PsiReferenceExpression methodExpr = methodCall.getMethodExpression();
String methodName = methodExpr.getReferenceName();
if (methodName == null) return;
PsiElement replaced = new CommentTracker().replaceAndRestoreComments(methodExpr, "java.lang.IO." + methodName);
PsiElement replaced = new CommentTracker().replaceAndRestoreComments(methodExpr, JAVA_LANG_IO + "." + methodName);
if (replaced instanceof PsiReferenceExpression replacedReferenceExpression) {
JavaCodeStyleManager.getInstance(replacedReferenceExpression.getProject()).shortenClassReferences(replacedReferenceExpression);
}