diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java index d55e9752fee..87ada0e748b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java @@ -6,25 +6,30 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Yuan Zhang / Beth Tibbitts (IBM Research) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTCompletionContext; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; /** - * @author jcamelon + * Node for elaborated type specifiers (examples: struct S; union U; enum E;) */ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implements - ICASTElaboratedTypeSpecifier { + ICASTElaboratedTypeSpecifier, IASTCompletionContext { private int kind; private IASTName name; @@ -102,4 +107,41 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement } return r_reference; } + + public IBinding[] findBindings(IASTName n, boolean isPrefix) { + IBinding[] result= CVisitor.findBindingsForContentAssist(n, isPrefix); + int nextPos= 0; + for (int i = 0; i < result.length; i++) { + IBinding b= result[i]; + if (b instanceof ICompositeType) { + ICompositeType ct= (ICompositeType) b; + try { + switch (ct.getKey()) { + case ICompositeType.k_struct: + if (getKind() != k_struct) + b= null; + break; + case ICompositeType.k_union: + if (getKind() != k_union) + b= null; + break; + } + } catch (DOMException e) { + // ignore and propose binding + } + } else if (b instanceof IEnumeration) { + if (getKind() != k_enum) + b= null; + } + if (b != null) { + result[nextPos++]= b; + } + } + if (nextPos != result.length) { + IBinding[] copy = new IBinding[nextPos]; + System.arraycopy(result, 0, copy, 0, nextPos); + return copy; + } + return result; + } } 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 cfdbd85c075..aa84fafc3bf 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 @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * Andrew Niefer (IBM Rational Software) - Initial API and implementation * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) @@ -109,8 +109,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.core.runtime.CoreException; /** - * Created on Nov 5, 2004 - * @author aniefer + * Collection of methods to find information in an AST. */ public class CVisitor { public static class ClearBindingAction extends CASTVisitor { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index b292588538c..5d5c4efaa23 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -2294,7 +2294,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } identifier= qualifiedName(); - if (identifier.getLastName().toCharArray().length == 0) + if (identifier.getLastName().toCharArray().length == 0 && LT(1) != IToken.tEOC) throwBacktrack(LA(1)); endOffset= calculateEndOffset(identifier); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index 448b484ed13..fca2581451f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -406,7 +406,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } public boolean isOnTopContext() { - return fCurrentContext == fRootContext; + ScannerContext ctx= fCurrentContext; + while (ctx != null && ctx.getLocationCtx() instanceof LocationCtxMacroExpansion) { + ctx= ctx.getParent(); + } + return ctx == fRootContext; } public void cancel() { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java index ffb89ef9d89..538dce1d87a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java @@ -1174,4 +1174,17 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= {"_f204758(_e204758 x) : void"}; assertCompletionResults(fCursorOffset, expected, COMPARE_DISP_STRINGS); } -} + + // #define CATCH(X) } catch (X) { + // void foo() { + // try { + // CATCH(float var) + // v/*cursor*/ + // } catch (int var2) { + // } + // } + public void testContentAssistWithBraceInMacro_Bug257915() throws Exception { + final String[] expected= {"var : float"}; + assertCompletionResults(fCursorOffset, expected, COMPARE_DISP_STRINGS); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java index 6aa248e5a2b..a1323f082ad 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java @@ -51,6 +51,7 @@ public class ParameterHintTests extends AbstractContentAssistTest { return BaseTestCase.suite(ParameterHintTests.class, "_"); } + @Override protected IFile setUpProjectContent(IProject project) throws Exception { String headerContent= readTaggedComment(HEADER_FILE_NAME); StringBuffer sourceContent= getContentsForTest(1)[0]; @@ -142,7 +143,7 @@ public class ParameterHintTests extends AbstractContentAssistTest { public void testTemplateConstructor() throws Exception { assertParameterHints(new String[] { "tClass(T t)", - "tClass(const tClass &)" + "tClass(const tClass &)" }); }