Skip to content

Commit

Permalink
Apply OpenRewrite Java 17 migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 19, 2024
1 parent 0008cd4 commit e7acb47
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@
<recipe>org.openrewrite.staticanalysis.MissingOverrideAnnotation</recipe>
<recipe>org.openrewrite.staticanalysis.CommonStaticAnalysis</recipe>
<recipe>org.openrewrite.staticanalysis.RemoveExtraSemicolons</recipe>
<recipe>org.openrewrite.java.migrate.Java8toJava11</recipe>
<recipe>org.openrewrite.java.RemoveUnusedImports</recipe>
<recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
<recipe>org.openrewrite.java.migrate.util.SequencedCollection</recipe>
<recipe>org.openrewrite.java.migrate.lang.var.UseVarForObject</recipe>
<recipe>org.openrewrite.java.format.RemoveTrailingWhitespace</recipe>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/hm/hafner/util/Ensure.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static void thatStatementIsNeverReached(final String explanation, final O
*/
@FormatMethod
private static void throwException(final String message, @CheckForNull final Object... args) {
throw new AssertionError(String.format(message, args));
throw new AssertionError(message.formatted(args));
}

/**
Expand All @@ -185,7 +185,7 @@ private static void throwException(final String message, @CheckForNull final Obj
*/
@FormatMethod
private static void throwNullPointerException(final String message, final Object... args) {
throw new NullPointerException(String.format(message, args)); // NOPMD
throw new NullPointerException(message.formatted(args)); // NOPMD
}

private Ensure() {
Expand Down Expand Up @@ -764,7 +764,7 @@ public ExceptionCondition(@CheckForNull final Throwable value) {
*/
@FormatMethod
public void isNeverThrown(final String explanation, final Object... args) {
throw new AssertionError(String.format(explanation, args), value);
throw new AssertionError(explanation.formatted(args), value);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/util/FilteredLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void logInfo(final String message) {
*/
@FormatMethod
public void logInfo(final String format, final Object... args) {
logInfo(String.format(format, args));
logInfo(format.formatted(args));
}

/**
Expand Down Expand Up @@ -142,7 +142,7 @@ public void logError(final String message) {
*/
@FormatMethod
public void logError(final String format, final Object... args) {
logError(String.format(format, args));
logError(format.formatted(args));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/edu/hm/hafner/util/LineRangeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ private void ensure(final int n) {

@Override
public boolean contains(final Object o) {
if (o instanceof LineRange) {
var other = (LineRange) o;

if (o instanceof final LineRange other) {
for (var cursor = new Cursor(); cursor.hasNext();) {
if (cursor.compare(other)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/util/LookaheadStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ public int getLine() {

@Override @Generated
public String toString() {
return String.format("[%d] -> '%s'", line, lookaheadLine);
return "[%d] -> '%s'".formatted(line, lookaheadLine);
}
}
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/util/PrefixLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PrefixLogger(final PrintStream logger, final String prefix) {
this.toolName = prefix + " ";
}
else {
this.toolName = String.format("[%s] ", prefix);
this.toolName = "[%s] ".formatted(prefix);
}
delegate = logger;
}
Expand All @@ -44,7 +44,7 @@ public PrefixLogger(final PrintStream logger, final String prefix) {
*/
@FormatMethod
public void log(final String format, final Object... args) {
print(String.format(format, args));
print(format.formatted(args));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/hm/hafner/util/SecureXmlParserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public ParsingException(final Throwable cause) {
*/
@FormatMethod
public ParsingException(final String messageFormat, final Object... args) {
super(String.format(messageFormat, args));
super(messageFormat.formatted(args));

Check warning on line 371 in src/main/java/edu/hm/hafner/util/SecureXmlParserFactory.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/edu/hm/hafner/util/SecureXmlParserFactory.java#L371

Added line #L371 was not covered by tests
}

/**
Expand All @@ -388,11 +388,11 @@ public ParsingException(final String messageFormat, final Object... args) {
*/
@FormatMethod
public ParsingException(final Throwable cause, final String messageFormat, final Object... args) {
super(createMessage(cause, String.format(messageFormat, args)), cause);
super(createMessage(cause, messageFormat.formatted(args)), cause);

Check warning on line 391 in src/main/java/edu/hm/hafner/util/SecureXmlParserFactory.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/edu/hm/hafner/util/SecureXmlParserFactory.java#L391

Added line #L391 was not covered by tests
}

private static String createMessage(final Throwable cause, final String message) {
return String.format("%s%n%s%n%s", message,
return "%s%n%s%n%s".formatted(message,
ExceptionUtils.getMessage(cause), ExceptionUtils.getStackTrace(cause));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/edu/hm/hafner/util/ArchitectureRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void check(final JavaMethod method, final ConditionEvents events) {
return;
}
events.add(SimpleConditionEvent.violated(method,
String.format("%s is not protected but the class might be extended in %s",
"%s is not protected but the class might be extended in %s".formatted(
method.getDescription(), method.getSourceCodeLocation())));
}
}
Expand Down

0 comments on commit e7acb47

Please sign in to comment.