mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 10:15:39 +02:00
Partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=50808
This commit is contained in:
parent
f971a5046c
commit
bf6652a96a
7 changed files with 100 additions and 8 deletions
|
@ -931,4 +931,55 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
||||||
node.getCompletionContext() );
|
node.getCompletionContext() );
|
||||||
assertEquals( result.getResultsSize(), 1 );
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,13 @@ public interface IASTCompletionNode {
|
||||||
*/
|
*/
|
||||||
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
|
* @return the prefix
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class CompletionParser extends ContextualParser implements IParser {
|
||||||
public IASTCompletionNode parse(int offset) {
|
public IASTCompletionNode parse(int offset) {
|
||||||
scanner.setOffsetBoundary(offset);
|
scanner.setOffsetBoundary(offset);
|
||||||
translationUnit();
|
translationUnit();
|
||||||
return new ASTCompletionNode( getCompletionKind(), getCompletionScope(), getCompletionContext(), getCompletionPrefix(), reconcileKeywords( getKeywordSet(), getCompletionPrefix() ), getCompletionFunctionName() );
|
return new ASTCompletionNode( getCompletionKind(), getCompletionScope(), getCompletionContext(), getCompletionPrefix(), reconcileKeywords( getKeywordSet(), getCompletionPrefix() ), getCompletionFunctionName(), getParameterListExpression() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -119,6 +119,8 @@ public class ContextualParser extends CompleteParser {
|
||||||
functionOrConstructorName = currentFunctionName;
|
functionOrConstructorName = currentFunctionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected void setCompletionKeywords(KeywordSets.Key key) {
|
protected void setCompletionKeywords(KeywordSets.Key key) {
|
||||||
this.keywordSet = KeywordSets.getKeywords( key, language );
|
this.keywordSet = KeywordSets.getKeywords( key, language );
|
||||||
}
|
}
|
||||||
|
@ -162,6 +164,7 @@ public class ContextualParser extends CompleteParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String currentFunctionName = EMPTY_STRING;
|
private String currentFunctionName = EMPTY_STRING;
|
||||||
|
protected IASTExpression parameterListExpression;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,4 +257,18 @@ public class ContextualParser extends CompleteParser {
|
||||||
setCompletionKind(kind);
|
setCompletionKind(kind);
|
||||||
checkEndOfFile();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -740,8 +740,10 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
IASTExpression assignmentExpression = assignmentExpression(scope,kind,key);
|
IASTExpression assignmentExpression = assignmentExpression(scope,kind,key);
|
||||||
while (LT(1) == IToken.tCOMMA)
|
while (LT(1) == IToken.tCOMMA)
|
||||||
{
|
{
|
||||||
consume();
|
consume(IToken.tCOMMA);
|
||||||
|
setParameterListExpression( assignmentExpression );
|
||||||
IASTExpression secondExpression = assignmentExpression(scope,kind,key);
|
IASTExpression secondExpression = assignmentExpression(scope,kind,key);
|
||||||
|
setParameterListExpression( null );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
assignmentExpression =
|
assignmentExpression =
|
||||||
|
@ -766,6 +768,11 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
return assignmentExpression;
|
return assignmentExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param assignmentExpression
|
||||||
|
*/
|
||||||
|
protected void setParameterListExpression(IASTExpression assignmentExpression) {
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param expression
|
* @param expression
|
||||||
* @throws BacktrackException
|
* @throws BacktrackException
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
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.IASTNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||||
|
|
||||||
|
@ -28,8 +29,9 @@ public class ASTCompletionNode implements IASTCompletionNode {
|
||||||
private final CompletionKind kind;
|
private final CompletionKind kind;
|
||||||
private final Set keywordSet;
|
private final Set keywordSet;
|
||||||
private final String functionName;
|
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.kind = kind;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -37,6 +39,7 @@ public class ASTCompletionNode implements IASTCompletionNode {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
this.keywordSet = keywords;
|
this.keywordSet = keywords;
|
||||||
this.functionName = functionName;
|
this.functionName = functionName;
|
||||||
|
this.parameterListExpression = expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -89,4 +92,11 @@ public class ASTCompletionNode implements IASTCompletionNode {
|
||||||
return functionName;
|
return functionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getFunctionParameters()
|
||||||
|
*/
|
||||||
|
public IASTExpression getFunctionParameters() {
|
||||||
|
return parameterListExpression;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2005,7 +2005,7 @@ public class Scanner implements IScanner {
|
||||||
*/
|
*/
|
||||||
protected void handleCompletionOnDefinition(String definition) throws EndOfFileException {
|
protected 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.EMPTY, scannerData.getLanguage()), EMPTY_STRING );
|
null, null, definition, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()), EMPTY_STRING, null );
|
||||||
|
|
||||||
throwEOF( node );
|
throwEOF( node );
|
||||||
}
|
}
|
||||||
|
@ -2064,19 +2064,19 @@ public class Scanner implements IScanner {
|
||||||
|
|
||||||
IASTCompletionNode node = new ASTCompletionNode( kind,
|
IASTCompletionNode node = new ASTCompletionNode( kind,
|
||||||
null, null, prefix,
|
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 );
|
throwEOF( node );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleInvalidCompletion() throws EndOfFileException
|
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
|
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
|
* @param key
|
||||||
|
|
Loading…
Add table
Reference in a new issue