[codeInsight] IDEA-113640 Provide intention to combine System.out.println(String.format(...)) into System.out.printf

This patch cleans up the code

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

GitOrigin-RevId: f90c1f9af167102b3b57daf43c144973e9502a6f
This commit is contained in:
Nikita Eshkeev
2020-05-08 03:58:42 +03:00
committed by intellij-monorepo-bot
parent 35a04c3cdd
commit ec420ec3d4
3 changed files with 96 additions and 68 deletions

View File

@@ -5,6 +5,7 @@ import java.io.PrintStream;
class String {
String(Object original) {}
public native String formatted(Object... args);
}
@@ -16,8 +17,8 @@ class Main {
"""/* two */)) + "%n", "Hello"/* four */, /* six */ "World" /* seven */);
/* one */
System.out.printf(/* six */( /* two */ ( /* three */ new String("""
%s, %s!
"""/* four */) /* five */)), "Hello"/* seven */, /* eight */ "World" /* nine */);
%s, %s!
"""/* four */) /* five */)), "Hello"/* seven */, /* eight */ "World" /* nine */);
/* one */
System.out.printf(/* six */new String("""
@@ -32,32 +33,52 @@ class Main {
""") + "%n"/* four */), "Hello"/* six */, /* seven */ "World" /* eight */);
System.out.printf(/* five */( /* one */ new String("""
%s,
""" /* two */) + new String(/* three */
"""
%s,
""" /* two */) +
new String(/* three */
"""
%s!
""")/* four */), "Hello"/* six */, /* seven */ "World" /* eight */);
}
Main() {
}
void f() {
}
void out(PrintStream printer) {
/* one */
printer.printf(/* three */(new String("""
%s, %s!
"""/* two */)) + "%n", "Hello"/* four */, /* six */ "World" /* seven */);
/* one */
printer.printf(/* six */( /* two */ ( /* three */ new String("""
%s, %s!
"""/* four */) /* five */)), "Hello"/* seven */, /* eight */ "World" /* nine */);
/* one */
printer.printf(/* six */new String("""
%s, %s!
"""/* two */), "Hello"/* seven */, /* eight */ "World" /* nine */);
printer.printf(/* five */( /* one */ new String("""
%s,
""" /* two */) + /* three */
new String("""
%s!
""") + "%n"/* four */), "Hello"/* six */, /* seven */ "World" /* eight */);
printer.printf(/* five */( /* one */ new String("""
%s,
""" /* two */) +
new String(/* three */
"""
%s!
""")/* four */), "Hello"/* six */, /* seven */ "World" /* eight */);
}
void caller() {
println(( /* one */ new String("""
%s,
""" /* two */ + /* three */
"""
%s!
"""/* four */)).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
%s,
""" /* two */ + /* three */
"""
%s!
"""/* four */)).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
}
static void println(String value) {}

View File

@@ -5,57 +5,76 @@ import java.io.PrintStream;
class String {
String(Object original) {}
public native String formatted(Object... args);
}
class Main {
static {
System.out.println(/* one */ new String("""
%s, %s!
"""/* two */).<caret>formatted(/* three */"Hello"/* four */, /* six */ "World" /* seven */));
%s, %s!
"""/* two */).<caret>formatted(/* three */"Hello"/* four */, /* six */ "World" /* seven */));
System.out.print(/* one */ ( /* two */ ( /* three */ new String("""
%s, %s!
"""/* four */) /* five */))
%s, %s!
"""/* four */) /* five */))
.formatted(/* six */"Hello"/* seven */, /* eight */ "World" /* nine */));
System.out.print(/* one */ new String("""
%s, %s!
"""/* two */).formatted(/* six */"Hello"/* seven */, /* eight */ "World" /* nine */));
%s, %s!
"""/* two */).formatted(/* six */"Hello"/* seven */, /* eight */ "World" /* nine */));
System.out.println(( /* one */ new String("""
%s,
""" /* two */) + /* three */
%s,
""" /* two */) + /* three */
new String("""
%s!
""")/* four */).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
%s!
""")/* four */).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
System.out.print(( /* one */ new String("""
%s,
""" /* two */) + new String(/* three */
"""
%s,
""" /* two */) +
new String(/* three */
"""
%s!
""")/* four */).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
}
void out(PrintStream printer) {
printer.println(/* one */ new String("""
%s, %s!
"""/* two */).formatted(/* three */"Hello"/* four */, /* six */ "World" /* seven */));
printer.print(/* one */ ( /* two */ ( /* three */ new String("""
%s, %s!
"""/* four */) /* five */))
.formatted(/* six */"Hello"/* seven */, /* eight */ "World" /* nine */));
printer.print(/* one */ new String("""
%s, %s!
"""/* two */).formatted(/* six */"Hello"/* seven */, /* eight */ "World" /* nine */));
printer.println(( /* one */ new String("""
%s,
""" /* two */) + /* three */
new String("""
%s!
""")/* four */).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
printer.print(( /* one */ new String("""
%s,
""" /* two */) +
new String(/* three */
"""
%s!
""")/* four */).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
}
Main() {
}
void f() {
}
void out(PrintStream printer) {
}
void caller() {
println(( /* one */ new String("""
%s,
""" /* two */ + /* three */
"""
%s!
"""/* four */)).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
%s,
""" /* two */ + /* three */
"""
%s!
"""/* four */)).formatted(/* five */"Hello"/* six */, /* seven */ "World" /* eight */));
}
static void println(String value) {}