Skip to content

Commit

Permalink
Merge pull request #535 from scireum/feature/jmu/SE-13940-remove-repl…
Browse files Browse the repository at this point in the history
…ace-warning

Don't warn about replaced parts
  • Loading branch information
jmuscireum authored Aug 23, 2024
2 parents 4e95c29 + 54682e3 commit b38bf9d
Showing 1 changed file with 7 additions and 13 deletions.
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

0 comments on commit b38bf9d

Please sign in to comment.