1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00
John Camelon 2004-05-15 15:13:10 +00:00
parent c9e829ba12
commit 06d6b593af
3 changed files with 50 additions and 33 deletions

View file

@ -984,42 +984,42 @@ public class CompletionParseTest extends CompletionParseBaseTest {
public void testConstructors() throws Exception public void testConstructors() throws Exception
{ {
String code = "class Foo{ public: Foo(); }; Foo::SP "; String code = "class Foo{ public: Foo(); }; Foo::SP "; //$NON-NLS-1$
IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.CONSTRUCTORS }, new IASTNode.LookupKind[]{ IASTNode.LookupKind.CONSTRUCTORS },
node.getCompletionContext(), null ); node.getCompletionContext(), null );
assertEquals( result.getResultsSize(), 1 ); assertEquals( result.getResultsSize(), 1 );
IASTMethod constructor = (IASTMethod) result.getNodes().next(); IASTMethod constructor = (IASTMethod) result.getNodes().next();
assertEquals( constructor.getName(), "Foo" ); assertEquals( constructor.getName(), "Foo" ); //$NON-NLS-1$
} }
public void testBug50807() throws Exception public void testBug50807() throws Exception
{ {
Writer writer = new StringWriter(); Writer writer = new StringWriter();
writer.write( "void foo();" ); writer.write( "void foo();" ); //$NON-NLS-1$
writer.write( "void foo( int );" ); writer.write( "void foo( int );" ); //$NON-NLS-1$
writer.write( "void foo( int, char );" ); writer.write( "void foo( int, char );" ); //$NON-NLS-1$
writer.write( "void foo( int, int, int );" ); writer.write( "void foo( int, int, int );" ); //$NON-NLS-1$
writer.write( "void bar(){ " ); writer.write( "void bar(){ " ); //$NON-NLS-1$
String code = writer.toString() + "foo( SP"; String code = writer.toString() + "foo( SP"; //$NON-NLS-1$
IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$
assertEquals( node.getCompletionPrefix(), "" ); assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$
assertEquals( node.getFunctionName(), "foo" ); assertEquals( node.getFunctionName(), "foo" ); //$NON-NLS-1$
ILookupResult result = node.getCompletionScope().lookup( node.getFunctionName(), ILookupResult result = node.getCompletionScope().lookup( node.getFunctionName(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS }, new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS },
node.getCompletionContext(), null ); node.getCompletionContext(), null );
assertEquals( result.getResultsSize(), 4 ); assertEquals( result.getResultsSize(), 4 );
code = writer.toString() + "foo( 1, SP"; code = writer.toString() + "foo( 1, SP"; //$NON-NLS-1$
node = parse( code, code.indexOf( "SP" ) ); node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$
assertEquals( node.getCompletionPrefix(), "" ); assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$
assertEquals( node.getFunctionName(), "foo" ); assertEquals( node.getFunctionName(), "foo" ); //$NON-NLS-1$
result = node.getCompletionScope().lookup( node.getFunctionName(), result = node.getCompletionScope().lookup( node.getFunctionName(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS }, new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS },
node.getCompletionContext(), node.getFunctionParameters() ); node.getCompletionContext(), node.getFunctionParameters() );
@ -1030,10 +1030,10 @@ public class CompletionParseTest extends CompletionParseBaseTest {
public void testBug60298() throws Exception public void testBug60298() throws Exception
{ {
Writer writer = new StringWriter(); Writer writer = new StringWriter();
writer.write( "class ABC { public: ABC(); int myInt(); };\n"); writer.write( "class ABC { public: ABC(); int myInt(); };\n"); //$NON-NLS-1$
writer.write( "int ABC::" ); writer.write( "int ABC::" ); //$NON-NLS-1$
String code = writer.toString(); String code = writer.toString();
IASTCompletionNode node = parse( code, code.indexOf( "::") + 2 ); IASTCompletionNode node = parse( code, code.indexOf( "::") + 2 ); //$NON-NLS-1$
assertEquals( node.getCompletionKind(), CompletionKind.SINGLE_NAME_REFERENCE ); assertEquals( node.getCompletionKind(), CompletionKind.SINGLE_NAME_REFERENCE );
} }
@ -1041,12 +1041,29 @@ public class CompletionParseTest extends CompletionParseBaseTest {
public void testBug62344() throws Exception public void testBug62344() throws Exception
{ {
Writer writer = new StringWriter(); Writer writer = new StringWriter();
writer.write( " namespace Foo{ class bar{}; } "); writer.write( " namespace Foo{ class bar{}; } "); //$NON-NLS-1$
writer.write( " void main() { "); writer.write( " void main() { "); //$NON-NLS-1$
writer.write( " Foo::bar * foobar = new Foo::SP "); writer.write( " Foo::bar * foobar = new Foo::SP "); //$NON-NLS-1$
String code = writer.toString(); String code = writer.toString();
IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$
assertEquals( node.getCompletionKind(), CompletionKind.NEW_TYPE_REFERENCE ); assertEquals( node.getCompletionKind(), CompletionKind.NEW_TYPE_REFERENCE );
} }
public void testBug62339() throws Exception
{
Writer writer = new StringWriter();
writer.write( "struct Cube { int nLength; int nWidth; int nHeight; };\n" ); //$NON-NLS-1$
writer.write( "int main(int argc, char **argv) { struct Cube * pCube;\n" ); //$NON-NLS-1$
writer.write( " pCube = (str" ); //$NON-NLS-1$
String code = writer.toString();
IASTCompletionNode node = parse( code, code.indexOf( "(str") + 4 ); //$NON-NLS-1$
assertNotNull( node );
boolean foundStruct = false;
Iterator i = node.getKeywords();
while( i.hasNext() )
if( ((String) i.next()).equals( "struct")) //$NON-NLS-1$
foundStruct = true;
assertTrue( foundStruct );
}
} }

View file

@ -1461,7 +1461,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
// If this isn't a type name, then we shouldn't be here // If this isn't a type name, then we shouldn't be here
try try
{ {
typeId = typeId(scope, false, ((kind == CompletionKind.SINGLE_NAME_REFERENCE )? kind : CompletionKind.TYPE_REFERENCE)); typeId = typeId(scope, false, getCastExpressionKind(kind));
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); popped = true;} if( templateIdScopes != null ){ templateIdScopes.pop(); popped = true;}
IASTExpression castExpression = castExpression(scope,kind,key); IASTExpression castExpression = castExpression(scope,kind,key);
@ -1495,6 +1495,13 @@ public class ExpressionParser implements IExpressionParser, IParserData {
} }
/**
* @param kind
* @return
*/
private CompletionKind getCastExpressionKind(CompletionKind kind) {
return ((kind == CompletionKind.SINGLE_NAME_REFERENCE || kind == CompletionKind.FUNCTION_REFERENCE)? kind : CompletionKind.TYPE_REFERENCE);
}
/** /**
* @param completionKind TODO * @param completionKind TODO
* @throws BacktrackException * @throws BacktrackException
@ -1513,7 +1520,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
{ {
try try
{ {
name = name(scope, completionKind, Key.EMPTY ); name = name(scope, completionKind, Key.DECL_SPECIFIER_SEQUENCE );
kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
break; break;
} }

View file

@ -97,14 +97,7 @@ public class ASTTypeId implements IASTTypeId
{ {
return references; return references;
} }
public void finalize()
{
references.clear();
references = null;
tokenDuple = null;
}
public ITokenDuple getTokenDuple() public ITokenDuple getTokenDuple()
{ {
return tokenDuple; return tokenDuple;