1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

Content assist after '<', bug 229062.

This commit is contained in:
Markus Schorn 2008-04-28 15:33:07 +00:00
parent b55658f76a
commit ac92e0e883
3 changed files with 91 additions and 15 deletions

View file

@ -171,7 +171,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private int templateCount = 0;
private int functionBodyCount= 0;
private int templateArgListCount= 0;
private int preventLogicalOperatorInTemplateID;
private int rejectLogicalOperatorInTemplateID;
protected CPPASTTranslationUnit translationUnit;
@ -290,7 +290,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
completedArg = false;
IToken mark = mark();
IASTTypeId typeId = typeId(false);
if (typeId == null) {
backup(mark);
@ -339,12 +338,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
* @since 5.0
*/
protected final ITokenDuple nameWithoutLogicalOperatorInTemplateID() throws BacktrackException, EndOfFileException {
preventLogicalOperatorInTemplateID++;
rejectLogicalOperatorInTemplateID++;
try {
return name();
}
finally {
preventLogicalOperatorInTemplateID--;
rejectLogicalOperatorInTemplateID--;
}
}
/**
@ -431,7 +430,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
@Override
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
final IASTExpression expr= super.conditionalExpression();
if (templateArgListCount > 0 && preventLogicalOperatorInTemplateID > 0) {
if (templateArgListCount > 0 && rejectLogicalOperatorInTemplateID > 0) {
// bug 104706, don't allow usage of logical operators in template argument lists.
if (expr instanceof IASTConditionalExpression) {
final ASTNode node = (ASTNode) expr;
@ -456,20 +455,29 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
consume();
templateArgListCount++;
try {
// bug 229062: content assist after '<' needs to prefer to backtrack here
if (rejectLogicalOperatorInTemplateID == 1) {
final int lt1= LT(1);
if (lt1 == IToken.tCOMPLETION || lt1 == IToken.tEOC) {
throw backtrack;
}
}
List<IASTNode> list = templateArgumentList();
argumentList.addSegment(list);
switch (LT(1)) {
case IToken.tGT:
switch(LT(1)) {
case IToken.tGT:
final int lt2= LT(2);
if (lt2 == IToken.tINTEGER || lt2 == IToken.tFLOATINGPT) {
throw backtrack;
}
break;
case IToken.tEOC:
if( LT(2) == IToken.tINTEGER || LT(2) == IToken.tFLOATINGPT) {
backup( secondMark );
return last;
}
last = consume();
break;
break;
default:
throw backtrack;
throw backtrack;
}
argumentList.addSegment(list);
last = consume();
} catch (BacktrackException bt) {
argumentList.addSegment(null);
backup(secondMark);

View file

@ -1060,6 +1060,36 @@ public class CompletionTests extends AbstractContentAssistTest {
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
// void test() {
// int local;
// for(loc/*cursor*/
public void testForStatement1() throws Exception {
final String[] expected= {
"local"
};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
// void test() {
// int local;
// for(int i=0;i<loc/*cursor*/
public void testForStatement2() throws Exception {
final String[] expected= {
"local"
};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
// void test() {
// int local;
// for(int i=0;i<local;loc/*cursor*/
public void testForStatement3() throws Exception {
final String[] expected= {
"local"
};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
// #define INIT_PTR(PtrName) (PtrName) = 0;
// class CCApp {
// public:
@ -1094,4 +1124,12 @@ public class CompletionTests extends AbstractContentAssistTest {
final String[] expected= {"pIShell"};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
// void test() {
// int alocal, blocal;
// if (alocal < b/*cursor*/
public void testCompletionAfterLessThan_Bug229062() throws Exception {
final String[] expected= {"blocal"};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
}

View file

@ -867,6 +867,36 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
assertCompletionResults(expected);
}
// void test() {
// int local;
// for(loc/*cursor*/
public void testForStatement1() throws Exception {
final String[] expected= {
"local"
};
assertCompletionResults(expected);
}
// void test() {
// int local;
// for(int i=0;i<loc/*cursor*/
public void testForStatement2() throws Exception {
final String[] expected= {
"local"
};
assertCompletionResults(expected);
}
// void test() {
// int local;
// for(int i=0;i<local;loc/*cursor*/
public void testForStatement3() throws Exception {
final String[] expected= {
"local"
};
assertCompletionResults(expected);
}
// #define INIT_PTR(PtrName) (PtrName) = 0;
// struct CCApp {
// int pIShell;