Skip to content

Commit

Permalink
Handle map keys with idRef
Browse files Browse the repository at this point in the history
  • Loading branch information
milesziemer committed Jan 19, 2024
1 parent e536ea2 commit b8a7aad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ private static NodeQuery buildNodeQuery(PathFinder.Path path) {
break;
}
switch (relationship.getRelationshipType()) {
case MEMBER_TARGET:
case MAP_KEY:
case TRAIT:
case MIXIN:
default:
query.anyMemberName();
break;
case MAP_VALUE:
query.anyMember();
Expand All @@ -98,6 +95,9 @@ private static NodeQuery buildNodeQuery(PathFinder.Path path) {
MemberShape member = (MemberShape) relationship.getNeighborShape().get();
query.member(member.getMemberName());
break;
default:
// Other relationship types don't produce meaningful edges to search the node.
break;
}
}
return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ NodeQuery anyElement() {
return this;
}

NodeQuery anyMemberName() {
queries.add(node -> {
if (node == null || !node.isObjectNode()) {
return Stream.empty();
}
return node.expectObjectNode().getMembers().keySet().stream();
});
return this;
}

List<Node> execute(Node node) {
if (queries.isEmpty()) {
return ListUtils.of();
Expand All @@ -72,6 +82,6 @@ List<Node> execute(Node node) {

@FunctionalInterface
interface Query {
Stream<Node> run(Node node);
Stream<? extends Node> run(Node node);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ operation GetFoo {
eight: Eight
nine: Nine
ten: Ten
eleven: Eleven
}
}

// --
@trait
structure withIdRefOnMember {
@idRef(failWhenMissing: true, selector: "*")
@idRef(failWhenMissing: true)
ref: String
}

Expand All @@ -40,7 +41,7 @@ structure withIdRefOnMemberTarget {
ref: OnTarget
}

@idRef(failWhenMissing: true, selector: "*")
@idRef(failWhenMissing: true)
string OnTarget

@withIdRefOnMemberTarget(ref: Ref2)
Expand All @@ -55,7 +56,7 @@ structure withIdRefOnNestedStructureMember {
}

structure Nested {
@idRef(failWhenMissing: true, selector: "*")
@idRef(failWhenMissing: true)
member: String
}

Expand All @@ -75,7 +76,7 @@ list withIdRefOnListMemberTarget {
member: OnListMemberTarget
}

@idRef(failWhenMissing: true, selector: "*")
@idRef(failWhenMissing: true)
string OnListMemberTarget

@withIdRefOnListMemberTarget([
Expand All @@ -87,7 +88,7 @@ structure Ref4 {}

// --
@trait
@idRef(failWhenMissing: true, selector: "*")
@idRef(failWhenMissing: true)
string withIdRefOnSelf

@withIdRefOnSelf(Ref5)
Expand Down Expand Up @@ -126,7 +127,7 @@ structure withIdRefThroughMixin with [ThroughMixin] {}

@mixin
structure ThroughMixin {
@idRef(failWhenMissing: true, selector: "*")
@idRef(failWhenMissing: true)
ref: String
}

Expand All @@ -142,7 +143,7 @@ map withIdRefOnMapValue {
value: OnMap
}

@idRef(failWhenMissing: true, selector: "*")
@idRef(failWhenMissing: true)
string OnMap

@withIdRefOnMapValue({
Expand All @@ -169,18 +170,15 @@ structure Ten {}
structure Ref10 {}

// --
// NOTE: This actually doesn't work because map key of 'Ref11' it says isn't a valid
// shape id.

//@trait
//map withIdRefOnMapKey {
// key: OnMap
// value: String
//}
@trait
map withIdRefOnMapKey {
key: OnMap
value: String
}

//@withIdRefOnMapKey({
// Ref11: "foo"
//})
//structure Eleven {}
@withIdRefOnMapKey({
"com.foo#Ref11": "foo"
})
structure Eleven {}

//structure Ref11 {}
structure Ref11 {}

0 comments on commit b8a7aad

Please sign in to comment.