1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix and test case for 190296: Codecompletion is not working for std-classes and only restricted in own classes

This commit is contained in:
Anton Leherbauer 2007-06-01 12:56:59 +00:00
parent a16b6dd5de
commit 5717eb041f
3 changed files with 41 additions and 4 deletions

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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));
}
}