public Set<Decl> getDeclsForAllElements(List<AltAST> altASTs) {
		Set<String> needsList = new HashSet<String>();
		Set<String> nonOptional = new HashSet<String>();
		List<GrammarAST> allRefs = new ArrayList<GrammarAST>();
		boolean firstAlt = true;
		IntervalSet reftypes = new IntervalSet(RULE_REF, TOKEN_REF, STRING_LITERAL);
		for (AltAST ast : altASTs) {
			List<GrammarAST> refs = getRuleTokens(ast.getNodesWithType(reftypes));
			allRefs.addAll(refs);
			Pair<FrequencySet<String>, FrequencySet<String>> minAndAltFreq = getElementFrequenciesForAlt(ast);
			FrequencySet<String> minFreq = minAndAltFreq.a;
			FrequencySet<String> altFreq = minAndAltFreq.b;
			for (GrammarAST t : refs) {
				String refLabelName = getName(t);

				if (refLabelName != null) {
					if (altFreq.count(refLabelName) > 1) {
						needsList.add(refLabelName);
					}

					if (firstAlt && minFreq.count(refLabelName) != 0) {
						nonOptional.add(refLabelName);
					}
				}
			}

			for (String ref : nonOptional.toArray(new String[0])) {
				if (minFreq.count(ref) == 0) {
					nonOptional.remove(ref);
				}
			}

			firstAlt = false;
		}
		Set<Decl> decls = new LinkedHashSet<Decl>();
		for (GrammarAST t : allRefs) {
			String refLabelName = getName(t);

			if (refLabelName == null) {
				continue;
			}

			List<Decl> d = getDeclForAltElement(t,
												refLabelName,
												needsList.contains(refLabelName),
												!nonOptional.contains(refLabelName));
			decls.addAll(d);
		}
		return decls;
	}
for all alts, find which ref X or r needs List
	   Must see across alts. If any alt needs X or r as list, then
	   define as list.
tool/src/org/antlr/v4/codegen/model/RuleFunction.java