org.gradle.model.internal.manage.schema.extract.CandidateMethods Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.model.internal.manage.schema.extract;
import com.google.common.base.Equivalence;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.*;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
public class CandidateMethods {
private final Map, Collection>> candidates;
public CandidateMethods(Map, Collection>> candidates) {
this.candidates = candidates;
}
/**
* @return TRUE if no candidate methods, FALSE otherwise
*/
boolean isEmpty() {
return candidates.isEmpty();
}
/**
* @return All candidate methods names
*/
public Iterable methodNames() {
return candidates.keySet();
}
/**
* @return All candidate methods indexed by signature equivalence
*/
public Map, Collection> allMethods() {
ImmutableMap.Builder, Collection> builder = ImmutableMap.builder();
for (Map, Collection> candidatesForSomeName : candidates.values()) {
builder.putAll(candidatesForSomeName);
}
return builder.build();
}
/**
* @param methodName Method name
* @return Candidate methods named {@literal methodName} or {@literal null} if none
*/
Map, Collection> methodsNamed(String methodName) {
if (candidates.containsKey(methodName)) {
return candidates.get(methodName);
}
return Collections., Collection>emptyMap();
}
/**
* @param methodName Method name
* @return Overridden candidate methods named {@literal methodName} indexed by signature equivalence or
* {@literal null} if none
*/
public Map, Collection> overriddenMethodsNamed(String methodName) {
if (candidates.containsKey(methodName)) {
return Maps.filterValues(candidates.get(methodName), new Predicate>() {
@Override
public boolean apply(Collection equivalentMethods) {
return equivalentMethods.size() > 1;
}
});
}
return Collections., Collection>emptyMap();
}
/**
* @param methodName Method name
* @param excludes Signature equivalences to exclude from the returned index
* @return Overloaded candidate methods named {@literal methodName} indexed by signature equivalence except thoses
* matching any of the signature equivalence provided in {@literal excludes} or {@literal null} if none
*/
public Map, Collection> overloadedMethodsNamed(String methodName, Collection> excludes) {
return Maps.filterKeys(overloadedMethodsNamed(methodName), Predicates.not(Predicates.in(excludes)));
}
/**
* @param methodName Method name
* @return Overloaded candidate methods named {@literal methodName} indexed by signature equivalence or
* {@literal null} if none
*/
Map, Collection> overloadedMethodsNamed(String methodName) {
if (candidates.containsKey(methodName)) {
Map, Collection> overloadeds = candidates.get(methodName);
if (overloadeds.size() > 1) {
return overloadeds;
}
}
return Collections., Collection>emptyMap();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy