Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't warn about replaced parts #535

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
20 changes: 7 additions & 13 deletions src/main/java/sirius/kernel/di/PartRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,11 @@ private void wireField(Object object, Field field) {

@Override
public void registerPart(Object part, Class<?>... implementedInterfaces) {
String customizationName = Sirius.getCustomizationName(part.getClass().getName());
if (!Sirius.isActiveCustomization(customizationName)) {
if (!Sirius.isActiveCustomization(Sirius.getCustomizationName(part.getClass().getName()))) {
return;
}
Object successor = shadowMap.get(part.getClass());
Class<?> predecessor = determinePredecessor(part, customizationName);
Class<?> predecessor = determinePredecessor(part);

registerPart(part, implementedInterfaces, predecessor, successor);
}
Expand All @@ -225,23 +224,18 @@ private void registerPart(Object part, Class<?>[] implementedInterfaces, Class<?
}
}

private Class<?> determinePredecessor(Object part, String customizationName) {
private Class<?> determinePredecessor(Object part) {
Class<?> predecessor = part.getClass().isAnnotationPresent(Replace.class) ?
part.getClass().getAnnotation(Replace.class).value() :
null;
if (predecessor == null) {
return null;
}

if (customizationName == null) {
if (Sirius.isStartedAsTest() && part.getClass().getSimpleName().endsWith("Mock")) {
Injector.LOG.WARN("%s is mocked by %s", predecessor, part.getClass());
} else {
Injector.LOG.WARN(
"@Replace should be only used within a customization. %s (%s) seems to be a base class!",
part,
part.getClass());
}
if (Sirius.isStartedAsTest() && part.getClass().getSimpleName().endsWith("Mock")) {
Injector.LOG.WARN("%s is mocked by %s", predecessor, part.getClass());
} else {
Injector.LOG.INFO("Part %s is replaced by %s using @Replace", predecessor, part.getClass());
}

shadowMap.put(predecessor, part);
Expand Down