mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 09:15:38 +02:00
This commit is contained in:
parent
d730ff0f94
commit
54aa75f147
4 changed files with 51 additions and 3 deletions
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.parser.ScannerInfo;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
|
@ -183,4 +184,20 @@ public class SelectionParseTest extends CompleteParseBaseTest {
|
|||
assertEquals( destructor.getName(), "~Gonzo" ); //$NON-NLS-1$
|
||||
assertTrue( destructor.isDestructor() );
|
||||
}
|
||||
|
||||
public void testBug60264() throws Exception
|
||||
{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write( "namespace Muppets { int i; }\n" ); //$NON-NLS-1$
|
||||
writer.write( "int main(int argc, char **argv) { Muppets::i = 1; }\n" ); //$NON-NLS-1$
|
||||
String code = writer.toString();
|
||||
int index = code.indexOf( "Muppets::"); //$NON-NLS-1$
|
||||
IASTNode node = parse( code, index, index + 7 );
|
||||
assertNotNull( node );
|
||||
assertTrue( node instanceof IASTNamespaceDefinition );
|
||||
IASTNamespaceDefinition namespace = (IASTNamespaceDefinition) node;
|
||||
assertEquals( namespace.getName(), "Muppets"); //$NON-NLS-1$
|
||||
assertEquals( namespace.getStartingLine(), 1 );
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,4 +53,9 @@ public interface ITokenDuple {
|
|||
public abstract boolean syntaxOfName();
|
||||
|
||||
public String extractNameFromTemplateId();
|
||||
/**
|
||||
* @param duple
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(ITokenDuple duple);
|
||||
}
|
|
@ -352,9 +352,16 @@ public class ASTExpression extends ASTNode implements IASTExpression
|
|||
{
|
||||
if( expression == null ) return false;
|
||||
if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION &&
|
||||
expression instanceof ASTExpression &&
|
||||
((ASTExpression)expression).getIdExpressionTokenDuple().equals( duple ) )
|
||||
return true;
|
||||
expression instanceof ASTExpression )
|
||||
{
|
||||
ITokenDuple expressionDuple = ((ASTExpression)expression).getIdExpressionTokenDuple();
|
||||
// check equality
|
||||
if( expressionDuple.equals( duple ) )
|
||||
return true;
|
||||
// check subduple
|
||||
if( expressionDuple.contains( duple ) )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -475,4 +475,23 @@ public class TokenDuple implements ITokenDuple {
|
|||
|
||||
return nameBuffer.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ITokenDuple#contains(org.eclipse.cdt.core.parser.ITokenDuple)
|
||||
*/
|
||||
public boolean contains(ITokenDuple duple) {
|
||||
if( duple == null ) return false;
|
||||
boolean foundFirst = false;
|
||||
boolean foundLast = false;
|
||||
Iterator i = iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
IToken current = (IToken) i.next();
|
||||
if( current == firstToken ) foundFirst = true;
|
||||
if( current == lastToken ) foundLast = true;
|
||||
if( foundFirst && foundLast ) break;
|
||||
}
|
||||
|
||||
return ( foundFirst && foundLast );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue