* (named elements do not have parents)
*/
public Set<TokenType> getNextRequiredTokens() {
if (nextRequiredTokens == null) {
nextRequiredTokens = new THashSet<TokenType>();
ElementType elementType = getElementType();
ElementType parentElementType = elementType.getParent();
while (parentElementType != null) {
if (parentElementType instanceof SequenceElementType) {
SequenceElementType sequence = (SequenceElementType) parentElementType;
int elementsCount = sequence.getElementTypes().length;
int index = sequence.indexOf(elementType, 0);
for (int i = index + 1; i < elementsCount; i++) {
if (!sequence.isOptional(i)) {
ElementType next = sequence.getElementTypes()[i];
nextRequiredTokens.addAll(next.getLookupCache().getFirstPossibleTokens());
parentElementType = null;
break;
}
}
} else if (parentElementType instanceof IterationElementType) {