Browse Source

Simplify if-statements with instanceof checks

Closes gh-25449
pull/25461/head
XenoAmess 5 years ago committed by GitHub
parent
commit
3b12beb1b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java
  2. 2
      spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java
  3. 2
      spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java
  4. 2
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java
  5. 2
      spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java
  6. 2
      spring-tx/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java
  7. 2
      spring-tx/src/main/java/org/springframework/transaction/annotation/JtaTransactionAnnotationParser.java
  8. 2
      spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java
  9. 3
      spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java
  10. 2
      spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java

2
spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java

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

2
spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java

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

2
spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java vendored

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

2
spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java

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

2
spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java

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

2
spring-tx/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java

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

2
spring-tx/src/main/java/org/springframework/transaction/annotation/JtaTransactionAnnotationParser.java

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

2
spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java

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

3
spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java

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

2
spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java

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

Loading…
Cancel
Save