Skip to content

Commit

Permalink
Show "Channels:" header when channels are defined
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo committed Jan 30, 2025
1 parent 81a2305 commit 506527b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ ModelBridge returns ModelThing:
properties+=ModelProperty? (',' properties+=ModelProperty)*
']')?
('{'
('Things:')?
(thingsHeader?='Things:')?
things+=(ModelThing|ModelBridge)*
('Channels:')?
(channelsHeader?='Channels:')?
channels+=ModelChannel*

'}')?
Expand All @@ -43,7 +43,7 @@ ModelThing:
properties+=ModelProperty? (',' properties+=ModelProperty)*
']')?
('{'
('Channels:')?
(channelsHeader?='Channels:')?
channels+=ModelChannel*
'}')?
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ class ThingFormatter extends AbstractDeclarativeFormatter {
@Inject extension ThingGrammarAccess

override protected void configureFormatting(FormattingConfig c) {
c.setLinewrap(1, 1, 2).before("Bridge")
c.setLinewrap(1, 1, 2).before("Bridge", "Things:", "Channels:")
c.setLinewrap(1, 1, 2).before(modelThingRule)
c.setLinewrap(1, 1, 2).before(modelChannelRule)

c.setIndentationIncrement.after("{")
c.setIndentationDecrement.before("}")
c.setIndentationIncrement.before(modelChannelRule)
c.setIndentationDecrement.after(modelChannelRule)
c.setLinewrap().before("}")

c.setNoSpace().withinKeywordPairs("(", ")")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,17 @@ private ModelThing buildModelThing(Thing thing, boolean preferPresentationAsTree
}

if (preferPresentationAsTree && modelBridge != null) {
modelBridge.setThingsHeader(false);
for (Thing child : getChildThings(thing)) {
if (onlyThings.contains(child) && !handledThings.contains(child)) {
modelBridge.getThings().add(buildModelThing(child, true, false, onlyThings, handledThings));
}
}
}

for (Channel channel : getNonDefaultChannels(thing)) {
List<Channel> channels = getNonDefaultChannels(thing);
model.setChannelsHeader(!channels.isEmpty());
for (Channel channel : channels) {
model.getChannels().add(buildModelChannel(channel));
}

Expand Down

0 comments on commit 506527b

Please sign in to comment.