mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Patch for Bryan - 181264 - support content assist in switch and while statements.
This commit is contained in:
parent
809ce2a43e
commit
9d0bde031c
3 changed files with 85 additions and 18 deletions
|
@ -100,4 +100,29 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
assertEquals("blah", ((ITypedef)bindings[0]).getName());
|
||||
}
|
||||
|
||||
public void testBug181624() throws Exception {
|
||||
StringBuffer code = new StringBuffer();
|
||||
code.append("void foo() {");
|
||||
code.append(" switch (");
|
||||
|
||||
// C++
|
||||
IASTCompletionNode node = getGPPCompletionNode(code.toString());
|
||||
assertNotNull(node);
|
||||
|
||||
// C
|
||||
node = getGCCCompletionNode(code.toString());
|
||||
assertNotNull(node);
|
||||
|
||||
code = new StringBuffer();
|
||||
code.append("void foo() {");
|
||||
code.append(" while (");
|
||||
|
||||
// C++
|
||||
node = getGPPCompletionNode(code.toString());
|
||||
assertNotNull(node);
|
||||
|
||||
// C
|
||||
node = getGCCCompletionNode(code.toString());
|
||||
assertNotNull(node);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2936,18 +2936,32 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
startOffset = consume().getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IASTExpression switch_condition = condition();
|
||||
consume(IToken.tRPAREN);
|
||||
IASTStatement switch_body = statement();
|
||||
switch (LT(1)) {
|
||||
case IToken.tRPAREN:
|
||||
consume();
|
||||
break;
|
||||
case IToken.tEOC:
|
||||
break;
|
||||
default:
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
IASTStatement switch_body = null;
|
||||
if (LT(1) != IToken.tEOC)
|
||||
switch_body = statement();
|
||||
|
||||
IASTSwitchStatement switch_statement = createSwitchStatement();
|
||||
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
|
||||
calculateEndOffset(switch_body) - startOffset);
|
||||
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
|
||||
switch_statement.setControllerExpression(switch_condition);
|
||||
switch_condition.setParent(switch_statement);
|
||||
switch_condition.setPropertyInParent(IASTSwitchStatement.CONTROLLER_EXP);
|
||||
|
||||
if (switch_body != null) {
|
||||
switch_statement.setBody(switch_body);
|
||||
switch_body.setParent(switch_statement);
|
||||
switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
|
||||
}
|
||||
|
||||
return switch_statement;
|
||||
}
|
||||
|
||||
|
|
|
@ -5212,12 +5212,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
int startOffset = consume().getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IASTNode while_condition = cppStyleCondition(true);
|
||||
consume(IToken.tRPAREN);
|
||||
IASTStatement while_body = statement();
|
||||
switch (LT(1)) {
|
||||
case IToken.tRPAREN:
|
||||
consume();
|
||||
break;
|
||||
case IToken.tEOC:
|
||||
break;
|
||||
default:
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
IASTStatement while_body = null;
|
||||
if (LT(1) != IToken.tEOC)
|
||||
while_body = statement();
|
||||
|
||||
ICPPASTWhileStatement while_statement = (ICPPASTWhileStatement) createWhileStatement();
|
||||
((ASTNode) while_statement).setOffsetAndLength(startOffset,
|
||||
calculateEndOffset(while_body) - startOffset);
|
||||
(while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset);
|
||||
if (while_condition instanceof IASTExpression) {
|
||||
while_statement.setCondition((IASTExpression) while_condition);
|
||||
while_condition.setParent(while_statement);
|
||||
|
@ -5230,9 +5240,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
while_condition
|
||||
.setPropertyInParent(ICPPASTWhileStatement.CONDITIONDECLARATION);
|
||||
}
|
||||
|
||||
if (while_body != null) {
|
||||
while_statement.setBody(while_body);
|
||||
while_body.setParent(while_statement);
|
||||
while_body.setPropertyInParent(IASTWhileStatement.BODY);
|
||||
}
|
||||
|
||||
return while_statement;
|
||||
|
||||
}
|
||||
|
@ -5488,12 +5502,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
startOffset = consume().getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IASTNode switch_condition = cppStyleCondition(true);
|
||||
consume(IToken.tRPAREN);
|
||||
IASTStatement switch_body = statement();
|
||||
switch (LT(1)) {
|
||||
case IToken.tRPAREN:
|
||||
consume();
|
||||
break;
|
||||
case IToken.tEOC:
|
||||
break;
|
||||
default:
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
IASTStatement switch_body = null;
|
||||
if (LT(1) != IToken.tEOC)
|
||||
switch_body = statement();
|
||||
|
||||
ICPPASTSwitchStatement switch_statement = createSwitchStatement();
|
||||
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
|
||||
calculateEndOffset(switch_body) - startOffset);
|
||||
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
|
||||
if( switch_condition instanceof IASTExpression )
|
||||
{
|
||||
switch_statement.setControllerExpression((IASTExpression) switch_condition);
|
||||
|
@ -5506,9 +5530,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
switch_condition.setParent(switch_statement);
|
||||
switch_condition.setPropertyInParent(ICPPASTSwitchStatement.CONTROLLER_DECLARATION);
|
||||
}
|
||||
|
||||
if (switch_body != null) {
|
||||
switch_statement.setBody(switch_body);
|
||||
switch_body.setParent(switch_statement);
|
||||
switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
|
||||
}
|
||||
|
||||
return switch_statement;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue