1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Content assist for anonymous struct members, bug 284245.

This commit is contained in:
Markus Schorn 2009-07-22 13:04:08 +00:00
parent 6f9b44ab96
commit 760abf7ac7
2 changed files with 45 additions and 12 deletions

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.prefix; package org.eclipse.cdt.core.parser.tests.prefix;
@ -168,4 +169,26 @@ public class BasicCompletionTest extends CompletionTestBase {
String[] expected= {}; String[] expected= {};
checkCompletion(code, true, expected); checkCompletion(code, true, expected);
} }
// struct s1 {
// struct {
// int a1;
// int a2;
// };
// union {
// int u1;
// char u2;
// };
// int b;
// };
// int test() {
// struct s1 s;
// s.
public void testBug284245() throws Exception {
String code = getAboveComment();
String[] expectedCpp= {"a1", "a2", "b", "s1", "u1", "u2"};
String[] expectedC= {"a1", "a2", "b", "u1", "u2"};
checkCompletion(code, true, expectedCpp);
checkCompletion(code, false, expectedC);
}
} }

View file

@ -146,16 +146,25 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
}; };
} }
ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) definition.getParent(); ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) definition.getParent();
IField[] fields = collectFields(compSpec, null);
return (IField[]) ArrayUtil.trim( IField.class, fields );
}
private IField[] collectFields(ICASTCompositeTypeSpecifier compSpec, IField[] fields) {
IASTDeclaration[] members = compSpec.getMembers(); IASTDeclaration[] members = compSpec.getMembers();
int size = members.length; if (members.length > 0) {
IField[] fields = new IField[ size ]; if (fields == null)
if (size > 0) { fields = new IField[members.length];
for (int i = 0; i < size; i++) { for (IASTDeclaration node : members) {
IASTNode node = members[i];
if (node instanceof IASTSimpleDeclaration) { if (node instanceof IASTSimpleDeclaration) {
IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators(); IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators();
for (int j = 0; j < declarators.length; j++) { if (declarators.length == 0) {
IASTDeclarator declarator = declarators[j]; IASTDeclSpecifier declspec = ((IASTSimpleDeclaration) node).getDeclSpecifier();
if (declspec instanceof ICASTCompositeTypeSpecifier) {
fields= collectFields((ICASTCompositeTypeSpecifier) declspec, fields);
}
} else {
for (IASTDeclarator declarator : declarators) {
IASTName name = declarator.getName(); IASTName name = declarator.getName();
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
if (binding != null) if (binding != null)
@ -164,7 +173,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
} }
} }
} }
return (IField[]) ArrayUtil.trim( IField.class, fields ); }
return fields;
} }
public IField findField(String name) throws DOMException { public IField findField(String name) throws DOMException {