TextRange (String line, int from, int to) { if (to - from > 200) return null; boolean hasDot = false; for (int i = from; i < to; i++) { char c = line.charAt(i); if (c == '.' && i == from) return null; if (c == '$' && !hasDot) return null; if (c != '.' && c != '$' && !Character.isJavaIdentifierPart(c)) return null; hasDot |= c == '.'; } if (!hasDot) return null; return new TextRange(from, to); }