Use pattern matching for instanceof where appropriate
See gh-31475
This commit is contained in:
committed by
Andy Wilkinson
parent
a7b98e7312
commit
5db04da275
@@ -213,8 +213,8 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
private Object extractValue(Object value) {
|
||||
if (value instanceof DeclaredType) {
|
||||
return Elements.getQualifiedName(((DeclaredType) value).asElement());
|
||||
if (value instanceof DeclaredType declaredType) {
|
||||
return Elements.getQualifiedName(declaredType.asElement());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,19 +38,18 @@ final class Elements {
|
||||
return getQualifiedName(enclosingElement) + "$"
|
||||
+ ((DeclaredType) element.asType()).asElement().getSimpleName().toString();
|
||||
}
|
||||
if (element instanceof TypeElement) {
|
||||
return ((TypeElement) element).getQualifiedName().toString();
|
||||
if (element instanceof TypeElement typeElement) {
|
||||
return typeElement.getQualifiedName().toString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TypeElement getEnclosingTypeElement(TypeMirror type) {
|
||||
if (type instanceof DeclaredType) {
|
||||
DeclaredType declaredType = (DeclaredType) type;
|
||||
if (type instanceof DeclaredType declaredType) {
|
||||
Element enclosingElement = declaredType.asElement().getEnclosingElement();
|
||||
if (enclosingElement instanceof TypeElement) {
|
||||
return (TypeElement) enclosingElement;
|
||||
if (enclosingElement instanceof TypeElement typeElement) {
|
||||
return typeElement;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user