-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace ArrayStoreException
with TypeNotPresentException
in try/catch using Class.getAnnotation()
#613
Replace ArrayStoreException
with TypeNotPresentException
in try/catch using Class.getAnnotation()
#613
Conversation
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/TypeNotPresentExceptionTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/TypeNotPresentExceptionTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/TypeNotPresentExceptionTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/TypeNotPresentExceptionTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/TypeNotPresentExceptionTest.java
Outdated
Show resolved
Hide resolved
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
final MethodMatcher classGetAnnotationMethod = new MethodMatcher("java.lang.Class getAnnotation(java.lang.Class)"); | ||
return new JavaVisitor<ExecutionContext>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a Precondition here to only call the visitor when classGetAnnotationMethod
is used. That way we can reject the vast majority of classes without visiting any elements, for a nice performance boost.
src/main/java/org/openrewrite/java/migrate/ArrayStoreExceptionToTypeNotPresentException.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
getAnnotation()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for kicking this off @BhavanaPidapa ; I've applied a few small changes in 18595ca to simplify the implementation and use established patterns. Approved from my side & ready to merge.
getAnnotation()
ArrayStoreException
with TypeNotPresentException
in try/catch using Class.getAnnotation()
What's changed?
This PR contains recipe - org.openrewrite.java.migrate.ArrayStoreExceptionToTypeNotPresentException
Rule:
What's your motivation?
This custom recipe replaces catch blocks for
ArrayStoreException
aroundgetAnnotation()
withTypeNotPresentException
to ensure compatibility with Java 11+.Anyone you would like to review specifically?
@timtebeek @cjobinabo
Checklist