1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Updated Scanner to allow for more robust completion in #if directives.

This commit is contained in:
John Camelon 2004-01-30 22:41:56 +00:00
parent df79974b26
commit de5b46412d
2 changed files with 42 additions and 23 deletions

View file

@ -1,3 +1,6 @@
2004-01-30 John Camelon
Updated Scanner to allow for more robust completion in #if directives.
2004-01-30 John Camelon 2004-01-30 John Camelon
Fixed Bug 50487 - Wrong completion kind and prefix after "#ifdef" Fixed Bug 50487 - Wrong completion kind and prefix after "#ifdef"

View file

@ -1827,7 +1827,7 @@ public class Scanner implements IScanner {
*/ */
private void handleCompletionOnDefinition(String definition) throws EndOfFileException { private void handleCompletionOnDefinition(String definition) throws EndOfFileException {
IASTCompletionNode node = new ASTCompletionNode( IASTCompletionNode.CompletionKind.MACRO_REFERENCE, IASTCompletionNode node = new ASTCompletionNode( IASTCompletionNode.CompletionKind.MACRO_REFERENCE,
null, null, definition, KeywordSets.getKeywords(KeywordSets.Key.MACRO, language) ); null, null, definition, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, language) );
throwEOF( node ); throwEOF( node );
} }
@ -1836,9 +1836,17 @@ public class Scanner implements IScanner {
* @param expression2 * @param expression2
*/ */
private void handleCompletionOnExpression(String expression) throws EndOfFileException { private void handleCompletionOnExpression(String expression) throws EndOfFileException {
int completionPoint = expression.length(); int completionPoint = expression.length() + 2;
IASTCompletionNode.CompletionKind kind = IASTCompletionNode.CompletionKind.MACRO_REFERENCE;
String prefix = "";
if( ! expression.trim().equals(""))
{
IScanner subScanner = ParserFactory.createScanner( new StringReader(expression), SCRATCH, EMPTY_INFO, ParserMode.QUICK_PARSE, language, new NullSourceElementRequestor(), new NullLogService()); IScanner subScanner = ParserFactory.createScanner( new StringReader(expression), SCRATCH, EMPTY_INFO, ParserMode.QUICK_PARSE, language, new NullSourceElementRequestor(), new NullLogService());
IToken lastToken = null; IToken lastToken = null;
while( true )
{
try try
{ {
lastToken = subScanner.nextToken(); lastToken = subScanner.nextToken();
@ -1846,22 +1854,30 @@ public class Scanner implements IScanner {
catch( EndOfFileException eof ) catch( EndOfFileException eof )
{ {
// ok // ok
break;
} catch (ScannerException e) { } catch (ScannerException e) {
handleInternalError(); handleInternalError();
break;
}
} }
String prefix = "";
if( ( lastToken != null )) if( ( lastToken != null ))
{ {
if( ( lastToken.getType() == IToken.tIDENTIFIER ) if( ( lastToken.getType() == IToken.tIDENTIFIER )
&& ( lastToken.getEndOffset() == completionPoint ) ) && ( lastToken.getEndOffset() == completionPoint ) )
{
prefix = lastToken.getImage(); prefix = lastToken.getImage();
else if( ( lastToken.getEndOffset() == completionPoint ) &&
( lastToken.getType() != IToken.tIDENTIFIER ) )
kind = IASTCompletionNode.CompletionKind.NO_SUCH_KIND;
} }
} }
IASTCompletionNode node = new ASTCompletionNode( IASTCompletionNode.CompletionKind.MACRO_REFERENCE, IASTCompletionNode node = new ASTCompletionNode( kind,
null, null, prefix, KeywordSets.getKeywords(KeywordSets.Key.MACRO, language) ); null, null, prefix,
KeywordSets.getKeywords(((kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND )? KeywordSets.Key.EMPTY : KeywordSets.Key.MACRO), language) );
throwEOF( node ); throwEOF( node );
} }