if (Character.isLetterOrDigit(c) && !inString && !inBuiltIn
&& !inNameFragment && !inParameters)
inNameFragment = true;
if (inNameFragment) {
if (c == LexicalConstants.QUESTION_MARK) {
fragments.add(new NameFragment(offsetStart, sb.toString()));
offsetStart = i;
sb.delete(0, sb.length());
inNameFragment = false;
inBuiltIn = true;
} else if (c == LexicalConstants.LEFT_PARENTHESIS) {
fragments.add(new NameFragment(offsetStart, sb.toString()));
offsetStart = i;
sb.delete(0, sb.length());
inNameFragment = false;
inParameters = true;
} else if (c == LexicalConstants.PERIOD) {
fragments.add(new NameFragment(offsetStart, sb.toString()));
offsetStart = i;
sb.delete(0, sb.length());
inNameFragment = true;
sb.append(c);
} else if (c == LexicalConstants.RIGHT_PARENTHESIS) {
// for now, forget about the stack
fragments.add(new NameFragment(offsetStart, sb.toString()));
offsetStart = i + 1;
sb.delete(0, sb.length());
inNameFragment = false;
} else
sb.append(c);
} else if (inBuiltIn) {
if (c == LexicalConstants.QUESTION_MARK) {
fragments.add(new BuiltInFragment(offsetStart, sb
.toString()));
offsetStart = i;
sb.delete(0, sb.length());
} else if (c == LexicalConstants.RIGHT_PARENTHESIS) {
fragments.add(new BuiltInFragment(offsetStart, sb
.toString()));
offsetStart = i + 1;
sb.delete(0, sb.length());
inBuiltIn = false;
} else if (c == LexicalConstants.PERIOD) {
fragments.add(new BuiltInFragment(offsetStart, sb
.toString()));
inNameFragment = true;
offsetStart = i;
sb.delete(0, sb.length());
inBuiltIn = false;
sb.append(c);
} else
sb.append(c);
} else if (inParameters) {
if (inString)
if (!escape && c == LexicalConstants.QUOT)
inString = false;
if (!inString && c == LexicalConstants.RIGHT_PARENTHESIS) {
fragments.add(new ParametersFragment(offsetStart, sb
.toString()));
offsetStart = i + 1;
sb.delete(0, sb.length());
} else
sb.append(c);
} else if (inString) {
if (escape)
sb.append(c);
else if (c == LexicalConstants.QUOT) {
fragments
.add(new StringFragment(offsetStart, sb.toString()));
offsetStart = i + 1;
sb.delete(0, sb.length());
} else if (c == LexicalConstants.BACKSLASH) {
doEscape = true;
sb.append(c);
} else
sb.append(c);
} else if (c == LexicalConstants.PERIOD) {
if (sb.length() > 0) {
if (inBuiltIn)
fragments.add(new BuiltInFragment(offsetStart, sb
.toString()));
else
fragments.add(new NameFragment(offsetStart, sb
.toString()));
}
inNameFragment = true;
offsetStart = i;
sb.delete(0, sb.length());
} else if (c == LexicalConstants.QUESTION_MARK) {
if (inBuiltIn)
fragments.add(new BuiltInFragment(offsetStart, sb
.toString()));
else
fragments.add(new NameFragment(offsetStart, sb.toString()));
inBuiltIn = true;
offsetStart = i;
sb.delete(0, sb.length());
} else if (c == LexicalConstants.LEFT_PARENTHESIS) {
if (fragments.size() == 0) {
// for now, forget about the stack
} else {
if (sb.length() > 0 && !inBuiltIn)
fragments.add(new NameFragment(offsetStart, sb
.toString()));
inParameters = true;
offsetStart = i;
sb.delete(0, sb.length());
}
} else if (c == '"') {
if (sb.length() > 0)
fragments.add(new NameFragment(offsetStart, sb.toString()));
inString = true;
offsetStart = i;
sb.delete(0, sb.length());
} else
sb.append(c);
escape = doEscape;
}
if (sb.length() > 0 || inBuiltIn) {
if (inBuiltIn)
fragments.add(new BuiltInFragment(offsetStart, sb.toString()));
else
fragments.add(new NameFragment(offsetStart, sb.toString()));
}
}