Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import org.sonar.plugins.java.api.semantic.MethodMatchers;
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.tree.MethodInvocationTree;
Expand All @@ -35,27 +36,36 @@ public MethodMatchersList(List<? extends MethodMatchers> matchers) {

@Override
public boolean matches(NewClassTree newClassTree) {
return matchers.stream().anyMatch(matcher -> matcher.matches(newClassTree));
return matchesAny(matcher -> matcher.matches(newClassTree));
}

@Override
public boolean matches(MethodInvocationTree mit) {
return matchers.stream().anyMatch(matcher -> matcher.matches(mit));
return matchesAny(matcher -> matcher.matches(mit));
}

@Override
public boolean matches(MethodTree methodTree) {
return matchers.stream().anyMatch(matcher -> matcher.matches(methodTree));
return matchesAny(matcher -> matcher.matches(methodTree));
}

@Override
public boolean matches(MethodReferenceTree methodReferenceTree) {
return matchers.stream().anyMatch(matcher -> matcher.matches(methodReferenceTree));
return matchesAny(matcher -> matcher.matches(methodReferenceTree));
}

@Override
public boolean matches(Symbol symbol) {
return matchers.stream().anyMatch(matcher -> matcher.matches(symbol));
return matchesAny(matcher -> matcher.matches(symbol));
}

private boolean matchesAny(Predicate<MethodMatchers> predicate) {
for (MethodMatchers matcher : matchers) {
if (predicate.test(matcher)) {
return true;
}
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.eclipse.jdt.core.dom.ASTUtils;
import org.eclipse.jdt.core.dom.IMethodBinding;
Expand Down Expand Up @@ -158,11 +157,12 @@ void findOverridesInParentTypes(Collection<MethodSymbol> accumulator, Predicate<
private void findOverridesInTypes(Collection<MethodSymbol> accumulator, Predicate<IMethodBinding> overridesCondition, ITypeBinding... types) {
for (ITypeBinding type : types) {
if (type != null) {
Stream.of(type.getDeclaredMethods())
.filter(overridesCondition)
.findFirst()
.map(sema::methodSymbol)
.ifPresent(accumulator::add);
for (IMethodBinding declaredMethod : type.getDeclaredMethods()) {
if (overridesCondition.test(declaredMethod)) {
accumulator.add(sema.methodSymbol(declaredMethod));
break;
}
}
findOverridesInParentTypes(accumulator, overridesCondition, type);
}
}
Expand Down
Loading