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

Content assist within function-style initializer, bug 69334.

This commit is contained in:
Markus Schorn 2008-06-18 13:35:53 +00:00
parent 7b61bb10f2
commit 0424024136
2 changed files with 32 additions and 16 deletions

View file

@ -3199,7 +3199,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} }
// we have an ambiguity // we have an ambiguity
if (LA(1) != end1) { if (end1 != null && LA(1).getEndOffset() != end1.getEndOffset()) {
backup(end1); backup(end1);
return dtor1; return dtor1;
} }
@ -3276,7 +3276,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTExpression astExpression = expression(); IASTExpression astExpression = expression();
if( astExpression == null ) if( astExpression == null )
throwBacktrack( t ); throwBacktrack( t );
int l = consume(IToken.tRPAREN).getEndOffset(); int l = consumeOrEOC(IToken.tRPAREN).getEndOffset();
ICPPASTConstructorInitializer result = createConstructorInitializer(); ICPPASTConstructorInitializer result = createConstructorInitializer();
((ASTNode) result).setOffsetAndLength(o, l - o); ((ASTNode) result).setOffsetAndLength(o, l - o);
result.setExpression(astExpression); result.setExpression(astExpression);

View file

@ -9,10 +9,6 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Sep 9, 2004
*/
package org.eclipse.cdt.ui.tests.text.contentassist; package org.eclipse.cdt.ui.tests.text.contentassist;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -59,7 +55,8 @@ public class ContentAssistTests extends BaseUITestCase {
static IProject project; static IProject project;
static boolean disabledHelpContributions = false; static boolean disabledHelpContributions = false;
public void setUp() { @Override
public void setUp() {
//(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset(); //(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset();
if (project == null) { if (project == null) {
@ -96,9 +93,9 @@ public class ContentAssistTests extends BaseUITestCase {
public ITranslationUnit getTranslationUnit(){return null;} public ITranslationUnit getTranslationUnit(){return null;}
} }
); );
for( int i = 0; i < helpBooks.length; i++ ){ for (CHelpBookDescriptor helpBook : helpBooks) {
if( helpBooks[i] != null ) if( helpBook != null )
helpBooks[i].enable( false ); helpBook.enable( false );
} }
} }
@ -118,20 +115,21 @@ public class ContentAssistTests extends BaseUITestCase {
} }
} }
protected void tearDown() throws Exception { @Override
protected void tearDown() throws Exception {
if( project == null || !project.exists() ) if( project == null || !project.exists() )
return; return;
closeAllEditors(); closeAllEditors();
IResource [] members = project.members(); IResource [] members = project.members();
for( int i = 0; i < members.length; i++ ){ for (IResource member : members) {
if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ if( member.getName().equals( ".project" ) || member.getName().equals( ".cproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$
continue; continue;
if (members[i].getName().equals(".settings")) if (member.getName().equals(".settings"))
continue; continue;
try{ try{
members[i].delete( false, monitor ); member.delete( false, monitor );
} catch( Throwable e ){ } catch( Throwable e ){
/*boo*/ /*boo*/
} }
@ -179,7 +177,7 @@ public class ContentAssistTests extends BaseUITestCase {
return processor.computeCompletionProposals(editor.getViewer(), offset); return processor.computeCompletionProposals(editor.getViewer(), offset);
} }
public void testBug69334() throws Exception { public void testBug69334a() throws Exception {
importFile( "test.h", "class Test{ public : Test( int ); }; \n" ); //$NON-NLS-1$//$NON-NLS-2$ importFile( "test.h", "class Test{ public : Test( int ); }; \n" ); //$NON-NLS-1$//$NON-NLS-2$
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "#include \"test.h\" \n"); //$NON-NLS-1$ writer.write( "#include \"test.h\" \n"); //$NON-NLS-1$
@ -197,6 +195,24 @@ public class ContentAssistTests extends BaseUITestCase {
assertEquals( "veryLongName : int", results[0].getDisplayString() ); //$NON-NLS-1$ assertEquals( "veryLongName : int", results[0].getDisplayString() ); //$NON-NLS-1$
} }
public void testBug69334b() throws Exception {
importFile( "test.h", "class Test{ public : Test( int ); }; \n" ); //$NON-NLS-1$//$NON-NLS-2$
StringWriter writer = new StringWriter();
writer.write( "#include \"test.h\" \n"); //$NON-NLS-1$
writer.write( "Test::Test( int i ) { return; } \n"); //$NON-NLS-1$
writer.write( "int main() { \n"); //$NON-NLS-1$
writer.write( " int veryLongName = 1; \n"); //$NON-NLS-1$
writer.write( " Test test( very \n"); //$NON-NLS-1$
String code = writer.toString();
IFile cu = importFile( "test.cpp", code ); //$NON-NLS-1$
ICompletionProposal [] results = getResults( cu, code.indexOf( "very " ) + 4 ); //$NON-NLS-1$
assertEquals( 1, results.length );
assertEquals( "veryLongName : int", results[0].getDisplayString() ); //$NON-NLS-1$
}
public void testBug72824() throws Exception { public void testBug72824() throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "class Strategy { \n"); //$NON-NLS-1$ writer.write( "class Strategy { \n"); //$NON-NLS-1$