@NotNull final CompletionResultSet result) {
final int offset = parameters.getOffset();
PsiElement position = parameters.getPosition();
PsiElement parent = PsiTreeUtil.getParentOfType(position, BnfExpression.class, BnfAttr.class, BnfRule.class, GeneratedParserUtilBase.DummyBlock.class);
if (parent != null && !(parent instanceof BnfStringLiteralExpression && !(parent.getParent() instanceof BnfAttr))) {
final BnfLexer lexer = new BnfLexer();
PsiReference referenceAt = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
final Set<String> existing;
if (referenceAt instanceof BnfReferenceImpl) {
existing = new THashSet<String>();
for (Object o : referenceAt.getVariants()) {
existing.add(((LookupElement)o).getLookupString());
}
}
else existing = null;
parameters.getOriginalFile().acceptChildren(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof BnfReferenceOrToken || element instanceof BnfStringLiteralExpression) {
PsiReference reference = element.getTextRange().containsOffset(offset) ? null : element.getReference();
if (reference != null) {
String text = StringUtil.unquoteString(element.getText());
if (existing != null && existing.contains(text)) return;
lexer.start(text);
if (lexer.getTokenType() == BnfTypes.BNF_ID && lexer.getTokenEnd() == text.length()) {
result.addElement(LookupElementBuilder.create(text));
}
}
}
else {