1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00
This commit is contained in:
John Camelon 2004-05-04 15:08:04 +00:00
parent f971a5046c
commit bf6652a96a
7 changed files with 100 additions and 8 deletions

View file

@ -931,4 +931,55 @@ public class CompletionParseTest extends CompletionParseBaseTest {
node.getCompletionContext() );
assertEquals( result.getResultsSize(), 1 );
}
public void testParameterListFunctionReference() throws Exception
{
Writer writer = new StringWriter();
writer.write( "int foo( int firstParam, int secondParam );\n"); //$NON-NLS-1$
writer.write( "void main() { \n"); //$NON-NLS-1$
writer.write( " int abc;\n"); //$NON-NLS-1$
writer.write( " int x;\n" ); //$NON-NLS-1$
writer.write( " foo( x,a"); //$NON-NLS-1$
String code = writer.toString();
for( int i = 0; i < 2; ++i )
{
int index = code.indexOf( "x,a") + 2; //$NON-NLS-1$
if( i == 1 ) index++;
IASTCompletionNode node = parse( code, index );
validateCompletionNode(node, (( i == 0 ) ? "" : "a" ), CompletionKind.FUNCTION_REFERENCE, null, true ); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull( node.getFunctionParameters() );
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES },
node.getCompletionContext() );
assertNotNull(result);
assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 );
}
}
public void testParameterListConstructorReference() throws Exception
{
Writer writer = new StringWriter();
writer.write( "class A { \n"); //$NON-NLS-1$
writer.write( "public:\n"); //$NON-NLS-1$
writer.write( " A( int first, int second );\n"); //$NON-NLS-1$
writer.write( "};\n" ); //$NON-NLS-1$
writer.write( "void main() { \n"); //$NON-NLS-1$
writer.write( " int four, x;"); //$NON-NLS-1$
writer.write( " A * a = new A( x,f "); //$NON-NLS-1$
String code = writer.toString();
for( int i = 0; i < 2; ++i )
{
int index = code.indexOf( "x,f") + 2; //$NON-NLS-1$
if( i == 1 ) index++;
IASTCompletionNode node = parse( code, index );
validateCompletionNode(node, (( i == 0 ) ? "" : "f" ), CompletionKind.CONSTRUCTOR_REFERENCE, null, true ); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull( node.getFunctionParameters() );
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES },
node.getCompletionContext() );
assertNotNull(result);
assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 );
}
}
}

View file

@ -114,7 +114,14 @@ public interface IASTCompletionNode {
* CONSTRUCTOR_REFERENCE
* FUNCTION_REFERENCE
*/
public String getFunctionName();
public String getFunctionName();
/**
*
* @return the IASTExpression representing the number of parameters
* input in the CONSTRUCTOR_REFERENCE/FUNCTION_REFERENCE context.
*/
public IASTExpression getFunctionParameters();
/**
* @return the prefix

View file

@ -56,7 +56,7 @@ public class CompletionParser extends ContextualParser implements IParser {
public IASTCompletionNode parse(int offset) {
scanner.setOffsetBoundary(offset);
translationUnit();
return new ASTCompletionNode( getCompletionKind(), getCompletionScope(), getCompletionContext(), getCompletionPrefix(), reconcileKeywords( getKeywordSet(), getCompletionPrefix() ), getCompletionFunctionName() );
return new ASTCompletionNode( getCompletionKind(), getCompletionScope(), getCompletionContext(), getCompletionPrefix(), reconcileKeywords( getKeywordSet(), getCompletionPrefix() ), getCompletionFunctionName(), getParameterListExpression() );
}
/**

View file

@ -118,6 +118,8 @@ public class ContextualParser extends CompleteParser {
protected void setCompletionFunctionName() {
functionOrConstructorName = currentFunctionName;
}
protected void setCompletionKeywords(KeywordSets.Key key) {
this.keywordSet = KeywordSets.getKeywords( key, language );
@ -162,6 +164,7 @@ public class ContextualParser extends CompleteParser {
}
private String currentFunctionName = EMPTY_STRING;
protected IASTExpression parameterListExpression;
@ -254,4 +257,18 @@ public class ContextualParser extends CompleteParser {
setCompletionKind(kind);
checkEndOfFile();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setParameterListExpression(org.eclipse.cdt.core.parser.ast.IASTExpression)
*/
protected void setParameterListExpression(
IASTExpression assignmentExpression) {
parameterListExpression = assignmentExpression;
}
/**
* @return Returns the parameterListExpression.
*/
public final IASTExpression getParameterListExpression() {
return parameterListExpression;
}
}

View file

@ -740,8 +740,10 @@ public class ExpressionParser implements IExpressionParser, IParserData {
IASTExpression assignmentExpression = assignmentExpression(scope,kind,key);
while (LT(1) == IToken.tCOMMA)
{
consume();
consume(IToken.tCOMMA);
setParameterListExpression( assignmentExpression );
IASTExpression secondExpression = assignmentExpression(scope,kind,key);
setParameterListExpression( null );
try
{
assignmentExpression =
@ -766,6 +768,11 @@ public class ExpressionParser implements IExpressionParser, IParserData {
return assignmentExpression;
}
/**
* @param assignmentExpression
*/
protected void setParameterListExpression(IASTExpression assignmentExpression) {
}
/**
* @param expression
* @throws BacktrackException

View file

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.Set;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope;
@ -28,8 +29,9 @@ public class ASTCompletionNode implements IASTCompletionNode {
private final CompletionKind kind;
private final Set keywordSet;
private final String functionName;
private final IASTExpression parameterListExpression;
public ASTCompletionNode( CompletionKind kind, IASTScope scope, IASTNode context, String prefix, Set keywords, String functionName )
public ASTCompletionNode( CompletionKind kind, IASTScope scope, IASTNode context, String prefix, Set keywords, String functionName, IASTExpression expression )
{
this.kind = kind;
this.context = context;
@ -37,6 +39,7 @@ public class ASTCompletionNode implements IASTCompletionNode {
this.prefix = prefix;
this.keywordSet = keywords;
this.functionName = functionName;
this.parameterListExpression = expression;
}
/* (non-Javadoc)
@ -89,4 +92,11 @@ public class ASTCompletionNode implements IASTCompletionNode {
return functionName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getFunctionParameters()
*/
public IASTExpression getFunctionParameters() {
return parameterListExpression;
}
}

View file

@ -2005,7 +2005,7 @@ public class Scanner implements IScanner {
*/
protected void handleCompletionOnDefinition(String definition) throws EndOfFileException {
IASTCompletionNode node = new ASTCompletionNode( IASTCompletionNode.CompletionKind.MACRO_REFERENCE,
null, null, definition, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()), EMPTY_STRING );
null, null, definition, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()), EMPTY_STRING, null );
throwEOF( node );
}
@ -2064,19 +2064,19 @@ public class Scanner implements IScanner {
IASTCompletionNode node = new ASTCompletionNode( kind,
null, null, prefix,
KeywordSets.getKeywords(((kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND )? KeywordSets.Key.EMPTY : KeywordSets.Key.MACRO), scannerData.getLanguage()), EMPTY_STRING );
KeywordSets.getKeywords(((kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND )? KeywordSets.Key.EMPTY : KeywordSets.Key.MACRO), scannerData.getLanguage()), EMPTY_STRING, null );
throwEOF( node );
}
protected void handleInvalidCompletion() throws EndOfFileException
{
throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, EMPTY_STRING, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()) , EMPTY_STRING));
throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, EMPTY_STRING, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()) , EMPTY_STRING, null));
}
protected void handleCompletionOnPreprocessorDirective( String prefix ) throws EndOfFileException
{
throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.NO_SUCH_KIND, null, null, prefix, KeywordSets.getKeywords(KeywordSets.Key.PP_DIRECTIVE, scannerData.getLanguage() ), EMPTY_STRING));
throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.NO_SUCH_KIND, null, null, prefix, KeywordSets.getKeywords(KeywordSets.Key.PP_DIRECTIVE, scannerData.getLanguage() ), EMPTY_STRING, null));
}
/**
* @param key