Skip to content

Commit

Permalink
use aliases for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Dec 25, 2023
1 parent 909f6de commit c1802f2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/org/comroid/api/DataStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.comroid.util.Constraint;
import org.comroid.util.StandardValueType;
import org.comroid.util.Switch;
import org.comroid.util.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -16,7 +17,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

import static org.comroid.annotations.Annotations.aliases;
import static org.comroid.api.Polyfill.uncheckedCast;
import static org.comroid.util.Streams.append;

@Value
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down Expand Up @@ -106,17 +109,18 @@ else if (it instanceof Method)
.filter(it -> !Annotations.ignore(it, DataStructure.class))
.filter(it -> !key.above.equals(it.getDeclaringClass()) && key.above.isAssignableFrom(it.getDeclaringClass()))
.filter(it -> Arrays.stream(SystemFilters).noneMatch(type -> it.getDeclaringClass().isAssignableFrom(type)))
.map(it -> {
.forEach(it -> {
var type = new Switch<Member, Class<?>>()
.option(Field.class::isInstance, () -> ((Field) it).getType())
.option(Method.class::isInstance, () -> ((Method) it).getReturnType())
.apply(it);
var name = it.getName();
if (it instanceof Method)
name = Character.toLowerCase(name.charAt(3)) + name.substring("getX".length());
return struct.createProperty(type, name, it);
})
.forEach(prop -> struct.properties.put(prop.name, prop));
final var prop = struct.createProperty(type, name, it);
Stream.of(name).collect(append(aliases(it)))
.forEach(alias -> struct.properties.put(alias, prop));
});

return struct;
}
Expand Down

0 comments on commit c1802f2

Please sign in to comment.