From 969cfafa867d751b397f9f27178ac04f7fe63946 Mon Sep 17 00:00:00 2001 From: Nicolas PERU Date: Tue, 28 Jun 2016 11:55:34 +0200 Subject: [PATCH] Fix quality flaw: reduce complexity by method --- .../resolve/ParametrizedTypeJavaType.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/java-frontend/src/main/java/org/sonar/java/resolve/ParametrizedTypeJavaType.java b/java-frontend/src/main/java/org/sonar/java/resolve/ParametrizedTypeJavaType.java index 9d7fc3e9102..ead1f0a4688 100644 --- a/java-frontend/src/main/java/org/sonar/java/resolve/ParametrizedTypeJavaType.java +++ b/java-frontend/src/main/java/org/sonar/java/resolve/ParametrizedTypeJavaType.java @@ -66,30 +66,24 @@ public boolean isSubtypeOf(Type superType) { if (((JavaType) superType).isTagged(TYPEVAR)) { return false; } - if(erasure() == superType.erasure()) { - if (((JavaType) superType).isParameterized()) { - return checkSubstitutedTypesCompatibility((ParametrizedTypeJavaType) superType); - } + if (erasure() == superType.erasure()) { + return !((JavaType) superType).isParameterized() || checkSubstitutedTypesCompatibility((ParametrizedTypeJavaType) superType); + } + if (verifySuperTypes(superType)) { return true; } + return ((JavaType) superType).isTagged(WILDCARD) && ((WildCardType) superType).isSubtypeOfBound(this); + } + private boolean verifySuperTypes(Type superType) { JavaType superclass = symbol.getSuperclass(); - if(superclass != null) { + if (superclass != null) { superclass = typeSubstitutionSolver.applySubstitution(superclass, this.typeSubstitution); - if(superclass.isSubtypeOf(superType)) { + if (superclass.isSubtypeOf(superType)) { return true; } } - for (JavaType superInterface : symbol.getInterfaces()) { - superclass = typeSubstitutionSolver.applySubstitution(superInterface, this.typeSubstitution); - if(superclass.isSubtypeOf(superType)) { - return true; - } - } - if (((JavaType) superType).isTagged(WILDCARD)) { - return ((WildCardType) superType).isSubtypeOfBound(this); - } - return false; + return symbol.getInterfaces().stream().map(si -> typeSubstitutionSolver.applySubstitution(si, this.typeSubstitution)).anyMatch(si -> si.isSubtypeOf(superType)); } private boolean checkSubstitutedTypesCompatibility(ParametrizedTypeJavaType superType) {