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:
parent
6f9b44ab96
commit
760abf7ac7
2 changed files with 45 additions and 12 deletions
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,25 +146,35 @@ 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();
|
||||||
IASTName name = declarator.getName();
|
if (declspec instanceof ICASTCompositeTypeSpecifier) {
|
||||||
IBinding binding = name.resolveBinding();
|
fields= collectFields((ICASTCompositeTypeSpecifier) declspec, fields);
|
||||||
if (binding != null)
|
}
|
||||||
fields = (IField[]) ArrayUtil.append(IField.class, fields, binding);
|
} 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 {
|
public IField findField(String name) throws DOMException {
|
||||||
|
|
Loading…
Add table
Reference in a new issue