Simplify if-statements with instanceof checks

Closes gh-25449
This commit is contained in:
XenoAmess 2020-07-22 16:34:27 +08:00 committed by GitHub
parent c7f44ff671
commit 3b12beb1b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 10 additions and 11 deletions

View File

@ -469,7 +469,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
if (this == other) { if (this == other) {
return true; return true;
} }
if (other == null || !(other instanceof TestBean)) { if (!(other instanceof TestBean)) {
return false; return false;
} }
TestBean tb2 = (TestBean) other; TestBean tb2 = (TestBean) other;

View File

@ -63,7 +63,7 @@ class TypeHelper {
if (type instanceof DeclaredType) { if (type instanceof DeclaredType) {
DeclaredType declaredType = (DeclaredType) type; DeclaredType declaredType = (DeclaredType) type;
Element enclosingElement = declaredType.asElement().getEnclosingElement(); Element enclosingElement = declaredType.asElement().getEnclosingElement();
if (enclosingElement != null && enclosingElement instanceof TypeElement) { if (enclosingElement instanceof TypeElement) {
return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString(); return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString();
} }
else { else {

View File

@ -223,7 +223,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || other instanceof SpringCacheAnnotationParser); return (other instanceof SpringCacheAnnotationParser);
} }
@Override @Override

View File

@ -62,7 +62,7 @@ public class OperatorInstanceof extends Operator {
Object leftValue = left.getValue(); Object leftValue = left.getValue();
Object rightValue = right.getValue(); Object rightValue = right.getValue();
BooleanTypedValue result; BooleanTypedValue result;
if (rightValue == null || !(rightValue instanceof Class)) { if (!(rightValue instanceof Class)) {
throw new SpelEvaluationException(getRightOperand().getStartPosition(), throw new SpelEvaluationException(getRightOperand().getStartPosition(),
SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND, SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND,
(rightValue == null ? "null" : rightValue.getClass().getName())); (rightValue == null ? "null" : rightValue.getClass().getName()));

View File

@ -181,7 +181,7 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
// If the WebApplicationContext has no parent or the parent is not a WebApplicationContext, // If the WebApplicationContext has no parent or the parent is not a WebApplicationContext,
// set the current context as the root WebApplicationContext: // set the current context as the root WebApplicationContext:
if (parent == null || (!(parent instanceof WebApplicationContext))) { if (!(parent instanceof WebApplicationContext)) {
String resourceBasePath = webMergedConfig.getResourceBasePath(); String resourceBasePath = webMergedConfig.getResourceBasePath();
ResourceLoader resourceLoader = (resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ? ResourceLoader resourceLoader = (resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ?
new DefaultResourceLoader() : new FileSystemResourceLoader()); new DefaultResourceLoader() : new FileSystemResourceLoader());

View File

@ -61,7 +61,7 @@ public class Ejb3TransactionAnnotationParser implements TransactionAnnotationPar
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || other instanceof Ejb3TransactionAnnotationParser); return (other instanceof Ejb3TransactionAnnotationParser);
} }
@Override @Override

View File

@ -82,7 +82,7 @@ public class JtaTransactionAnnotationParser implements TransactionAnnotationPars
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || other instanceof JtaTransactionAnnotationParser); return (other instanceof JtaTransactionAnnotationParser);
} }
@Override @Override

View File

@ -104,7 +104,7 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || other instanceof SpringTransactionAnnotationParser); return (other instanceof SpringTransactionAnnotationParser);
} }
@Override @Override

View File

@ -167,8 +167,7 @@ public class PathPattern implements Comparable<PathPattern> {
if (elem instanceof CaptureTheRestPathElement || elem instanceof WildcardTheRestPathElement) { if (elem instanceof CaptureTheRestPathElement || elem instanceof WildcardTheRestPathElement) {
this.catchAll = true; this.catchAll = true;
} }
if (elem instanceof SeparatorPathElement && elem.next != null && if (elem instanceof SeparatorPathElement && elem.next instanceof WildcardPathElement && elem.next.next == null) {
elem.next instanceof WildcardPathElement && elem.next.next == null) {
this.endsWithSeparatorWildcard = true; this.endsWithSeparatorWildcard = true;
} }
elem = elem.next; elem = elem.next;

View File

@ -96,7 +96,7 @@ public class WebSocketMessageBrokerStats {
} }
} }
SubProtocolHandler defaultHandler = this.webSocketHandler.getDefaultProtocolHandler(); SubProtocolHandler defaultHandler = this.webSocketHandler.getDefaultProtocolHandler();
if (defaultHandler != null && defaultHandler instanceof StompSubProtocolHandler) { if (defaultHandler instanceof StompSubProtocolHandler) {
return (StompSubProtocolHandler) defaultHandler; return (StompSubProtocolHandler) defaultHandler;
} }
return null; return null;