}
CompletionCandidates getCompletionCandidates(String textTillCarret)
{
CompletionParser parser = new CompletionParser(textTillCarret);
ArrayList<CodeCompletionInfo> ret = new ArrayList<CodeCompletionInfo>();
if(false == parser.isQualified())
{
///////////////////////////////////////////////////////////////////////////////
// The colums of the last completed table/view that match the tableNamePat
// will be returned on top of the collection
ret.addAll( getColumnsFromLastSelectionStartingWith(parser.getStringToParse()) );
//
//////////////////////////////////////////////////////////////////////////////
ret.addAll( Arrays.asList(_codeCompletionInfos.getInfosStartingWith(null, null, parser.getStringToParse())) );
}
else // 1 < buf.size()
{
String catalog = null;
int catAndSchemCount = 0;
if(_codeCompletionInfos.isCatalog(parser.getToken(0)))
{
catalog = parser.getToken(0);
catAndSchemCount = 1;
}
String schema = null;
if(_codeCompletionInfos.isSchema(parser.getToken(0)))
{
schema = parser.getToken(0);
catAndSchemCount = 1;
}
else if(_codeCompletionInfos.isSchema(parser.getToken(1)))
{
schema = parser.getToken(1);
catAndSchemCount = 2;
}
// Might also be a catalog or a schema name
String tableNamePat1 = parser.getToken(parser.size() - 2);
String colNamePat1 = parser.getToken(parser.size() - 1);
if(0 < catAndSchemCount)
{
String tableNamePat2 = parser.getToken(catAndSchemCount);
if(parser.size() > catAndSchemCount + 1)
{
String colNamePat2 = parser.getToken(catAndSchemCount+1);
ret.addAll( getColumnsForName(catalog, schema, tableNamePat2, colNamePat2, parser.getStringToParsePosition()) );
}
else
{
ret.addAll(Arrays.asList(_codeCompletionInfos.getInfosStartingWith(catalog, schema, tableNamePat2)));
}
}
else
{
ret.addAll( getColumnsForName(null, null, tableNamePat1, colNamePat1, parser.getStringToParsePosition()) );
}
}
CodeCompletionInfo[] ccis = ret.toArray(new CodeCompletionInfo[ret.size()]);
return new CompletionCandidates(ccis, parser.getReplacementStart(), parser.getStringToReplace());
}