else if (Rule.isPrivate(metaRule)) {
result = psiMap();
Map<PsiElement, Cardinality> metaResults = getPrivateRuleContent(metaRule, visited);
List<String> params = null;
for (PsiElement member : metaResults.keySet()) {
Cardinality cardinality = metaResults.get(member);
if (!(member instanceof BnfExternalExpression)) {
result.put(member, cardinality);
}
else {
if (params == null) {
params = collectExtraArguments(metaRule, metaRule.getExpression());
}
int idx = params.indexOf(member.getText());
if (idx > -1 && idx + 1 < expressionList.size()) {
Map<PsiElement, Cardinality> argMap = collectMembers(rule, expressionList.get(idx + 1), visited);
for (PsiElement element : argMap.keySet()) {
result.put(element, cardinality.and(argMap.get(element)));
}
}
}
}
}
else {
result = psiMap(metaRule, REQUIRED);
}
}
if (firstNonTrivial && willCollapse(rule, result) && !Rule.isPrivate(rule)) {
result = Collections.emptyMap();
}
}
else {
List<BnfExpression> pinned = ContainerUtil.newArrayList();
GrammarUtil.processPinnedExpressions(rule, new CommonProcessors.CollectProcessor<BnfExpression>(pinned));
boolean pinApplied = false;
IElementType type = getEffectiveType(tree);
List<Map<PsiElement, Cardinality>> list = new ArrayList<Map<PsiElement, Cardinality>>();
List<BnfExpression> childExpressions = getChildExpressions(tree);
for (BnfExpression child : childExpressions) {
Map<PsiElement, Cardinality> nextMap = collectMembers(rule, child, visited);
if (pinApplied) {
nextMap = joinMaps(rule, false, BnfTypes.BNF_OP_OPT, Collections.singletonList(nextMap));
}
list.add(nextMap);
if (!pinApplied && pinned.contains(child)) {
pinApplied = true;
}
}
result = joinMaps(rule, firstNonTrivial, type, list);
result = result.remove(rule.getExpression()) != null ? joinMaps(rule, false, type, Arrays.asList(result, result)) : result;
}
if (rule.getExpression() == tree && Rule.isLeft(rule) && !Rule.isPrivate(rule) && !Rule.isInner(rule)) {
List<Map<PsiElement, Cardinality>> list = new ArrayList<Map<PsiElement, Cardinality>>();
Map<BnfRule, Cardinality> rulesToTheLeft = getRulesToTheLeft(rule);
for (BnfRule r : rulesToTheLeft.keySet()) {
Cardinality cardinality = rulesToTheLeft.get(r);
Map<PsiElement, Cardinality> leftMap = psiMap(r, REQUIRED);
if (cardinality.many()) {
list.add(joinMaps(rule, false, BnfTypes.BNF_CHOICE, Arrays.asList(leftMap, psiMap(rule, REQUIRED))));
}
else {
list.add(leftMap);
}