1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +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:
* IBM Corporation - initial API and implementation
* Bryan Wilkinson (QNX)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.prefix;
@ -168,4 +169,26 @@ public class BasicCompletionTest extends CompletionTestBase {
String[] 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,25 +146,35 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
};
}
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();
int size = members.length;
IField[] fields = new IField[ size ];
if (size > 0) {
for (int i = 0; i < size; i++) {
IASTNode node = members[i];
if (members.length > 0) {
if (fields == null)
fields = new IField[members.length];
for (IASTDeclaration node : members) {
if (node instanceof IASTSimpleDeclaration) {
IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators();
for (int j = 0; j < declarators.length; j++) {
IASTDeclarator declarator = declarators[j];
IASTName name = declarator.getName();
IBinding binding = name.resolveBinding();
if (binding != null)
fields = (IField[]) ArrayUtil.append(IField.class, fields, binding);
if (declarators.length == 0) {
IASTDeclSpecifier declspec = ((IASTSimpleDeclaration) node).getDeclSpecifier();
if (declspec instanceof ICASTCompositeTypeSpecifier) {
fields= collectFields((ICASTCompositeTypeSpecifier) declspec, fields);
}
} else {
for (IASTDeclarator declarator : declarators) {
IASTName name = declarator.getName();
IBinding binding = name.resolveBinding();
if (binding != null)
fields = (IField[]) ArrayUtil.append(IField.class, fields, binding);
}
}
}
}
}
return (IField[]) ArrayUtil.trim( IField.class, fields );
return fields;
}
public IField findField(String name) throws DOMException {