// Step 1, must format up to the first selector entry expression to know the correct indentation of the selector entry
// expression. (At point of entry to this method, the whitespace between a preceding statement and the selector
// expression has not yet been processed, and thus, no WS, break, indent etc. has taken place.
//
DelegatingLayoutContext dlc = new DelegatingLayoutContext(context);
MeasuredTextFlow continuedFlow = new MeasuredTextFlow((MeasuredTextFlow) flow);
int currentMaxWidth = flow.getPreferredMaxWidth();
int availableWidth = 0; // set when first case is seen
// IBreakAndAlignAdvice advice = adviceProvider.get(); // TODO: Advice? this formatting ?
final boolean doAlignment = true; // advice.isAlignCases();
// used to collect the widths of each case's width of its values
List<Integer> widths = Lists.newArrayList();
// int maxLastLine = 0;
boolean firstSelectoEntrySeen = false;
List<IDomNode> fatCommaNodes = Lists.newArrayList();
IntegerCluster clusters = new IntegerCluster(SELECTOR_EXPRESSION_CLUSTER_SIZE);
for(IDomNode n : node.getChildren()) {
if(n.getGrammarElement() instanceof RuleCall &&
((RuleCall) n.getGrammarElement()).getRule() == selectorEntryRule) {
if(!firstSelectoEntrySeen) {
// finish measurement of the position the selectorEntry will appear at
//
continuedFlow.appendBreak();
continuedFlow.getIndentation();
availableWidth = currentMaxWidth - (continuedFlow.getIndentation() + 1) *
continuedFlow.getIndentSize();
}
// used to measure output of formatted selector entry values
// adjust its width to available width (and do not mark items consumed in the given context)
DelegatingLayoutContext innerContext = new DelegatingLayoutContext(context, availableWidth);
TextFlow measuredFlow = new TextFlow(innerContext);