private QualifiedIdentifierVariant getMostProbableParseVariant_(ParserBuilder builder, ParsePathNode node) {
TokenElementType separatorToken = getElementType().getSeparatorToken();
QualifiedIdentifierVariant mostProbableVariant = null;
int initialSiblingIndex = node.getCurrentSiblingIndex();
try {
for (LeafElementType[] variants : getElementType().getVariants()) {
int offset = 0;
//PsiBuilder.Marker marker = builder.mark();
int matchedTokens = 0;
for (int i=0; i< variants.length; i++) {
TokenType tokenType = builder.lookAhead(offset);
// if no mach -> consider as partial if not first element
node.setCurrentSiblingIndex(i);
if (match(variants[i], tokenType, node, true)) {
matchedTokens++;
offset++;
tokenType = builder.lookAhead(offset);
boolean isSeparator = tokenType == separatorToken.getTokenType();
boolean isFullMatch = matchedTokens == variants.length;
boolean isLastElement = i == variants.length - 1;
if (isLastElement) {
QualifiedIdentifierVariant variant = new QualifiedIdentifierVariant(variants, matchedTokens);
if ((isFullMatch && !isSeparator) || variant.containsNonIdentifierTokens()) {
//markerRollbackTo(marker);
return variant;
}
if (mostProbableVariant == null || matchedTokens > mostProbableVariant.getMatchedTokens()) {
mostProbableVariant = variant;
}
break;
} else {
if (!isSeparator) { // is not separator token
QualifiedIdentifierVariant variant = new QualifiedIdentifierVariant(variants, matchedTokens);
if (mostProbableVariant == null || mostProbableVariant.getMatchedTokens() < variant.getMatchedTokens()) {
mostProbableVariant = variant;
}
break;
}
}
offset++;
} else {
if (matchedTokens > 0) {
QualifiedIdentifierVariant variant = new QualifiedIdentifierVariant(variants, matchedTokens);
if (variant.containsNonIdentifierTokens()) {
//markerRollbackTo(marker);
return variant;
}
if (mostProbableVariant == null || mostProbableVariant.getMatchedTokens() < variant.getMatchedTokens()) {
mostProbableVariant = variant;
}
}
break;
}