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

View file

@ -1060,6 +1060,36 @@ public class CompletionTests extends AbstractContentAssistTest {
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); 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; // #define INIT_PTR(PtrName) (PtrName) = 0;
// class CCApp { // class CCApp {
// public: // public:
@ -1094,4 +1124,12 @@ public class CompletionTests extends AbstractContentAssistTest {
final String[] expected= {"pIShell"}; final String[] expected= {"pIShell"};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); 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); 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; // #define INIT_PTR(PtrName) (PtrName) = 0;
// struct CCApp { // struct CCApp {
// int pIShell; // int pIShell;