Files
openide/java/java-tests/testData/codeInsight/replaceStringFormat/afterPrintStringFormat1.java
Nikita Eshkeev d605adb8d1 [codeInsight] IDEA-113640 Provide intention to combine System.out.println(String.format(...)) into System.out.printf
The RedundantStringFormatCallInspection inspection used to be able to
detect excessive String.format calls and get rid of them not changing
the callsite at all. This patch enhances the inspection's capabilities
with changing the callsite if it is either PrintStream#print or
PrintStream#println and converting it to PrintStream#printf adding "%n"
if necessary.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 7edc5b0a84fb6c7b9caf504b1afb8905c5684985
2020-05-01 14:07:13 +00:00

29 lines
922 B
Java

// "Fix all 'Redundant call to 'String.format()'' problems in file" "true"
import java.io.PrintStream;
class Main {
static {
System.out.print(/* begin */ "Hello, World!"/* end */);
System.out.print(String.format(/* begin */ "Hello, World!%n"/* end */));
}
Main() {
System.out.print(/* begin */ "Hello, World!"/* end */);
System.out.print(String.format(/* begin */ "Hello, World!%n"/* end */));
}
void f() {
System.out.print(/* begin */ "Hello, World!"/* end */);
System.out.print(String.format(/* begin */ "Hello, World!%n"/* end */));
}
void out(PrintStream printer) {
printer.print(/* begin */ "Hello, World!"/* end */);
printer.print(String.format(/* begin */ "Hello, World!%n"/* end */));
}
void caller() {
print(/* begin */ "Hello, World!"/* end */);
print(String.format(/* begin */ "Hello, World!%n"/* end */));
}
static void print(String value) {}
}