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 1935a184c6b..d9c7602ba2e 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 @@ -373,7 +373,17 @@ public class BasicCompletionTest extends CompletionTestBase { // struct foo { int axx;}; // struct foo bar = {.a - public void testCompletionInDesignatedInitializor_353281() throws Exception { + public void testCompletionInDesignatedInitializor_353281a() throws Exception { + String code = getAboveComment(); + String[] expected= {"axx"}; + checkCompletion(code, false, expected); + } + + // struct foo { int axx;}; + // void func() + // { + // struct foo bar = {.a + public void testCompletionInDesignatedInitializor_353281b() throws Exception { String code = getAboveComment(); String[] expected= {"axx"}; checkCompletion(code, false, expected); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 288b42a9578..648c774806b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ * Andrew Ferguson (Symbian) * Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion) * Sergey Prigogin (Google) + * Marc-Andre Laperle (Ericsson) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -1531,13 +1532,17 @@ public class CVisitor extends ASTQueries { private static IBinding[] findBindingForContentAssist(ICASTFieldDesignator fd, boolean isPrefix) { IASTNode blockItem = getContainingBlockItem(fd); - - IASTNode parent= blockItem; - while (parent != null && !(parent instanceof IASTSimpleDeclaration)) - parent= parent.getParent(); - - if (parent instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent; + + IASTNode declarationNode = blockItem; + if (blockItem instanceof IASTDeclarationStatement && ((IASTDeclarationStatement) blockItem).getDeclaration() instanceof IASTSimpleDeclaration) { + declarationNode = ((IASTDeclarationStatement) blockItem).getDeclaration(); + } else { + while (declarationNode != null && !(declarationNode instanceof IASTSimpleDeclaration)) + declarationNode= declarationNode.getParent(); + } + + if (declarationNode instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declarationNode; IBinding struct= null; if (simpleDecl.getDeclSpecifier() instanceof IASTNamedTypeSpecifier) { struct = ((IASTNamedTypeSpecifier) simpleDecl.getDeclSpecifier()).getName().resolveBinding(); @@ -1554,6 +1559,7 @@ public class CVisitor extends ASTQueries { } } } + return null; } diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java index a209083c336..64a0e1a174d 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java @@ -49,7 +49,7 @@ public class LRCompletionBasicTest extends BasicCompletionTest { @Override public void testConditionalOperator_Bug308611() throws Exception {} @Override - public void testCompletionInDesignatedInitializor_353281() throws Exception {} + public void testCompletionInDesignatedInitializor_353281a() throws Exception {} @Override @SuppressWarnings("unused")