mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 04:45:38 +02:00
This commit is contained in:
parent
5d76260d33
commit
5bbba8f2a5
3 changed files with 90 additions and 23 deletions
|
@ -36,28 +36,7 @@ public class SelectionParseTest extends CompleteParseBaseTest {
|
||||||
|
|
||||||
protected IASTNode parse(String code, int offset1, int offset2 )
|
protected IASTNode parse(String code, int offset1, int offset2 )
|
||||||
throws Exception {
|
throws Exception {
|
||||||
callback = new FullParseCallback();
|
return parse( code, offset1, offset2, true );
|
||||||
IParser parser = null;
|
|
||||||
|
|
||||||
parser =
|
|
||||||
ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner(
|
|
||||||
new StringReader(code),
|
|
||||||
"completion-test", //$NON-NLS-1$
|
|
||||||
new ScannerInfo(),
|
|
||||||
ParserMode.SELECTION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
callback,
|
|
||||||
new NullLogService(), null),
|
|
||||||
callback,
|
|
||||||
ParserMode.SELECTION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
ParserUtil.getParserLogService());
|
|
||||||
|
|
||||||
IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
|
|
||||||
if( result == null ) return null;
|
|
||||||
return (IASTNode) result.getOffsetableNamedElement();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,9 +65,47 @@ public class SelectionParseTest extends CompleteParseBaseTest {
|
||||||
String code = "int x() { y( ) }"; //$NON-NLS-1$
|
String code = "int x() { y( ) }"; //$NON-NLS-1$
|
||||||
int offset1 = code.indexOf( "y( " ); //$NON-NLS-1$
|
int offset1 = code.indexOf( "y( " ); //$NON-NLS-1$
|
||||||
int offset2 = code.indexOf( "( )"); //$NON-NLS-1$
|
int offset2 = code.indexOf( "( )"); //$NON-NLS-1$
|
||||||
assertNull( parse( code, offset1, offset2 ));
|
assertNull( parse( code, offset1, offset2, false ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param code
|
||||||
|
* @param offset1
|
||||||
|
* @param offset2
|
||||||
|
* @param b
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected IASTNode parse(String code, int offset1, int offset2, boolean expectedToPass ) throws Exception {
|
||||||
|
callback = new FullParseCallback();
|
||||||
|
IParser parser = null;
|
||||||
|
|
||||||
|
parser =
|
||||||
|
ParserFactory.createParser(
|
||||||
|
ParserFactory.createScanner(
|
||||||
|
new StringReader(code),
|
||||||
|
"completion-test", //$NON-NLS-1$
|
||||||
|
new ScannerInfo(),
|
||||||
|
ParserMode.SELECTION_PARSE,
|
||||||
|
ParserLanguage.CPP,
|
||||||
|
callback,
|
||||||
|
new NullLogService(), null),
|
||||||
|
callback,
|
||||||
|
ParserMode.SELECTION_PARSE,
|
||||||
|
ParserLanguage.CPP,
|
||||||
|
ParserUtil.getParserLogService());
|
||||||
|
|
||||||
|
IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
|
||||||
|
if( expectedToPass )
|
||||||
|
{
|
||||||
|
assertNotNull( result );
|
||||||
|
String filename = result.getFilename();
|
||||||
|
assertTrue( !filename.equals( "")); //$NON-NLS-1$
|
||||||
|
return (IASTNode) result.getOffsetableNamedElement();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testBaseCase_FunctionDeclaration() throws Exception
|
public void testBaseCase_FunctionDeclaration() throws Exception
|
||||||
{
|
{
|
||||||
String code = "int x(); x( );"; //$NON-NLS-1$
|
String code = "int x(); x( );"; //$NON-NLS-1$
|
||||||
|
@ -200,4 +217,25 @@ public class SelectionParseTest extends CompleteParseBaseTest {
|
||||||
assertEquals( namespace.getStartingLine(), 1 );
|
assertEquals( namespace.getStartingLine(), 1 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug61613() throws Exception
|
||||||
|
{
|
||||||
|
Writer writer = new StringWriter();
|
||||||
|
writer.write( "class Foo { // ** (A) **\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( " public:\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "Foo() {};\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "};\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "int \n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "main(int argc, char **argv) {\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "Foo foo; // ** (B) **\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "}\n" ); //$NON-NLS-1$
|
||||||
|
String code = writer.toString();
|
||||||
|
int index = code.indexOf( "class Foo") + 6; //$NON-NLS-1$
|
||||||
|
IASTNode node = parse( code, index, index + 3 );
|
||||||
|
assertTrue( node instanceof IASTClassSpecifier );
|
||||||
|
IASTClassSpecifier foo = (IASTClassSpecifier) node;
|
||||||
|
assertEquals( foo.getName(), "Foo"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1109,6 +1109,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IASTDeclaration declaration = (IASTDeclaration)i.next();
|
IASTDeclaration declaration = (IASTDeclaration)i.next();
|
||||||
|
endDeclaration( declaration );
|
||||||
declaration.enterScope( requestor );
|
declaration.enterScope( requestor );
|
||||||
|
|
||||||
if ( !( declaration instanceof IASTScope ) )
|
if ( !( declaration instanceof IASTScope ) )
|
||||||
|
@ -2628,6 +2629,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
consume(IToken.tLBRACE);
|
consume(IToken.tLBRACE);
|
||||||
setCompletionValues(astClassSpecifier, CompletionKind.FIELD_TYPE, Key.DECLARATION );
|
setCompletionValues(astClassSpecifier, CompletionKind.FIELD_TYPE, Key.DECLARATION );
|
||||||
astClassSpecifier.enterScope( requestor );
|
astClassSpecifier.enterScope( requestor );
|
||||||
|
handleClassSpecifier( astClassSpecifier );
|
||||||
memberDeclarationLoop : while (LT(1) != IToken.tRBRACE)
|
memberDeclarationLoop : while (LT(1) != IToken.tRBRACE)
|
||||||
{
|
{
|
||||||
IToken checkToken = LA(1);
|
IToken checkToken = LA(1);
|
||||||
|
@ -3189,6 +3191,14 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
cleanupLastToken();
|
cleanupLastToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handleClassSpecifier( IASTClassSpecifier classSpecifier ) throws EndOfFileException
|
||||||
|
{
|
||||||
|
cleanupLastToken();
|
||||||
|
if( classSpecifier instanceof IASTOffsetableNamedElement )
|
||||||
|
handleOffsetableNamedElement( classSpecifier );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param expression
|
* @param expression
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||||
import org.eclipse.cdt.core.parser.ParseError;
|
import org.eclipse.cdt.core.parser.ParseError;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||||
|
@ -248,7 +249,11 @@ public class SelectionParser extends ContextualParser {
|
||||||
if( token == lastTokenOfDuple ) ++tokensFound;
|
if( token == lastTokenOfDuple ) ++tokensFound;
|
||||||
}
|
}
|
||||||
if( tokensFound == 2 )
|
if( tokensFound == 2 )
|
||||||
|
{
|
||||||
greaterContextDuple = tokenDuple;
|
greaterContextDuple = tokenDuple;
|
||||||
|
pastPointOfSelection = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,4 +336,18 @@ public class SelectionParser extends ContextualParser {
|
||||||
throw new EndOfFileException();
|
throw new EndOfFileException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.Parser#endClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
|
||||||
|
*/
|
||||||
|
protected void handleClassSpecifier(IASTClassSpecifier classSpecifier)
|
||||||
|
throws EndOfFileException {
|
||||||
|
if( ! tokenDupleCompleted() )
|
||||||
|
super.handleClassSpecifier(classSpecifier);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
contextNode = classSpecifier;
|
||||||
|
handleOffsetableNamedElement( classSpecifier );
|
||||||
|
throw new EndOfFileException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue