mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Partial fix for <A HREF="https://bugs.eclipse.org/bugs/show_bug.cgi?id=57898">Bug 57898 [Search] Selection search does not work under all circumstances</A>
This commit is contained in:
parent
daaf6bcf2b
commit
5f7bf6d199
4 changed files with 99 additions and 6 deletions
|
@ -1,3 +1,6 @@
|
|||
2004-04-10 John Camelon
|
||||
Partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=57898
|
||||
|
||||
2004-04-09 Andrew Niefer
|
||||
handle NPE during template argument deduction
|
||||
fix bug in definitions of certain template member templates (fixes a ClassCastException encountered in <list>)
|
||||
|
|
|
@ -336,10 +336,19 @@ public class ExpressionParser implements IExpressionParser {
|
|||
}
|
||||
}
|
||||
|
||||
return new TokenDuple(first, last, ( hasTemplateId ? argumentList : null ) );
|
||||
ITokenDuple tokenDuple = new TokenDuple(first, last, ( hasTemplateId ? argumentList : null ) );
|
||||
setGreaterNameContext( tokenDuple );
|
||||
return tokenDuple;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tokenDuple
|
||||
*/
|
||||
protected void setGreaterNameContext(ITokenDuple tokenDuple) {
|
||||
//do nothing in this implementation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scope
|
||||
* @param kind
|
||||
|
@ -2548,8 +2557,7 @@ public class ExpressionParser implements IExpressionParser {
|
|||
|
||||
try
|
||||
{
|
||||
IToken value = scanner.nextToken();
|
||||
handleNewToken( value );
|
||||
IToken value = scanner.nextToken();
|
||||
return value;
|
||||
}
|
||||
catch( OffsetLimitReachedException olre )
|
||||
|
@ -2629,6 +2637,7 @@ public class ExpressionParser implements IExpressionParser {
|
|||
if (currToken != null)
|
||||
lastToken = currToken;
|
||||
currToken = currToken.getNext();
|
||||
handleNewToken( lastToken );
|
||||
return lastToken;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
|
@ -35,6 +37,8 @@ public class SelectionParser extends ContextualParser {
|
|||
private IASTScope ourScope = null;
|
||||
private IASTCompletionNode.CompletionKind ourKind = null;
|
||||
private IASTNode ourContext = null;
|
||||
private ITokenDuple greaterContextDuple = null;
|
||||
private boolean pastPointOfSelection = false;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken)
|
||||
|
@ -53,7 +57,7 @@ public class SelectionParser extends ContextualParser {
|
|||
TraceUtil.outputTrace(log, "Offset Ceiling Hit w/token \"", null, value.getImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
lastTokenOfDuple = value;
|
||||
}
|
||||
if( scanner.isOnTopContext() && lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset() )
|
||||
if( lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset() )
|
||||
{
|
||||
if ( ourScope == null )
|
||||
ourScope = getCompletionScope();
|
||||
|
@ -61,12 +65,13 @@ public class SelectionParser extends ContextualParser {
|
|||
ourContext = getCompletionContext();
|
||||
if( ourKind == null )
|
||||
ourKind = getCompletionKind();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param scanner
|
||||
* @param callback
|
||||
|
@ -102,9 +107,48 @@ public class SelectionParser extends ContextualParser {
|
|||
if( ! duple.syntaxOfName() )
|
||||
throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME );
|
||||
|
||||
return duple.lookup( astFactory, ourScope );
|
||||
return provideSelectionNode(duple);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param duple
|
||||
* @return
|
||||
*/
|
||||
protected IASTNode provideSelectionNode(ITokenDuple duple) {
|
||||
|
||||
ITokenDuple finalDuple = null;
|
||||
// reconcile the name to look up first
|
||||
if( ! duple.equals( greaterContextDuple ))
|
||||
{
|
||||
// 3 cases
|
||||
|
||||
// duple is prefix of greaterContextDuple
|
||||
if( duple.getFirstToken().equals( greaterContextDuple.getFirstToken() ))
|
||||
{
|
||||
// => do not use greaterContextDuple
|
||||
finalDuple = duple;
|
||||
}
|
||||
// duple is suffix of greaterContextDuple
|
||||
else if( duple.getLastToken().equals( greaterContextDuple.getLastToken() ))
|
||||
{
|
||||
// => use greaterContextDuple
|
||||
finalDuple = greaterContextDuple;
|
||||
}
|
||||
// duple is a sub-duple of greaterContextDuple
|
||||
else
|
||||
{
|
||||
// => throw ParseError
|
||||
throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME );
|
||||
}
|
||||
}
|
||||
else
|
||||
finalDuple = greaterContextDuple;
|
||||
return finalDuple.lookup( astFactory, ourScope );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int)
|
||||
*/
|
||||
|
@ -119,4 +163,29 @@ public class SelectionParser extends ContextualParser {
|
|||
protected void checkEndOfFile() throws EndOfFileException {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setGreaterNameContext(org.eclipse.cdt.core.parser.ITokenDuple)
|
||||
*/
|
||||
protected void setGreaterNameContext(ITokenDuple tokenDuple) {
|
||||
|
||||
if( pastPointOfSelection ) return;
|
||||
if( greaterContextDuple == null && scanner.isOnTopContext() && lastTokenOfDuple != null && firstTokenOfDuple != null )
|
||||
{
|
||||
if( tokenDuple.getStartOffset() > lastTokenOfDuple.getEndOffset() )
|
||||
{
|
||||
pastPointOfSelection = true;
|
||||
return;
|
||||
}
|
||||
int tokensFound = 0;
|
||||
Iterator i = tokenDuple.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
IToken token = (IToken) i.next();
|
||||
if( token == firstTokenOfDuple ) ++tokensFound;
|
||||
if( token == lastTokenOfDuple ) ++tokensFound;
|
||||
}
|
||||
if( tokensFound == 2 )
|
||||
greaterContextDuple = tokenDuple;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -425,4 +425,16 @@ public class TokenDuple implements ITokenDuple {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object other) {
|
||||
if( !(other instanceof ITokenDuple ) ) return false;
|
||||
if( ((ITokenDuple) other).getFirstToken().equals( getFirstToken() ) &&
|
||||
((ITokenDuple) other).getLastToken().equals( getLastToken() ) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue