Skip to content

Commit 0f61cc1

Browse files
committed
Fix quality flaw: dupicate conditions
1 parent 5c53d10 commit 0f61cc1

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

java-checks/src/main/java/org/sonar/java/closeresource/CloseableVisitor.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,21 @@ private static boolean shouldBeIgnored(@Nullable ExpressionTree expression) {
155155

156156
private static boolean usesIgnoredCloseableAsArgument(ExecutionState executionState, List<ExpressionTree> arguments) {
157157
for (ExpressionTree argument : arguments) {
158-
if (isNewClassWithIgnoredArguments(executionState, argument)) {
159-
return true;
160-
} else if (isMethodInvocationWithIgnoredArguments(executionState, argument)) {
161-
return true;
162-
} else if (useIgnoredCloseable(executionState, argument) || isSubclassOfInputStreamOrOutputStreamWithoutClose(argument.symbolType())) {
158+
if (isIgnoredCloseableArgument(executionState, argument)) {
163159
return true;
164160
}
165161
}
166162
return false;
167163
}
168164

165+
private static boolean isIgnoredCloseableArgument(ExecutionState executionState, ExpressionTree argument) {
166+
return isNewClassWithIgnoredArguments(executionState, argument)
167+
|| isMethodInvocationWithIgnoredArguments(executionState, argument)
168+
|| useIgnoredCloseable(executionState, argument)
169+
|| isSubclassOfInputStreamOrOutputStreamWithoutClose(argument.symbolType());
170+
}
171+
172+
169173
private static boolean isNewClassWithIgnoredArguments(ExecutionState executionState, ExpressionTree argument) {
170174
return argument.is(Tree.Kind.NEW_CLASS) && usesIgnoredCloseableAsArgument(executionState, ((NewClassTree) argument).arguments());
171175
}

java-squid/src/main/java/org/sonar/java/ast/visitors/PublicApiChecker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ private boolean isPublicApi(ClassTree classTree, MethodTree methodTree) {
178178
Preconditions.checkNotNull(classTree);
179179
if (separateAccessorsFromMethods && AccessorsUtils.isAccessor(classTree, methodTree)) {
180180
return false;
181-
} else if (isPublicInterface(classTree)) {
181+
}
182+
if (isPublicInterface(classTree)) {
182183
return !hasOverrideAnnotation(methodTree);
183184
} else if (isEmptyDefaultConstructor(methodTree) || hasOverrideAnnotation(methodTree) || classTree.is(Tree.Kind.INTERFACE, Tree.Kind.ANNOTATION_TYPE)) {
184185
return false;

java-squid/src/main/java/org/sonar/java/resolve/Resolve.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,8 @@ private JavaSymbol selectMostSpecific(JavaSymbol m1, JavaSymbol m2, List<JavaTyp
520520
return m1;
521521
} else if (m2SignatureMoreSpecific) {
522522
return m2;
523-
} else {
524-
return new AmbiguityErrorJavaSymbol();
525523
}
524+
return new AmbiguityErrorJavaSymbol();
526525
}
527526

528527
/**

java-squid/src/main/java/org/sonar/java/resolve/SecondPass.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,11 @@ private void populateSuperclass(JavaSymbol.TypeJavaSymbol symbol, Resolve.Env en
127127
Scope enumParameters = ((JavaSymbol.TypeJavaSymbol) symbols.enumType.symbol()).typeParameters();
128128
JavaType.TypeVariableJavaType enumParameter = (JavaType.TypeVariableJavaType) enumParameters.lookup("E").get(0).type();
129129
type.supertype = parametrizedTypeCache.getParametrizedTypeType(symbols.enumType.symbol, new TypeSubstitution().add(enumParameter, type));
130-
} else if (tree.is(Tree.Kind.CLASS)) {
131-
// JLS8 8.1.4: the direct superclass of the class type C<F1,...,Fn> is
130+
} else if (tree.is(Tree.Kind.CLASS, Tree.Kind.INTERFACE)) {
131+
// For CLASS JLS8 8.1.4: the direct superclass of the class type C<F1,...,Fn> is
132132
// the type given in the extends clause of the declaration of C
133133
// if an extends clause is present, or Object otherwise.
134-
type.supertype = symbols.objectType;
135-
} else if(tree.is(Tree.Kind.INTERFACE)) {
136-
// JLS8 9.1.3: While every class is an extension of class Object, there is no single interface of which all interfaces are
134+
// For INTERFACE JLS8 9.1.3: While every class is an extension of class Object, there is no single interface of which all interfaces are
137135
// extensions.
138136
// but we can call object method on any interface type.
139137
type.supertype = symbols.objectType;

0 commit comments

Comments
 (0)