mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Content assist for anonymous struct members, bug 284245.
This commit is contained in:
parent
6f9b44ab96
commit
760abf7ac7
2 changed files with 45 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,16 +146,25 @@ 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];
|
||||
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)
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue