Skip to content

Commit

Permalink
Use Java modern features/APIs (#357)
Browse files Browse the repository at this point in the history
* refactor: Run openrewrite to use Java 17 features

This mainly uses:

- Text blocks: https://openjdk.org/jeps/378
- Pattern matching: https://openjdk.org/jeps/394

* refactor: a few usages of newer Collections APIs
  • Loading branch information
marcospereira authored May 12, 2024
1 parent 9320ca7 commit 8c7703b
Show file tree
Hide file tree
Showing 25 changed files with 1,340 additions and 927 deletions.
14 changes: 7 additions & 7 deletions jte-jsp-converter/src/main/java/example/JteContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class JteContext {
public static boolean isEmpty(Object obj) {
if (obj == null) {
return true;
} else if (obj instanceof String) {
return ((String) obj).length() == 0;
} else if (obj instanceof Object[]) {
return ((Object[]) obj).length == 0;
} else if (obj instanceof Collection) {
return ((Collection<?>) obj).isEmpty();
} else if (obj instanceof String string) {
return string.isEmpty();
} else if (obj instanceof Object[] objects) {
return objects.length == 0;
} else if (obj instanceof Collection<?> collection) {
return collection.isEmpty();
} else {
return obj instanceof Map && ((Map<?, ?>) obj).isEmpty();
return obj instanceof Map<?, ?> m && m.isEmpty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ void simpleTagWithNotYetConvertedTags() {
givenUsecase("simpleTagWithNotYetConvertedTags");
Throwable throwable = catchThrowable(() -> whenJspTagIsConverted("my/simple.tag", "tag/my/simple.jte"));
assertThat(throwable).isInstanceOf(UnsupportedOperationException.class).hasMessage(
"The tag <my:simple-dependency1/> is used by this tag and not converted to jte yet. You should convert <my:simple-dependency1/> first. If this is a tag that should be always converted by hand, implement getNotConvertedTags() and add it there.\n" +
"The tag <my:simple-dependency2/> is used by this tag and not converted to jte yet. You should convert <my:simple-dependency2/> first. If this is a tag that should be always converted by hand, implement getNotConvertedTags() and add it there."
"""
The tag <my:simple-dependency1/> is used by this tag and not converted to jte yet. You should convert <my:simple-dependency1/> first. If this is a tag that should be always converted by hand, implement getNotConvertedTags() and add it there.
The tag <my:simple-dependency2/> is used by this tag and not converted to jte yet. You should convert <my:simple-dependency2/> first. If this is a tag that should be always converted by hand, implement getNotConvertedTags() and add it there.\
"""
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void report(CompilerMessageSeverity severity, @SuppressWarnings("Nullable
line = location.getLine();
}

errors.add(String.format("%s%n%s:%d:%d%nReason: %s", location.getLineContent(), location.getPath(),
errors.add("%s%n%s:%d:%d%nReason: %s".formatted(location.getLineContent(), location.getPath(),
location.getLine(),
location.getColumn(), s));
} else {
Expand Down
Loading

0 comments on commit 8c7703b

Please sign in to comment.