ProhibitedMethods Class — spring-boot Architecture
Architecture documentation for the ProhibitedMethods class in TaskConfigurationAvoidanceTests.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/TaskConfigurationAvoidanceTests.java lines 69–156
private static final class ProhibitedMethods implements Predicate<JavaMethodCall> {
private final List<Predicate<JavaMethodCall>> prohibited = new ArrayList<>();
private ProhibitedConfigurer on(Class<?> type) {
return new ProhibitedConfigurer(type);
}
@Override
public boolean test(JavaMethodCall methodCall) {
for (Predicate<JavaMethodCall> spec : this.prohibited) {
if (spec.test(methodCall)) {
return true;
}
}
return false;
}
private final class ProhibitedConfigurer {
private final Class<?> type;
private ProhibitedConfigurer(Class<?> type) {
this.type = type;
}
private ProhibitedConfigurer methodsNamed(String... names) {
for (String name : names) {
ProhibitedMethods.this.prohibited.add(new ProhibitMethodsNamed(this.type, name));
}
return this;
}
private ProhibitedConfigurer method(String name, Class<?>... parameterTypes) {
ProhibitedMethods.this.prohibited
.add(new ProhibitMethod(this.type, name, Arrays.asList(parameterTypes)));
return this;
}
}
static class ProhibitMethodsNamed implements Predicate<JavaMethodCall> {
private final Class<?> owner;
private final String name;
ProhibitMethodsNamed(Class<?> owner, String name) {
this.owner = owner;
this.name = name;
}
@Override
public boolean test(JavaMethodCall methodCall) {
return methodCall.getTargetOwner().isEquivalentTo(this.owner) && methodCall.getName().equals(this.name);
}
}
private static final class ProhibitMethod extends ProhibitMethodsNamed {
private final List<Class<?>> parameterTypes;
private ProhibitMethod(Class<?> owner, String name, List<Class<?>> parameterTypes) {
super(owner, name);
this.parameterTypes = parameterTypes;
}
@Override
public boolean test(JavaMethodCall methodCall) {
return super.test(methodCall) && match(methodCall.getTarget().getParameterTypes());
}
private boolean match(List<JavaType> callParameterTypes) {
if (this.parameterTypes.size() != callParameterTypes.size()) {
return false;
}
for (int i = 0; i < this.parameterTypes.size(); i++) {
if (!callParameterTypes.get(i).toErasure().isEquivalentTo(this.parameterTypes.get(i))) {
return false;
}
}
return true;
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free