1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

org.eclipse.cdt.core

Fixed  50642 - Wrong completion kind when declaring an argument type
	Updated using declarations for more accurate keywords and closure.

org.eclipse.cdt.ui.tests
	Updated CompletionTest_ArgumentType_Prefix_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix and moved to passed test package.
	Updated CompletionTest_ArgumentType_Prefix2_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix2 and moved to passed test package.
	Updated CompletionTest_ArgumentType_NoPrefix_Bug50642, renamed it to CompletionTest_ArgumentType_NoPrefix and moved to passed test package.
	Updated CompletionTest_ArgumentType_NoPrefix2_Bug50642, renamed it to CompletionTest_ArgumentType_NoPrefix2 and moved to passed test package.
This commit is contained in:
John Camelon 2004-01-29 16:59:54 +00:00
parent 752890b1aa
commit d46025b64f
9 changed files with 211 additions and 161 deletions

View file

@ -1,3 +1,7 @@
2004-01-29 John Camelon
Fixed 50642 - Wrong completion kind when declaring an argument type
Updated using declarations for more accurate keywords and closure.
2004-01-29 Hoda Amer
Put CompletionKind.FUNCTION_REFERENCE back.

View file

@ -301,13 +301,16 @@ public abstract class Parser implements IParser
else
{
boolean typeName = false;
setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, Key.POST_USING );
if (LT(1) == IToken.t_typename)
{
typeName = true;
consume(IToken.t_typename);
}
setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, Key.EMPTY );
setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, Key.NAMESPACE_ONLY );
TokenDuple name = null;
if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON)
{
@ -337,6 +340,7 @@ public abstract class Parser implements IParser
throw backtrack;
}
declaration.acceptElement( requestor );
setCompletionValues(scope, getCompletionKindForDeclaration(scope, null), Key.DECLARATION );
}
else
{
@ -1206,6 +1210,7 @@ public abstract class Parser implements IParser
throw backtrack;
}
setCompletionValues(scope,CompletionKind.USER_SPECIFIED_NAME,Key.EMPTY );
if (LT(1) != IToken.tSEMI)
initDeclarator(sdw, SimpleDeclarationStrategy.TRY_FUNCTION );
@ -2188,11 +2193,11 @@ public abstract class Parser implements IParser
{
case IToken.tLPAREN :
boolean failed = false;
// temporary fix for initializer/function declaration ambiguity
if (!LA(2).looksLikeExpression() && strategy != SimpleDeclarationStrategy.TRY_VARIABLE )
if ( queryLookaheadCapability(2) && !LA(2).looksLikeExpression() && strategy != SimpleDeclarationStrategy.TRY_VARIABLE )
{
boolean failed = false;
if( LT(2) == IToken.tIDENTIFIER )
if( LT(2) == IToken.tIDENTIFIER )
{
IToken newMark = mark();
consume( IToken.tLPAREN );
@ -2215,138 +2220,141 @@ public abstract class Parser implements IParser
backup( newMark );
}
if( !failed )
{
// parameterDeclarationClause
d.setIsFunction(true);
// TODO need to create a temporary scope object here
consume(IToken.tLPAREN);
boolean seenParameter = false;
parameterDeclarationLoop : for (;;)
{
switch (LT(1))
{
case IToken.tRPAREN :
consume();
break parameterDeclarationLoop;
case IToken.tELLIPSIS :
consume();
d.setIsVarArgs( true );
break;
case IToken.tCOMMA :
consume();
seenParameter = false;
break;
default :
if (seenParameter)
throw backtrack;
parameterDeclaration(d, scope);
seenParameter = true;
}
}
}
if (LT(1) == IToken.tCOLON || LT(1) == IToken.t_try )
break overallLoop;
IToken beforeCVModifier = mark();
IToken cvModifier = null;
IToken afterCVModifier = beforeCVModifier;
// const-volatile
// 2 options: either this is a marker for the method,
// or it might be the beginning of old K&R style parameter declaration, see
// void getenv(name) const char * name; {}
// This will be determined further below
if (LT(1) == IToken.t_const
|| LT(1) == IToken.t_volatile)
}
if( ( queryLookaheadCapability(2) && !LA(2).looksLikeExpression() && strategy != SimpleDeclarationStrategy.TRY_VARIABLE && !failed) || ! queryLookaheadCapability(3) )
{
// parameterDeclarationClause
d.setIsFunction(true);
// TODO need to create a temporary scope object here
consume(IToken.tLPAREN);
setCompletionValues( scope, CompletionKind.ARGUMENT_TYPE, Key.DECL_SPECIFIER_SEQUENCE );
boolean seenParameter = false;
parameterDeclarationLoop : for (;;)
{
cvModifier = consume();
afterCVModifier = mark();
}
//check for throws clause here
List exceptionSpecIds = null;
if (LT(1) == IToken.t_throw)
{
exceptionSpecIds = new ArrayList();
consume(); // throw
consume(IToken.tLPAREN); // (
boolean done = false;
IASTTypeId duple = null;
while (!done)
switch (LT(1))
{
switch (LT(1))
{
case IToken.tRPAREN :
consume();
done = true;
break;
case IToken.tCOMMA :
consume();
break;
default :
String image = LA(1).getImage();
try
{
duple = typeId(scope, false);
exceptionSpecIds.add(duple);
}
catch (BacktrackException e)
{
failParse();
log.traceLog(
"Unexpected Token ="
+ image );
consume();
// eat this token anyway
continue;
}
break;
}
case IToken.tRPAREN :
consume();
setCompletionValues( scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.FUNCTION_MODIFIER );
break parameterDeclarationLoop;
case IToken.tELLIPSIS :
consume();
d.setIsVarArgs( true );
break;
case IToken.tCOMMA :
consume();
setCompletionValues( scope, CompletionKind.ARGUMENT_TYPE, Key.DECL_SPECIFIER_SEQUENCE );
seenParameter = false;
break;
default :
if (seenParameter)
throw backtrack;
parameterDeclaration(d, scope);
seenParameter = true;
}
if (exceptionSpecIds != null)
try
{
d.setExceptionSpecification(
astFactory
.createExceptionSpecification(
d.getDeclarationWrapper().getScope(), exceptionSpecIds));
}
catch (ASTSemanticException e)
{
failParse();
throw backtrack;
} catch (Exception e)
{
throw backtrack;
}
}
// check for optional pure virtual
if (LT(1) == IToken.tASSIGN
&& LT(2) == IToken.tINTEGER
&& LA(2).getImage().equals("0"))
{
consume(IToken.tASSIGN);
consume(IToken.tINTEGER);
d.setPureVirtual(true);
}
if (afterCVModifier != LA(1)
|| LT(1) == IToken.tSEMI)
{
// There were C++-specific clauses after const/volatile modifier
// Then it is a marker for the method
if (cvModifier != null)
{
}
if (cvModifier.getType() == IToken.t_const)
d.setConst(true);
if (cvModifier.getType()
== IToken.t_volatile)
d.setVolatile(true);
if (LT(1) == IToken.tCOLON || LT(1) == IToken.t_try )
break overallLoop;
IToken beforeCVModifier = mark();
IToken cvModifier = null;
IToken afterCVModifier = beforeCVModifier;
// const-volatile
// 2 options: either this is a marker for the method,
// or it might be the beginning of old K&R style parameter declaration, see
// void getenv(name) const char * name; {}
// This will be determined further below
if (LT(1) == IToken.t_const
|| LT(1) == IToken.t_volatile)
{
cvModifier = consume();
afterCVModifier = mark();
}
//check for throws clause here
List exceptionSpecIds = null;
if (LT(1) == IToken.t_throw)
{
exceptionSpecIds = new ArrayList();
consume(); // throw
consume(IToken.tLPAREN); // (
boolean done = false;
IASTTypeId duple = null;
while (!done)
{
switch (LT(1))
{
case IToken.tRPAREN :
consume();
done = true;
break;
case IToken.tCOMMA :
consume();
break;
default :
String image = LA(1).getImage();
try
{
duple = typeId(scope, false);
exceptionSpecIds.add(duple);
}
catch (BacktrackException e)
{
failParse();
log.traceLog(
"Unexpected Token ="
+ image );
consume();
// eat this token anyway
continue;
}
break;
}
afterCVModifier = mark();
// In this case (method) we can't expect K&R parameter declarations,
// but we'll check anyway, for errorhandling
}
if (exceptionSpecIds != null)
try
{
d.setExceptionSpecification(
astFactory
.createExceptionSpecification(
d.getDeclarationWrapper().getScope(), exceptionSpecIds));
}
catch (ASTSemanticException e)
{
failParse();
throw backtrack;
} catch (Exception e)
{
throw backtrack;
}
}
// check for optional pure virtual
if (LT(1) == IToken.tASSIGN
&& LT(2) == IToken.tINTEGER
&& LA(2).getImage().equals("0"))
{
consume(IToken.tASSIGN);
consume(IToken.tINTEGER);
d.setPureVirtual(true);
}
if (afterCVModifier != LA(1)
|| LT(1) == IToken.tSEMI)
{
// There were C++-specific clauses after const/volatile modifier
// Then it is a marker for the method
if (cvModifier != null)
{
if (cvModifier.getType() == IToken.t_const)
d.setConst(true);
if (cvModifier.getType()
== IToken.t_volatile)
d.setVolatile(true);
}
afterCVModifier = mark();
// In this case (method) we can't expect K&R parameter declarations,
// but we'll check anyway, for errorhandling
}
break;
case IToken.tLBRACKET :

View file

@ -33,6 +33,8 @@ public class KeywordSets {
public static final Key STATEMENT = new Key(3);
public static final Key BASE_SPECIFIER = new Key(4);
public static final Key POST_USING = new Key( 5 );
public static final Key FUNCTION_MODIFIER = new Key( 6 );
public static final Key NAMESPACE_ONLY = new Key(6);
/**
* @param enumValue
*/
@ -56,6 +58,10 @@ public class KeywordSets {
return BASE_SPECIFIER_CPP;
if( kind == Key.POST_USING )
return POST_USING_CPP;
if( kind == Key.FUNCTION_MODIFIER )
return (Set) FUNCTION_MODIFIER.get( language );
if( kind == Key.NAMESPACE_ONLY )
return NAMESPACE_ONLY;
//TODO finish this
return null;
@ -63,6 +69,13 @@ public class KeywordSets {
private static final Set EMPTY = new HashSet();
private static final Set NAMESPACE_ONLY;
static
{
NAMESPACE_ONLY = new HashSet();
NAMESPACE_ONLY.add(Keywords.NAMESPACE );
}
private static final Set DECL_SPECIFIER_SEQUENCE_C;
static
{
@ -189,4 +202,27 @@ public class KeywordSets {
POST_USING_CPP.add(Keywords.NAMESPACE);
POST_USING_CPP.add(Keywords.TYPENAME);
}
private static final Set FUNCTION_MODIFIER_C;
static
{
FUNCTION_MODIFIER_C = new TreeSet();
}
private static final Set FUNCTION_MODIFIER_CPP;
static
{
FUNCTION_MODIFIER_CPP = new TreeSet( FUNCTION_MODIFIER_C );
FUNCTION_MODIFIER_CPP.add( Keywords.CONST );
FUNCTION_MODIFIER_CPP.add( Keywords.THROW);
FUNCTION_MODIFIER_CPP.add( Keywords.TRY );
FUNCTION_MODIFIER_CPP.add( Keywords.VOLATILE );
}
private static final Hashtable FUNCTION_MODIFIER;
static
{
FUNCTION_MODIFIER= new Hashtable();
FUNCTION_MODIFIER.put( ParserLanguage.CPP, FUNCTION_MODIFIER_CPP );
FUNCTION_MODIFIER.put( ParserLanguage.C, FUNCTION_MODIFIER_C );
}
}

View file

@ -1,3 +1,9 @@
2004-01-29 John Camelon
Updated CompletionTest_ArgumentType_Prefix_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix and moved to passed test package.
Updated CompletionTest_ArgumentType_Prefix2_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix2 and moved to passed test package.
Updated CompletionTest_ArgumentType_NoPrefix_Bug50642, renamed it to CompletionTest_ArgumentType_NoPrefix and moved to passed test package.
Updated CompletionTest_ArgumentType_NoPrefix2_Bug50642, renamed it to CompletionTest_ArgumentType_NoPrefix2 and moved to passed test package.
2004-01-29 Hoda Amer
Added two more tests, namely Function_Reference and Constructor_Reference.
Moved tests starts resources all to one directory.

View file

@ -42,10 +42,10 @@ public class AutomatedSuite extends TestSuite {
addTest(CompletionTest_FieldType_NoPrefix2.suite());
addTest(CompletionTest_VariableType_Prefix.suite());
addTest(CompletionTest_VariableType_NoPrefix.suite());
addTest(CompletionTest_ArgumentType_NoPrefix_Bug50642.suite());
addTest(CompletionTest_ArgumentType_NoPrefix2_Bug50642.suite());
addTest(CompletionTest_ArgumentType_Prefix_Bug50642.suite());
addTest(CompletionTest_ArgumentType_NoPrefix2_Bug50642.suite());
addTest(CompletionTest_ArgumentType_NoPrefix.suite());
addTest(CompletionTest_ArgumentType_NoPrefix2.suite());
addTest(CompletionTest_ArgumentType_Prefix.suite());
addTest(CompletionTest_ArgumentType_NoPrefix2.suite());
addTest(CompletionTest_SingleName_Method_Prefix.suite());
addTest(CompletionTest_SingleName_Method_NoPrefix.suite());
addTest(CompletionTest_SingleName_Prefix.suite());

View file

@ -8,14 +8,13 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist.failedtests;
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/**
* @author hamer
@ -24,25 +23,25 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
* Bug#50642 : Wrong completion kind when declaring an argument type
*
*/
public class CompletionTest_ArgumentType_NoPrefix_Bug50642 extends CompletionProposalsBaseTest{
public class CompletionTest_ArgumentType_NoPrefix extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart17.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTCompilationUnit";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE; // should be CompletionKind.ARGUMENT_TYPE;
private final CompletionKind expectedKind = CompletionKind.ARGUMENT_TYPE;
private final String expectedPrefix = "";
private final String[] expectedResults = {
};
public CompletionTest_ArgumentType_NoPrefix_Bug50642(String name) {
public CompletionTest_ArgumentType_NoPrefix(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_NoPrefix_Bug50642.class.getName());
suite.addTest(new CompletionTest_ArgumentType_NoPrefix_Bug50642("testCompletionProposals"));
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_NoPrefix.class.getName());
suite.addTest(new CompletionTest_ArgumentType_NoPrefix("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)

View file

@ -8,13 +8,12 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist.failedtests;
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/**
* @author hamer
@ -23,25 +22,25 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
* Bug#50642 : Wrong completion kind when declaring an argument type
*
*/
public class CompletionTest_ArgumentType_NoPrefix2_Bug50642 extends CompletionProposalsBaseTest{
public class CompletionTest_ArgumentType_NoPrefix2 extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart19.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTClassSpecifier";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.FIELD_TYPE; // should be CompletionKind.ARGUMENT_TYPE;
private final CompletionKind expectedKind = CompletionKind.ARGUMENT_TYPE;
private final String expectedPrefix = "";
private final String[] expectedResults = {
};
public CompletionTest_ArgumentType_NoPrefix2_Bug50642(String name) {
public CompletionTest_ArgumentType_NoPrefix2(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_NoPrefix2_Bug50642.class.getName());
suite.addTest(new CompletionTest_ArgumentType_NoPrefix2_Bug50642("testCompletionProposals"));
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_NoPrefix2.class.getName());
suite.addTest(new CompletionTest_ArgumentType_NoPrefix2("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)

View file

@ -8,13 +8,12 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist.failedtests;
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/**
* @author hamer
@ -23,14 +22,14 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
* Bug#50642 : Wrong completion kind when declaring an argument type
*
*/
public class CompletionTest_ArgumentType_Prefix_Bug50642 extends CompletionProposalsBaseTest{
public class CompletionTest_ArgumentType_Prefix extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart16.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTCompilationUnit";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE; // should be CompletionKind.ARGUMENT_TYPE;
private final CompletionKind expectedKind = CompletionKind.ARGUMENT_TYPE;
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aClass",
@ -40,13 +39,13 @@ public class CompletionTest_ArgumentType_Prefix_Bug50642 extends CompletionProp
"AStruct"
};
public CompletionTest_ArgumentType_Prefix_Bug50642(String name) {
public CompletionTest_ArgumentType_Prefix(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_Prefix_Bug50642.class.getName());
suite.addTest(new CompletionTest_ArgumentType_Prefix_Bug50642("testCompletionProposals"));
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_Prefix.class.getName());
suite.addTest(new CompletionTest_ArgumentType_Prefix("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)

View file

@ -8,13 +8,12 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist.failedtests;
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/**
* @author hamer
@ -23,14 +22,14 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
* Bug#50642 : Wrong completion kind when declaring an argument type
*
*/
public class CompletionTest_ArgumentType_Prefix2_Bug50642 extends CompletionProposalsBaseTest{
public class CompletionTest_ArgumentType_Prefix2 extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart18.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTClassSpecifier";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.FIELD_TYPE; // should be CompletionKind.ARGUMENT_TYPE;
private final CompletionKind expectedKind = CompletionKind.ARGUMENT_TYPE;
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aClass",
@ -40,13 +39,13 @@ public class CompletionTest_ArgumentType_Prefix2_Bug50642 extends CompletionPro
"AStruct"
};
public CompletionTest_ArgumentType_Prefix2_Bug50642(String name) {
public CompletionTest_ArgumentType_Prefix2(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_Prefix2_Bug50642.class.getName());
suite.addTest(new CompletionTest_ArgumentType_Prefix2_Bug50642("testCompletionProposals"));
TestSuite suite= new TestSuite(CompletionTest_ArgumentType_Prefix2.class.getName());
suite.addTest(new CompletionTest_ArgumentType_Prefix2("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)