Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2009-07-22 09:04:13 -0400
committerMarkus Schorn2009-07-22 09:04:13 -0400
commit6b2f285d8737b970bd9fdf0a1ee4217d132e4547 (patch)
treeb625a627368affce60f4e0633f0cd25492c6117c /core
parent040fa39ccdec18bba9482988e651d2f0e9f8e398 (diff)
downloadorg.eclipse.cdt-6b2f285d8737b970bd9fdf0a1ee4217d132e4547.tar.gz
org.eclipse.cdt-6b2f285d8737b970bd9fdf0a1ee4217d132e4547.tar.xz
org.eclipse.cdt-6b2f285d8737b970bd9fdf0a1ee4217d132e4547.zip
Content assist for anonymous struct members, bug 284245.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/BasicCompletionTest.java23
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java34
2 files changed, 45 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/BasicCompletionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/BasicCompletionTest.java
index 2c9b218897..7c3340f062 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/BasicCompletionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/BasicCompletionTest.java
@@ -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);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java
index 7a47f986fb..ee0d75ec5b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java
@@ -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 {

Back to the top