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:
parent
a16b6dd5de
commit
5717eb041f
3 changed files with 41 additions and 4 deletions
|
@ -9,23 +9,28 @@
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Bryan Wilkinson (QNX)
|
* Bryan Wilkinson (QNX)
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
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.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
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.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class CPPASTName extends CPPASTNode implements IASTName {
|
public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionContext {
|
||||||
private final static class RecursionResolvingBinding extends ProblemBinding {
|
private final static class RecursionResolvingBinding extends ProblemBinding {
|
||||||
public RecursionResolvingBinding() {
|
public RecursionResolvingBinding() {
|
||||||
super(null, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, CharArrayUtils.EMPTY);
|
super(null, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, CharArrayUtils.EMPTY);
|
||||||
|
@ -90,7 +95,23 @@ public class CPPASTName extends CPPASTNode implements IASTName {
|
||||||
}
|
}
|
||||||
node = node.getParent();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -759,4 +759,12 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
assertMinimumCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
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.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
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.IASTFunctionStyleMacroParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
@ -215,7 +217,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
if (!isAnonymousBinding(binding)) {
|
if (!isAnonymousBinding(binding)) {
|
||||||
if (binding instanceof ICPPClassType) {
|
if (binding instanceof ICPPClassType) {
|
||||||
handleClass((ICPPClassType) binding, cContext, proposals);
|
handleClass((ICPPClassType) binding, astContext, cContext, proposals);
|
||||||
} else if (binding instanceof IFunction) {
|
} else if (binding instanceof IFunction) {
|
||||||
handleFunction((IFunction)binding, cContext, proposals);
|
handleFunction((IFunction)binding, cContext, proposals);
|
||||||
} else if (!cContext.isContextInformationStyle()) {
|
} else if (!cContext.isContextInformationStyle()) {
|
||||||
|
@ -235,7 +237,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
return name.length == 0 || name[0] == '{';
|
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()) {
|
if (context.isContextInformationStyle()) {
|
||||||
try {
|
try {
|
||||||
ICPPConstructor[] constructors = classType.getConstructors();
|
ICPPConstructor[] constructors = classType.getConstructors();
|
||||||
|
@ -245,6 +247,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
} else {
|
} 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));
|
proposals.add(createProposal(classType.getName(), classType.getName(), getImage(classType), context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue