diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java index a3136bc6845..23767087098 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java @@ -9,23 +9,28 @@ * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompletionContext; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * @author jcamelon */ -public class CPPASTName extends CPPASTNode implements IASTName { +public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionContext { private final static class RecursionResolvingBinding extends ProblemBinding { public RecursionResolvingBinding() { super(null, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, CharArrayUtils.EMPTY); @@ -90,10 +95,26 @@ public class CPPASTName extends CPPASTNode implements IASTName { } node = node.getParent(); } - + if (getLength() > 0) { + return this; + } return null; } + public IBinding[] findBindings(IASTName n, boolean isPrefix) { + if (getParent() instanceof IASTDeclarator) { + IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix); + for (int i = 0; i < bindings.length; i++) { + if (bindings[i] instanceof ICPPNamespace || bindings[i] instanceof ICPPClassType) { + } else { + bindings[i]= null; + } + } + return (IBinding[])ArrayUtil.removeNulls(IBinding.class, bindings); + } + return null; + } + public void setBinding(IBinding binding) { this.binding = binding; fResolutionDepth= 0; 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 1d023c77f25..facbc79d00f 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 @@ -759,4 +759,12 @@ public class CompletionTests extends AbstractContentAssistTest { assertMinimumCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); } + // void Pri/*cursor*/ + public void testMethodDefinitionClassName_Bug190296() throws Exception { + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=190296 + final String[] expected= { + "Printer::" + }; + assertMinimumCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index c3b781ee8d8..ca99f54818b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -8,6 +8,7 @@ * Contributors: * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.contentassist; @@ -24,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompletionContext; import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -215,7 +217,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (!isAnonymousBinding(binding)) { if (binding instanceof ICPPClassType) { - handleClass((ICPPClassType) binding, cContext, proposals); + handleClass((ICPPClassType) binding, astContext, cContext, proposals); } else if (binding instanceof IFunction) { handleFunction((IFunction)binding, cContext, proposals); } else if (!cContext.isContextInformationStyle()) { @@ -235,7 +237,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer return name.length == 0 || name[0] == '{'; } - private void handleClass(ICPPClassType classType, CContentAssistInvocationContext context, List proposals) { + private void handleClass(ICPPClassType classType, IASTCompletionContext astContext, CContentAssistInvocationContext context, List proposals) { if (context.isContextInformationStyle()) { try { ICPPConstructor[] constructors = classType.getConstructors(); @@ -245,6 +247,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } catch (DOMException e) { } } else { + if (astContext instanceof IASTName && !(astContext instanceof ICPPASTQualifiedName)) { + IASTName name= (IASTName)astContext; + if (name.getParent() instanceof IASTDeclarator) { + proposals.add(createProposal(classType.getName()+"::", classType.getName(), getImage(classType), context)); //$NON-NLS-1$ + } + } proposals.add(createProposal(classType.getName(), classType.getName(), getImage(classType), context)); } }