Skip to content

Commit

Permalink
revert change to DiscriminatorFunction parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
evanchooly committed Aug 19, 2024
1 parent 096f88d commit befcca8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.morphia.mapping;

import com.mongodb.lang.NonNull;

import dev.morphia.mapping.discriminator.ClassNameDiscriminator;
import dev.morphia.mapping.discriminator.LowerClassNameDiscriminator;
import dev.morphia.mapping.discriminator.LowerSimpleNameDiscriminator;
Expand Down Expand Up @@ -57,7 +55,7 @@ public static DiscriminatorFunction simpleName() {
* @return
* @hidden
*/
public final String apply(String type, String discriminator) {
public final String apply(Class<?> type, String discriminator) {
return discriminator.equals(Mapper.IGNORED_FIELDNAME) ? compute(type) : discriminator;
}

Expand All @@ -67,9 +65,6 @@ public final String apply(String type, String discriminator) {
* @return the discriminator value
* @param type
*/
public final String compute(Class<?> type) {
return compute(type.getName());
}
public abstract String compute(Class<?> type);

public abstract String compute(@NonNull String type);
}
8 changes: 0 additions & 8 deletions core/src/main/java/dev/morphia/mapping/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@
public class Mapper {
private static final Logger LOG = LoggerFactory.getLogger(Mapper.class);

public static String simpleName(String type) {
while (!Character.isUpperCase(type.charAt(0)) && type.contains(".")) {
type = type.substring(type.indexOf('.') + 1);
}

return type;
}

/**
* Special name that can never be used. Used as default for some fields to indicate default state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void apply(Mapper mapper, EntityModel model) {
model.annotation(entity);
}

model.discriminator(config.discriminator().apply(model.getType().getName(), entity.discriminator()));
model.discriminator(config.discriminator().apply(model.getType(), entity.discriminator()));
}

public static String applyDefaults(String configured, String defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class ClassNameDiscriminator extends DiscriminatorFunction {
@Override
public String compute(String type) {
return type;
public String compute(Class<?> type) {
return type.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class LowerClassNameDiscriminator extends DiscriminatorFunction {
@Override
public String compute(String type) {
return type.toLowerCase();
public String compute(Class<?> type) {
return type.getName().toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dev.morphia.mapping.discriminator;

import dev.morphia.mapping.DiscriminatorFunction;
import dev.morphia.mapping.Mapper;

public class LowerSimpleNameDiscriminator extends DiscriminatorFunction {
@Override
public String compute(String type) {
return Mapper.simpleName(type).toLowerCase();
public String compute(Class<?> type) {
return type.getSimpleName().toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dev.morphia.mapping.discriminator;

import dev.morphia.mapping.DiscriminatorFunction;
import dev.morphia.mapping.Mapper;

public class SimpleNameDiscriminator extends DiscriminatorFunction {
@Override
public String compute(String type) {
return Mapper.simpleName(type);
public String compute(Class<?> type) {
return type.getSimpleName();
}
}
4 changes: 4 additions & 0 deletions docs/modules/ROOT/examples/complete-morphia-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ morphia.ignore-finals=false
######
morphia.packages=.*
######
# default=dev.morphia.config.MorphiaPropertyAnnotationProvider
######
morphia.property-annotation-providers=dev.morphia.config.MorphiaPropertyAnnotationProvider
######
# default=fields
# possible values=fields, methods
######
Expand Down

0 comments on commit befcca8

Please sign in to comment.